mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
* lib/time.rb: do not reference Time directly from the inside of
definitions. [ruby-dev:33059] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@15029 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
5b46f99ce1
commit
669e94a314
2 changed files with 14 additions and 9 deletions
|
@ -1,3 +1,8 @@
|
||||||
|
Mon Jan 14 09:19:07 2008 Tadayoshi Funaba <tadf@dotrb.org>
|
||||||
|
|
||||||
|
* lib/time.rb: do not reference Time directly from the inside of
|
||||||
|
definitions. [ruby-dev:33059]
|
||||||
|
|
||||||
Mon Jan 14 05:44:44 2008 NARUSE, Yui <naruse@ruby-lang.org>
|
Mon Jan 14 05:44:44 2008 NARUSE, Yui <naruse@ruby-lang.org>
|
||||||
|
|
||||||
* enc/*.c: add replicas and aliases.
|
* enc/*.c: add replicas and aliases.
|
||||||
|
|
18
lib/time.rb
18
lib/time.rb
|
@ -66,7 +66,7 @@ class Time
|
||||||
'N' => -1, 'O' => -2, 'P' => -3, 'Q' => -4, 'R' => -5, 'S' => -6,
|
'N' => -1, 'O' => -2, 'P' => -3, 'Q' => -4, 'R' => -5, 'S' => -6,
|
||||||
'T' => -7, 'U' => -8, 'V' => -9, 'W' => -10, 'X' => -11, 'Y' => -12,
|
'T' => -7, 'U' => -8, 'V' => -9, 'W' => -10, 'X' => -11, 'Y' => -12,
|
||||||
}
|
}
|
||||||
def zone_offset(zone, year=Time.now.year)
|
def zone_offset(zone, year=self.now.year)
|
||||||
off = nil
|
off = nil
|
||||||
zone = zone.upcase
|
zone = zone.upcase
|
||||||
if /\A([+-])(\d\d):?(\d\d)\z/ =~ zone
|
if /\A([+-])(\d\d):?(\d\d)\z/ =~ zone
|
||||||
|
@ -75,9 +75,9 @@ class Time
|
||||||
off = zone.to_i * 3600
|
off = zone.to_i * 3600
|
||||||
elsif ZoneOffset.include?(zone)
|
elsif ZoneOffset.include?(zone)
|
||||||
off = ZoneOffset[zone] * 3600
|
off = ZoneOffset[zone] * 3600
|
||||||
elsif ((t = Time.local(year, 1, 1)).zone.upcase == zone rescue false)
|
elsif ((t = self.local(year, 1, 1)).zone.upcase == zone rescue false)
|
||||||
off = t.utc_offset
|
off = t.utc_offset
|
||||||
elsif ((t = Time.local(year, 7, 1)).zone.upcase == zone rescue false)
|
elsif ((t = self.local(year, 7, 1)).zone.upcase == zone rescue false)
|
||||||
off = t.utc_offset
|
off = t.utc_offset
|
||||||
end
|
end
|
||||||
off
|
off
|
||||||
|
@ -177,7 +177,7 @@ class Time
|
||||||
if off
|
if off
|
||||||
year, mon, day, hour, min, sec =
|
year, mon, day, hour, min, sec =
|
||||||
apply_offset(year, mon, day, hour, min, sec, off)
|
apply_offset(year, mon, day, hour, min, sec, off)
|
||||||
t = Time.utc(year, mon, day, hour, min, sec, usec)
|
t = self.utc(year, mon, day, hour, min, sec, usec)
|
||||||
t.localtime if !zone_utc?(zone)
|
t.localtime if !zone_utc?(zone)
|
||||||
t
|
t
|
||||||
else
|
else
|
||||||
|
@ -236,7 +236,7 @@ class Time
|
||||||
#
|
#
|
||||||
# A failure for Time.parse should be checked, though.
|
# A failure for Time.parse should be checked, though.
|
||||||
#
|
#
|
||||||
def parse(date, now=Time.now)
|
def parse(date, now=self.now)
|
||||||
d = Date._parse(date, false)
|
d = Date._parse(date, false)
|
||||||
year = d[:year]
|
year = d[:year]
|
||||||
year = yield(year) if year && block_given?
|
year = yield(year) if year && block_given?
|
||||||
|
@ -250,7 +250,7 @@ class Time
|
||||||
# block. For example:
|
# block. For example:
|
||||||
#
|
#
|
||||||
# Time.strptime(...) {|y| y < 100 ? (y >= 69 ? y + 1900 : y + 2000) : y}
|
# Time.strptime(...) {|y| y < 100 ? (y >= 69 ? y + 1900 : y + 2000) : y}
|
||||||
def strptime(date, format, now=Time.now)
|
def strptime(date, format, now=self.now)
|
||||||
d = Date._strptime(date, format)
|
d = Date._strptime(date, format)
|
||||||
raise ArgumentError, "invalid strptime format - `#{format}'" unless d
|
raise ArgumentError, "invalid strptime format - `#{format}'" unless d
|
||||||
year = d[:year]
|
year = d[:year]
|
||||||
|
@ -344,7 +344,7 @@ class Time
|
||||||
else
|
else
|
||||||
year += 1900
|
year += 1900
|
||||||
end
|
end
|
||||||
Time.utc(year, $2, $1.to_i, $4.to_i, $5.to_i, $6.to_i)
|
self.utc(year, $2, $1.to_i, $4.to_i, $5.to_i, $6.to_i)
|
||||||
elsif /\A\s*
|
elsif /\A\s*
|
||||||
(?:Mon|Tue|Wed|Thu|Fri|Sat|Sun)\x20
|
(?:Mon|Tue|Wed|Thu|Fri|Sat|Sun)\x20
|
||||||
(Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)\x20
|
(Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)\x20
|
||||||
|
@ -389,9 +389,9 @@ class Time
|
||||||
zone = $8
|
zone = $8
|
||||||
year, mon, day, hour, min, sec =
|
year, mon, day, hour, min, sec =
|
||||||
apply_offset(year, mon, day, hour, min, sec, zone_offset(zone))
|
apply_offset(year, mon, day, hour, min, sec, zone_offset(zone))
|
||||||
Time.utc(year, mon, day, hour, min, sec, usec)
|
self.utc(year, mon, day, hour, min, sec, usec)
|
||||||
else
|
else
|
||||||
Time.local(year, mon, day, hour, min, sec, usec)
|
self.local(year, mon, day, hour, min, sec, usec)
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
raise ArgumentError.new("invalid date: #{date.inspect}")
|
raise ArgumentError.new("invalid date: #{date.inspect}")
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue