DateTime comparision at sub-millisecond resolution #1311

Closed
philr opened this Issue Dec 6, 2013 · 1 comment

Projects

None yet

3 participants

@philr
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 = DateTime.new(2013, 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 = DateTime.new(2013, 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 added a commit to tzinfo/tzinfo that referenced this issue Dec 7, 2013
@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.
2fc441e
@headius headius added a commit that referenced this issue Dec 10, 2013
@lucasallan @headius lucasallan + headius Added test case to reproduce issue #1311.
Signed-off-by: Charles Oliver Nutter <headius@headius.com>
b67b419
@headius headius added a commit that referenced this issue Dec 10, 2013
@headius headius Fix spelling of test for #1311. 3e51a6e
@headius
Member
headius commented Dec 10, 2013

Fixed by #1317.

@headius headius closed this Dec 10, 2013
@enebo enebo modified the milestone: 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