Skip to content


Subversion checkout URL

You can clone with
Download ZIP


DateTime comparision at sub-millisecond resolution #1311

philr opened this Issue · 1 comment

3 participants


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 philr referenced this issue from a commit in tzinfo/tzinfo
@philr philr 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 headius referenced this issue from a commit
@lucasallan lucasallan Added test case to reproduce issue #1311.
Signed-off-by: Charles Oliver Nutter <>

Fixed by #1317.

@headius headius closed this
@enebo enebo modified the milestone: JRuby 1.7.10, JRuby 1.7.11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.