diff options
| author | Nobuyoshi Nakada <nobu@ruby-lang.org> | 2025-10-29 18:40:25 +0900 |
|---|---|---|
| committer | git <svn-admin@ruby-lang.org> | 2025-10-29 10:03:50 +0000 |
| commit | e49e0bb6c9b4ade9d8fb615a1f7cc65f9ea13a7f (patch) | |
| tree | 367673e11811831864d83d848ab358751582ed80 | |
| parent | 0f629083722a09f0b5a75040ca0511e71eb6032a (diff) | |
[ruby/date] Remove archaic conditions
`Time#nsec` and `Time#subsec` were both introduced in Ruby 1.9.
https://github.com/ruby/date/commit/2c310d9f5c
| -rw-r--r-- | test/date/test_date_conv.rb | 20 |
1 files changed, 8 insertions, 12 deletions
diff --git a/test/date/test_date_conv.rb b/test/date/test_date_conv.rb index c54a118f8f..8d81084435 100644 --- a/test/date/test_date_conv.rb +++ b/test/date/test_date_conv.rb @@ -82,21 +82,17 @@ class TestDateConv < Test::Unit::TestCase 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.method_defined?(:nsec) - d = DateTime.new(2004, 9, 19, 1, 2, 3, 0) + 456789123.to_r/86400000000000 - t = d.to_time.utc - assert_equal([2004, 9, 19, 1, 2, 3, 456789123], - [t.year, t.mon, t.mday, t.hour, t.min, t.sec, t.nsec]) - end + d = DateTime.new(2004, 9, 19, 1, 2, 3, 0) + 456789123.to_r/86400000000000 + t = d.to_time.utc + assert_equal([2004, 9, 19, 1, 2, 3, 456789123], + [t.year, t.mon, t.mday, t.hour, t.min, t.sec, t.nsec]) # TruffleRuby does not support more than nanoseconds unless RUBY_ENGINE == 'truffleruby' - if Time.method_defined?(:subsec) - d = DateTime.new(2004, 9, 19, 1, 2, 3, 0) + 456789123456789123.to_r/86400000000000000000000 - t = d.to_time.utc - assert_equal([2004, 9, 19, 1, 2, 3, Rational(456789123456789123,1000000000000000000)], - [t.year, t.mon, t.mday, t.hour, t.min, t.sec, t.subsec]) - end + d = DateTime.new(2004, 9, 19, 1, 2, 3, 0) + 456789123456789123.to_r/86400000000000000000000 + t = d.to_time.utc + assert_equal([2004, 9, 19, 1, 2, 3, Rational(456789123456789123,1000000000000000000)], + [t.year, t.mon, t.mday, t.hour, t.min, t.sec, t.subsec]) end end |
