-
-
Notifications
You must be signed in to change notification settings - Fork 942
Closed
Milestone
Description
Hello,
There seems to be a problem with the Julian day of a DateTime object when the latter has been initialized specifying a negative offset. With JRuby 1.7.13 and MRI 2.1.2:
>> require 'date'
=> true
>> without_offset = DateTime.civil(1999, 12, 31, 19, 0, 0);
>> with_offset = DateTime.civil(1999, 12, 31, 19, 0, 0, Rational(-5, 24))
>> RUBY_ENGINE
=> "jruby"
>> without_offset.jd
=> 2451544
>> with_offset.jd
=> 2451545 # Incremented by 1
>> RUBY_ENGINE
=> "ruby"
>> without_offset.jd
=> 2451544
>> with_offset.jd
=> 2451544The bug isn't reproducible with any Rational object. It looks like it should be negative and close to 0 (e.g. -5 / 24.0 works but 5 / 24.0 don't). Here's a failing test:
diff --git a/test/mri/date/test_date_new.rb b/test/mri/date/test_date_new.rb
index 0bbbfee..bebafbe 100644
--- a/test/mri/date/test_date_new.rb
+++ b/test/mri/date/test_date_new.rb
@@ -31,6 +31,13 @@ class TestDateNew < Test::Unit::TestCase
end
end
+ def test_jd__with_offset
+ without_offset = DateTime.civil(1999, 12, 31, 19, 0, 0)
+ with_offset = DateTime.civil(1999, 12, 31, 19, 0, 0, Rational(-5, 24))
+
+ assert_equal without_offset.jd, with_offset.jd
+ end
+
def test_ordinal
d = Date.ordinal
dt = DateTime.ordinalHave a nice day.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels