* lib/time.rb (make_time): Produce fixed-offset time object if
appropriate. (Time.strptime): Use d[:zone] instead of d[:offset]. * lib/rss/rss.rb (Time.w3cdtf): Produce fixed-offset time object if appropriate. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@45798 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
0a76ec34ea
commit
c4f29a6576
@ -1,3 +1,12 @@
|
|||||||
|
Sat May 3 23:52:20 2014 Tanaka Akira <akr@fsij.org>
|
||||||
|
|
||||||
|
* lib/time.rb (make_time): Produce fixed-offset time object if
|
||||||
|
appropriate.
|
||||||
|
(Time.strptime): Use d[:zone] instead of d[:offset].
|
||||||
|
|
||||||
|
* lib/rss/rss.rb (Time.w3cdtf): Produce fixed-offset time object if
|
||||||
|
appropriate.
|
||||||
|
|
||||||
Sat May 3 20:21:38 2014 Tanaka Akira <akr@fsij.org>
|
Sat May 3 20:21:38 2014 Tanaka Akira <akr@fsij.org>
|
||||||
|
|
||||||
* lib/time.rb (Time.strptime): Use d[:offset] if d[:seconds] is not
|
* lib/time.rb (Time.strptime): Use d[:offset] if d[:seconds] is not
|
||||||
|
@ -28,7 +28,7 @@ class Time
|
|||||||
datetime = apply_offset(*(datetime + [off]))
|
datetime = apply_offset(*(datetime + [off]))
|
||||||
datetime << usec
|
datetime << usec
|
||||||
time = Time.utc(*datetime)
|
time = Time.utc(*datetime)
|
||||||
time.localtime unless zone_utc?(zone)
|
time.localtime(off) unless zone_utc?(zone)
|
||||||
time
|
time
|
||||||
else
|
else
|
||||||
datetime << usec
|
datetime << usec
|
||||||
|
16
lib/time.rb
16
lib/time.rb
@ -258,7 +258,11 @@ class Time
|
|||||||
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 = self.utc(year, mon, day, hour, min, sec, usec)
|
t = self.utc(year, mon, day, hour, min, sec, usec)
|
||||||
t.localtime if !zone_utc?(zone)
|
if zone_utc?(zone)
|
||||||
|
t.utc
|
||||||
|
else
|
||||||
|
t.localtime(off)
|
||||||
|
end
|
||||||
t
|
t
|
||||||
else
|
else
|
||||||
self.local(year, mon, day, hour, min, sec, usec)
|
self.local(year, mon, day, hour, min, sec, usec)
|
||||||
@ -394,14 +398,18 @@ class Time
|
|||||||
raise ArgumentError, "invalid strptime format - `#{format}'" unless d
|
raise ArgumentError, "invalid strptime format - `#{format}'" unless d
|
||||||
if seconds = d[:seconds]
|
if seconds = d[:seconds]
|
||||||
t = Time.at(seconds)
|
t = Time.at(seconds)
|
||||||
|
if zone = d[:zone]
|
||||||
|
if zone_utc?(zone)
|
||||||
|
t.utc
|
||||||
|
elsif offset = zone_offset(zone)
|
||||||
|
t.localtime(offset)
|
||||||
|
end
|
||||||
|
end
|
||||||
else
|
else
|
||||||
year = d[:year]
|
year = d[:year]
|
||||||
year = yield(year) if year && block_given?
|
year = yield(year) if year && block_given?
|
||||||
t = make_time(year, d[:mon], d[:mday], d[:hour], d[:min], d[:sec], d[:sec_fraction], d[:zone], now)
|
t = make_time(year, d[:mon], d[:mday], d[:hour], d[:min], d[:sec], d[:sec_fraction], d[:zone], now)
|
||||||
end
|
end
|
||||||
if offset = d[:offset]
|
|
||||||
t.localtime(offset)
|
|
||||||
end
|
|
||||||
t
|
t
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -407,6 +407,10 @@ class TestTimeExtension < Test::Unit::TestCase # :nodoc:
|
|||||||
t = Time.strptime('0 +0100', '%s %z')
|
t = Time.strptime('0 +0100', '%s %z')
|
||||||
assert_equal(0, t.to_r)
|
assert_equal(0, t.to_r)
|
||||||
assert_equal(3600, t.utc_offset)
|
assert_equal(3600, t.utc_offset)
|
||||||
|
t = Time.strptime('0 UTC', '%s %z')
|
||||||
|
assert_equal(0, t.to_r)
|
||||||
|
assert_equal(0, t.utc_offset)
|
||||||
|
assert_equal(true, t.utc?)
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_strptime_Ymd_z
|
def test_strptime_Ymd_z
|
||||||
@ -418,6 +422,15 @@ class TestTimeExtension < Test::Unit::TestCase # :nodoc:
|
|||||||
assert_equal(0, t.min)
|
assert_equal(0, t.min)
|
||||||
assert_equal(0, t.sec)
|
assert_equal(0, t.sec)
|
||||||
assert_equal(-7200, t.utc_offset)
|
assert_equal(-7200, t.utc_offset)
|
||||||
|
t = Time.strptime('20010203 UTC', '%Y%m%d %z')
|
||||||
|
assert_equal(2001, t.year)
|
||||||
|
assert_equal(2, t.mon)
|
||||||
|
assert_equal(3, t.day)
|
||||||
|
assert_equal(0, t.hour)
|
||||||
|
assert_equal(0, t.min)
|
||||||
|
assert_equal(0, t.sec)
|
||||||
|
assert_equal(0, t.utc_offset)
|
||||||
|
assert_equal(true, t.utc?)
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_nsec
|
def test_nsec
|
||||||
|
Loading…
x
Reference in New Issue
Block a user