From 6538f67d4dccc32f1613be188a0748f0d4f90a05 Mon Sep 17 00:00:00 2001 From: naruse Date: Thu, 5 Jul 2018 11:43:42 +0000 Subject: Re-apply r63848 (Optimize Time.utc) * Both timegmw and gmtimew ignores leap second if the timezone doesn't have leap seconds on the first call of init_leap_second_info() * Add Bug::Time.reset_leap_second_info for testing git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@63857 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- test/ruby/test_time_tz.rb | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) (limited to 'test') diff --git a/test/ruby/test_time_tz.rb b/test/ruby/test_time_tz.rb index d138bcece1..43758d948f 100644 --- a/test/ruby/test_time_tz.rb +++ b/test/ruby/test_time_tz.rb @@ -1,5 +1,6 @@ # frozen_string_literal: false require 'test/unit' +require '-test-/time' class TestTimeTZ < Test::Unit::TestCase has_right_tz = true @@ -210,6 +211,7 @@ class TestTimeTZ < Test::Unit::TestCase def test_right_utc with_tz(tz="right/UTC") { + ::Bug::Time.reset_leap_second_info 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]) @@ -217,6 +219,31 @@ class TestTimeTZ < Test::Unit::TestCase } end if has_right_tz + def test_right_utc_switching + with_tz("UTC") { # ensure no leap second timezone + ::Bug::Time.reset_leap_second_info + assert_equal(4102444800, Time.utc(2100,1,1,0,0,0).to_i) + 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, "2009-01-01 00:00:00 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]) + assert_equal(4102444800, Time.utc(2100,1,1,0,0,0).to_i) + } + } + with_tz("right/UTC") { + ::Bug::Time.reset_leap_second_info + assert_equal(4102444827, Time.utc(2100,1,1,0,0,0).to_i) + with_tz(tz="UTC") { + assert_time_constructor(tz, "2008-12-31 23:59:59 UTC", :utc, [2008,12,31,23,59,59]) + assert_time_constructor(tz, "2009-01-01 00:00:00 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]) + assert_equal(4102444827, Time.utc(2100,1,1,0,0,0).to_i) + } + } + end if has_right_tz + 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]) @@ -281,6 +308,7 @@ class TestTimeTZ < Test::Unit::TestCase mesg = "#{mesg_utc}.localtime" define_method(gen_test_name(tz)) { with_tz(tz) { + ::Bug::Time.reset_leap_second_info t = nil assert_nothing_raised(mesg) { t = Time.utc(*u) } assert_equal(expected_utc, time_to_s(t), mesg_utc) -- cgit v1.2.3