Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DateTime comparision at sub-millisecond resolution #1311

philr opened this Issue Dec 6, 2013 · 1 comment


None yet
3 participants
Copy link

philr commented Dec 6, 2013

The DateTime comparison operator in JRuby 1.7.5 and later considers two DateTime instances that differ by less than a millisecond (and by more than 0s) to be equivalent. For example (using JRuby 1.7.9 in 1.9 mode):

 > d1 =, 12, 6, 0, 0, Rational(1, 10000))
=> #<DateTime: 2013-12-06T00:00:00+00:00 ((2456633j,0s,100000n),+0s,2299161j)>
 > d1.day_fraction
=> (1/864000000)
 > d2 =, 12, 6, 0, 0, Rational(2, 10000))
=> #<DateTime: 2013-12-06T00:00:00+00:00 ((2456633j,0s,200000n),+0s,2299161j)>
 > d2.day_fraction
=> (1/432000000)
 > d1 <=> d2
=> 0

d1 is 0.0001s earlier than d2, so d1 <=> d2 should have returned -1 instead of 0.

JRuby 1.7.4, MRI 1.9.3 and MRI 2.0.0 return the correct result.

It looks like the problem is that <=> only compares @dt, but not @sub_millis.

philr added a commit to tzinfo/tzinfo that referenced this issue Dec 7, 2013

Fix test case failures on JRuby >= 1.7.5.
- DateTime on JRuby 1.7.5 only allows offsets of less than 1 day. Change
  uses of 1 day offsets to 1 hour.
- JRuby 1.7.5 considers DateTime instances that differ by less than 1
  millisecond to be equivalent
  (jruby/jruby#1311). Make tests that rely on
  being able to distinguish differences of 1 microsecond adapt if the
  platform doesn't support such comparisons.

headius added a commit that referenced this issue Dec 10, 2013

Added test case to reproduce issue #1311.
Signed-off-by: Charles Oliver Nutter <>

headius added a commit that referenced this issue Dec 10, 2013


This comment has been minimized.

Copy link

headius commented Dec 10, 2013

Fixed by #1317.

@headius headius closed this Dec 10, 2013

@enebo enebo modified the milestones: JRuby 1.7.10, JRuby 1.7.11 Feb 24, 2014

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.