mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
* lib/time.rb (Time.parse): "Fri Jan 1 08:59:60 +0900 1999" was
parsed as "Fri Jan 01 09:00:00 JST 1999" even on an environment which supports leap seconds. (Time.rfc2822): ditto. (Time.xmlschema): ditto. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_8@8629 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
ad0f7f889b
commit
37f56905ef
2 changed files with 58 additions and 4 deletions
|
@ -1,3 +1,11 @@
|
|||
Thu Jun 16 12:53:24 2005 Tanaka Akira <akr@m17n.org>
|
||||
|
||||
* lib/time.rb (Time.parse): "Fri Jan 1 08:59:60 +0900 1999" was
|
||||
parsed as "Fri Jan 01 09:00:00 JST 1999" even on an environment
|
||||
which supports leap seconds.
|
||||
(Time.rfc2822): ditto.
|
||||
(Time.xmlschema): ditto.
|
||||
|
||||
Thu Jun 16 08:29:22 2005 Hirokazu Yamamoto <ocean@m2.ccsnet.ne.jp>
|
||||
|
||||
* ext/dl/sym.c (rb_dlsym_call): needs FREE_ARGS before return.
|
||||
|
|
54
lib/time.rb
54
lib/time.rb
|
@ -170,6 +170,7 @@ class Time
|
|||
off = zone_offset(zone, year) if zone
|
||||
|
||||
if off
|
||||
sec = 59 if sec == 60 && 0 < off
|
||||
t = Time.utc(year, mon, day, hour, min, sec) - off
|
||||
t.localtime if !zone_utc?(zone)
|
||||
t
|
||||
|
@ -222,8 +223,9 @@ class Time
|
|||
year
|
||||
end
|
||||
|
||||
t = Time.utc(year, mon, day, hour, min, sec)
|
||||
t -= zone_offset(zone)
|
||||
off = zone_offset(zone)
|
||||
sec = 59 if sec == 60 && 0 < off
|
||||
t = Time.utc(year, mon, day, hour, min, sec) - off
|
||||
t.localtime if !zone_utc?(zone)
|
||||
t
|
||||
else
|
||||
|
@ -293,7 +295,9 @@ class Time
|
|||
datetime = [$1.to_i, $2.to_i, $3.to_i, $4.to_i, $5.to_i, $6.to_i]
|
||||
datetime << $7.to_f * 1000000 if $7
|
||||
if $8
|
||||
Time.utc(*datetime) - zone_offset($8)
|
||||
off = zone_offset($8)
|
||||
datetime[5] = 59 if datetime[5] == 60 && 0 < off
|
||||
Time.utc(*datetime) - off
|
||||
else
|
||||
Time.local(*datetime)
|
||||
end
|
||||
|
@ -636,6 +640,48 @@ if __FILE__ == $0
|
|||
assert_equal(false, Time.rfc2822("Sat, 01 Jan 2000 00:00:00 +0000").utc?)
|
||||
assert_equal(true, Time.rfc2822("Sat, 01 Jan 2000 00:00:00 UTC").utc?)
|
||||
end
|
||||
end
|
||||
|
||||
def test_parse_leap_second
|
||||
t = Time.utc(1998,12,31,23,59,59)
|
||||
t += 1
|
||||
if t.sec == 60
|
||||
assert_equal(t, Time.parse("Thu Dec 31 23:59:60 UTC 1998"))
|
||||
assert_equal(t, Time.parse("Fri Dec 31 23:59:60 -0000 1998"))
|
||||
t.localtime
|
||||
assert_equal(t, Time.parse("Fri Jan 1 08:59:60 +0900 1999"))
|
||||
assert_equal(t, Time.parse("Fri Jan 1 00:59:60 +0100 1999"))
|
||||
assert_equal(t, Time.parse("Fri Dec 31 23:59:60 +0000 1998"))
|
||||
assert_equal(t, Time.parse("Fri Dec 31 22:59:60 -0100 1998"))
|
||||
end
|
||||
end
|
||||
|
||||
def test_rfc2822_leap_second
|
||||
t = Time.utc(1998,12,31,23,59,59)
|
||||
t += 1
|
||||
if t.sec == 60
|
||||
assert_equal(t, Time.rfc2822("Thu, 31 Dec 1998 23:59:60 UTC"))
|
||||
assert_equal(t, Time.rfc2822("Fri, 31 Dec 1998 23:59:60 -0000"))
|
||||
t.localtime
|
||||
assert_equal(t, Time.rfc2822("Fri, 1 Jan 1999 08:59:60 +0900"))
|
||||
assert_equal(t, Time.rfc2822("Fri, 1 Jan 1999 00:59:60 +0100"))
|
||||
assert_equal(t, Time.rfc2822("Fri, 31 Dec 1998 23:59:60 +0000"))
|
||||
assert_equal(t, Time.rfc2822("Fri, 31 Dec 1998 22:59:60 -0100"))
|
||||
end
|
||||
end
|
||||
|
||||
def test_xmlschema_leap_second
|
||||
t = Time.utc(1998,12,31,23,59,59)
|
||||
t += 1
|
||||
if t.sec == 60
|
||||
assert_equal(t, Time.xmlschema("1998-12-31T23:59:60Z"))
|
||||
assert_equal(t, Time.xmlschema("1998-12-31T23:59:60-00:00"))
|
||||
t.localtime
|
||||
assert_equal(t, Time.xmlschema("1999-01-01T08:59:60+09:00"))
|
||||
assert_equal(t, Time.xmlschema("1999-01-01T00:59:60+01:00"))
|
||||
assert_equal(t, Time.xmlschema("1998-12-31T23:59:60+00:00"))
|
||||
assert_equal(t, Time.xmlschema("1998-12-31T22:59:60-01:00"))
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue