diff options
author | zverok <zverok.offline@gmail.com> | 2022-12-06 19:57:51 +0200 |
---|---|---|
committer | git <svn-admin@ruby-lang.org> | 2022-12-13 19:52:06 +0000 |
commit | 1859784422ca7f19710bbfb1b12b46fdd8ecf3cb (patch) | |
tree | e820848bbeff7e921c52a768e69d7834fca2cca9 /test/date | |
parent | 25f727d4caf72056b5c88ac2ea292093a9a06099 (diff) | |
download | ruby-1859784422ca7f19710bbfb1b12b46fdd8ecf3cb.tar.gz |
[ruby/date] Implement Date#deconstruct_keys and DateTime#deconstruct_keys
https://github.com/ruby/date/commit/6bb6d3a810
Diffstat (limited to 'test/date')
-rw-r--r-- | test/date/test_date.rb | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/test/date/test_date.rb b/test/date/test_date.rb index 6e99bc562c..3f9c893efa 100644 --- a/test/date/test_date.rb +++ b/test/date/test_date.rb @@ -175,4 +175,33 @@ class TestDate < Test::Unit::TestCase assert_equal(-1, -Float::INFINITY <=> Date::Infinity.new) assert_equal(-1, -Date::Infinity.new <=> Float::INFINITY) end + + def test_deconstruct_keys + d = Date.new(1999,5,23) + assert_equal({year: 1999, month: 5, day: 23, wday: 0, yday: 143}, d.deconstruct_keys(nil)) + assert_equal({year: 1999}, d.deconstruct_keys([:year, :century])) + assert_equal( + {year: 1999, month: 5, day: 23, wday: 0, yday: 143}, + d.deconstruct_keys([:year, :month, :day, :wday, :yday]) + ) + + dt = DateTime.new(1999, 5, 23, 4, 20, Rational(1, 10000)) + + assert_equal( + {year: 1999, month: 5, day: 23, wday: 0, yday: 143, + hour: 4, min: 20, sec: 0, sec_fraction: Rational(1, 10000), zone: "+00:00"}, + dt.deconstruct_keys(nil) + ) + + assert_equal({year: 1999}, dt.deconstruct_keys([:year, :century])) + + assert_equal( + {year: 1999, month: 5, day: 23, wday: 0, yday: 143, + hour: 4, min: 20, sec: 0, sec_fraction: Rational(1, 10000), zone: "+00:00"}, + dt.deconstruct_keys([:year, :month, :day, :wday, :yday, :hour, :min, :sec, :sec_fraction, :zone]) + ) + + dtz = DateTime.parse('3rd Feb 2001 04:05:06+03:30') + assert_equal({zone: '+03:30'}, dtz.deconstruct_keys([:zone])) + end end |