[前][次][番号順一覧][スレッド一覧]

ruby-changes:63781

From: Jeremy <ko1@a...>
Date: Sat, 28 Nov 2020 15:41:58 +0900 (JST)
Subject: [ruby-changes:63781] 276f6a225d (master): Don't double fractional seconds when passing timezone object to Time.new

https://git.ruby-lang.org/ruby.git/commit/?id=276f6a225d

From 276f6a225d18561cbe5282b798cb4e416c66079f Mon Sep 17 00:00:00 2001
From: Jeremy Evans <code@j...>
Date: Thu, 26 Nov 2020 21:16:19 -0800
Subject: Don't double fractional seconds when passing timezone object to
 Time.new

I found that fractional seconds were doubled when using the timezone
feature of Time in Sequel's named_timezones extension (which uses
TZInfo for the timezone object), and traced the problem to this code.

There is no subsecx being modified in the utc_to_local call below
this, and I'm not sure why you would want to add in the fractional
seconds unless you assumed the timezone conversion would drop the
existing fractional seconds (TZInfo doesn't drop fractional seconds).

diff --git a/test/ruby/test_time_tz.rb b/test/ruby/test_time_tz.rb
index c9c2b77..dade0bf 100644
--- a/test/ruby/test_time_tz.rb
+++ b/test/ruby/test_time_tz.rb
@@ -752,6 +752,16 @@ class TestTimeTZ::DummyTZ < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_time_tz.rb#L752
   def self.make_timezone(tzname, abbr, utc_offset, abbr2 = nil, utc_offset2 = nil)
     TestTimeTZ::TZ.new(tzname, abbr, utc_offset, abbr2, utc_offset2)
   end
+
+  def test_fractional_second
+    x = Object.new
+    def x.local_to_utc(t); t + 8*3600; end
+    def x.utc_to_local(t); t - 8*3600; end
+
+    t1 = Time.new(2020,11,11,12,13,14.124r, '-08:00')
+    t2 = Time.new(2020,11,11,12,13,14.124r, x)
+    assert_equal(t1, t2)
+  end
 end
 
 begin
-- 
cgit v0.10.2


--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]