From 00f97ed41a56f8146a8066db0934b574615b9760 Mon Sep 17 00:00:00 2001 From: akr Date: Fri, 9 Jul 2010 11:33:46 +0000 Subject: [PATCH] * time.c (find_time_t): 24:00 should be the beginning of the next day even if the leap second, 23:59:60, exists. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@28588 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ChangeLog | 5 +++++ test/ruby/test_time_tz.rb | 17 +++++++++++++++++ time.c | 3 ++- 3 files changed, 24 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index 4a1e1debb9..cfeffc7772 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +Fri Jul 9 20:30:26 2010 Tanaka Akira + + * time.c (find_time_t): 24:00 should be the beginning of the next + day even if the leap second, 23:59:60, exists. + Fri Jul 9 01:08:46 2010 Aaron Patterson * ext/psych/lib/psych/visitors/emitter.rb (initialize): line_width is diff --git a/test/ruby/test_time_tz.rb b/test/ruby/test_time_tz.rb index 4942d32028..e6b632f2dd 100644 --- a/test/ruby/test_time_tz.rb +++ b/test/ruby/test_time_tz.rb @@ -147,6 +147,23 @@ class TestTimeTZ < Test::Unit::TestCase } end + def test_right_utc + with_tz(tz="right/UTC") { + assert_time_constructor(tz, "2008-12-31 23:59:59 UTC", :utc, [2008,12,31,23,59,59]) + assert_time_constructor(tz, "2008-12-31 23:59:60 UTC", :utc, [2008,12,31,23,59,60]) + assert_time_constructor(tz, "2009-01-01 00:00:00 UTC", :utc, [2008,12,31,24,0,0]) + assert_time_constructor(tz, "2009-01-01 00:00:00 UTC", :utc, [2009,1,1,0,0,0]) + } + end + + def test_right_america_los_angeles + with_tz(tz="right/America/Los_Angeles") { + assert_time_constructor(tz, "2008-12-31 15:59:59 -0800", :local, [2008,12,31,15,59,59]) + assert_time_constructor(tz, "2008-12-31 15:59:60 -0800", :local, [2008,12,31,15,59,60]) + assert_time_constructor(tz, "2008-12-31 16:00:00 -0800", :local, [2008,12,31,16,0,0]) + } + end + MON2NUM = { "Jan" => 1, "Feb" => 2, "Mar" => 3, "Apr" => 4, "May" => 5, "Jun" => 6, "Jul" => 7, "Aug" => 8, "Sep" => 9, "Oct" => 10, "Nov" => 11, "Dec" => 12 diff --git a/time.c b/time.c index 04145f63ea..d2a90d4aa2 100644 --- a/time.c +++ b/time.c @@ -2928,6 +2928,7 @@ find_time_t(struct tm *tptr, int utc_p, time_t *tp) return NULL; } } + /* Given argument has no corresponding time_t. Let's outerpolation. */ /* * `Seconds Since the Epoch' in SUSv3: @@ -2950,7 +2951,7 @@ find_time_t(struct tm *tptr, int utc_p, time_t *tp) tm_lo.tm_yday) * 86400 + (tptr->tm_hour - tm_lo.tm_hour) * 3600 + (tptr->tm_min - tm_lo.tm_min) * 60 + - (tptr->tm_sec - tm_lo.tm_sec); + (tptr->tm_sec - (tm_lo.tm_sec == 60 ? 59 : tm_lo.tm_sec)); return NULL;