summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorakr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2005-06-16 04:00:01 +0000
committerakr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2005-06-16 04:00:01 +0000
commitdc2ad49ea6274476bd5fbe1798a14ee14754b1e8 (patch)
tree792848512cb1d605fa62907245c35cb50ce18da9
parente8f46293b6bf786db3d71b356f8aab34b4d8d118 (diff)
downloadruby-dc2ad49ea6274476bd5fbe1798a14ee14754b1e8.tar.gz
ruby-dc2ad49ea6274476bd5fbe1798a14ee14754b1e8.tar.xz
ruby-dc2ad49ea6274476bd5fbe1798a14ee14754b1e8.zip
* 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: http://svn.ruby-lang.org/repos/ruby/branches/ruby_1_8@8629 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r--ChangeLog8
-rw-r--r--lib/time.rb54
2 files changed, 58 insertions, 4 deletions
diff --git a/ChangeLog b/ChangeLog
index eeeed028e..68c9969ac 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -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.
diff --git a/lib/time.rb b/lib/time.rb
index e0d831d3b..1fd897f1b 100644
--- a/lib/time.rb
+++ b/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