diff options
author | Jeremy Evans <code@jeremyevans.net> | 2019-07-17 14:53:55 -0700 |
---|---|---|
committer | Hiroshi SHIBATA <hsbt@ruby-lang.org> | 2019-10-24 18:39:04 +0900 |
commit | 9eb798a3f1de6a9e08e510904d376952d5e94d50 (patch) | |
tree | d000971b8e7f0fa83890453064a87f884eec4d45 /test | |
parent | f1de438380893682257b8648784a0fe7714b1f9f (diff) | |
download | ruby-9eb798a3f1de6a9e08e510904d376952d5e94d50.tar.gz |
[ruby/date] Make julian dates roundtrip through to_time.to_date
Previously, julian dates would not round trip through to_time.to_date,
because Time is always considered gregorian. This converts the Date
instance from julian to gregorian before converting to Time, ensuring
that an equal date object will be returned if converting that Time
back to Date.
This does result in julian Date objects showing different day values
if converting to Time.
Fixes Ruby Bug 8428.
https://github.com/ruby/date/commit/d8df64555e
Diffstat (limited to 'test')
-rw-r--r-- | test/date/test_date_conv.rb | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/test/date/test_date_conv.rb b/test/date/test_date_conv.rb index 5c295daba6..d41ff45d85 100644 --- a/test/date/test_date_conv.rb +++ b/test/date/test_date_conv.rb @@ -48,6 +48,24 @@ class TestDateConv < Test::Unit::TestCase [t.year, t.mon, t.mday, t.hour, t.min, t.sec, t.usec]) end + def test_to_time_to_date_roundtrip__from_gregorian_date + d = Date.new(1582, 10, 15) + t = d.to_time + assert_equal([1582, 10, 15, 0, 0, 0, 0], + [t.year, t.mon, t.mday, t.hour, t.min, t.sec, t.usec]) + assert_equal(d, t.to_date) + assert_equal(d.jd, t.to_date.jd) + end + + def test_to_time_to_date_roundtrip__from_julian_date + d = Date.new(1582, 10, 4) + t = d.to_time + assert_equal([1582, 10, 14, 0, 0, 0, 0], + [t.year, t.mon, t.mday, t.hour, t.min, t.sec, t.usec]) + assert_equal(d, t.to_date) + assert_equal(d.jd, t.to_date.jd) + end + def test_to_time__from_datetime d = DateTime.new(2004, 9, 19, 1, 2, 3, 8.to_r/24) + 456789.to_r/86400000000 t = d.to_time |