aboutsummaryrefslogtreecommitdiffstats
path: root/test/date
diff options
context:
space:
mode:
authorNobuyoshi Nakada <nobu@ruby-lang.org>2022-08-08 22:43:56 +0900
committergit <svn-admin@ruby-lang.org>2022-08-08 23:50:17 +0900
commite07d450deae500422b7693a30c75c5b1567601a2 (patch)
tree856b46413ab3f44a41612f13127e4758b1219602 /test/date
parent43239b23b48a6c3fde6bdc4b9cc568bedac161b2 (diff)
downloadruby-e07d450deae500422b7693a30c75c5b1567601a2.tar.gz
[ruby/date] Fix Time#to_datetime before calendar reform
Time is always in the proleptic Gregorian calendar. Also DateTime#to_time should convert to the Gregorian calendar first, before extracting its components. https://bugs.ruby-lang.org/issues/18946#change-98527 https://github.com/ruby/date/commit/b2aee75248
Diffstat (limited to 'test/date')
-rw-r--r--test/date/test_date_conv.rb17
1 files changed, 17 insertions, 0 deletions
diff --git a/test/date/test_date_conv.rb b/test/date/test_date_conv.rb
index d41ff45d85..ed478b41bb 100644
--- a/test/date/test_date_conv.rb
+++ b/test/date/test_date_conv.rb
@@ -77,6 +77,11 @@ class TestDateConv < Test::Unit::TestCase
assert_equal([2004, 9, 19, 1, 2, 3, 456789],
[t.year, t.mon, t.mday, t.hour, t.min, t.sec, t.usec])
+ d = DateTime.new(1582, 10, 3, 1, 2, 3, 0) + 456789.to_r/86400000000
+ t = d.to_time.utc
+ assert_equal([1582, 10, 13, 1, 2, 3, 456789],
+ [t.year, t.mon, t.mday, t.hour, t.min, t.sec, t.usec])
+
if Time.allocate.respond_to?(:nsec)
d = DateTime.new(2004, 9, 19, 1, 2, 3, 0) + 456789123.to_r/86400000000000
t = d.to_time.utc
@@ -100,6 +105,10 @@ class TestDateConv < Test::Unit::TestCase
t = Time.utc(2004, 9, 19, 1, 2, 3, 456789)
d = t.to_date
assert_equal([2004, 9, 19, 0], [d.year, d.mon, d.mday, d.day_fraction])
+
+ t = Time.utc(1582, 10, 13, 1, 2, 3, 456789)
+ d = t.to_date # using ITALY
+ assert_equal([1582, 10, 3, 0], [d.year, d.mon, d.mday, d.day_fraction])
end
def test_to_date__from_date
@@ -136,6 +145,14 @@ class TestDateConv < Test::Unit::TestCase
[d.year, d.mon, d.mday, d.hour, d.min, d.sec,
d.sec_fraction, d.offset])
+ t = Time.utc(1582, 10, 13, 1, 2, 3, 456789)
+ d = t.to_datetime # using ITALY
+ assert_equal([1582, 10, 3, 1, 2, 3,
+ 456789.to_r/1000000,
+ 0],
+ [d.year, d.mon, d.mday, d.hour, d.min, d.sec,
+ d.sec_fraction, d.offset])
+
t = Time.now
d = t.to_datetime
require 'time'