Make subtract and addition operators work with DateTime objects#5369
Make subtract and addition operators work with DateTime objects#5369massive wants to merge 1 commit intojruby:masterfrom massive:datetime-regression
Conversation
|
nice - thanks, isn't using longs enough? that round with a hard-coded precision of |
|
@kares Thanks for your input. I agree, the rounding part is a subpar solution. However, while using longs fixes the problem with addition, it's not enough to fix the problems with subtraction. For instance, within the provided spec, the result for I'm not quite yet there to understand how and where to best deal with the problem though. |
|
yeah having floats around is always problematic, think I have some ideas on how to proceed. |
|
also as a work-around you should be able to run fine with JRuby 9.1 .. 9.2.1 release should be close thought |
|
for the record, only the add part is to be considered a regression, the sub-tract doesn't work in 9.1 either: ... we do the calculation "right" in 9.2 ~ the same as in previous JRubies. can not use the rounding as is since (as CI revealed) that introduces more problems, will try to port the |
spec-ed DateTime#- part still failing, for now adjusted from GH-5369
|
pushed a modified commit (with the long fix since its a regression) into master: bf2a83c ... so this doesn't hold up for long. tagged the failing subtract specs, might push a fix for that later - have one but it doesn't scale beyond 5 decimal places. |
so that 'precision' doesn't get lost on `(date + float) - date` ... still mostly just a work-around and does not behave as MRI e.g. `date - 0.00001` passes but `date - 0.000001` doesn't caused by having a different store and thus calculation algorithm anyway at least we're now closer and GH-5369 should pass fine
|
going to close this one, the provided specs are now passing ... there's still more work to do. |
spec-ed DateTime#- part still failing, for now adjusted from jruby/jruby#5369
We recently discovered a few nasty bugs that affect DateTime calculations when the precision of time is high enough.
As a practical example, when subtracting values produced by
DateTime.current(via Active Support), you'll get weird results. e.g.:I traced the problem down to
RubyDate#op_plus_numeric, where value multiplication produce incorrect results seemingly due to floating point inaccuracy. I was able to "fix" the problem using round, but obviously that is not really elegant solution (maybe it should use BigDecimal under the hood or something?).While I was working with this bug, I also discovered another bug, which turned out to be related: namely when adding sub-millisecond precision value to
DateTimeobject, JRuby interpreter threw an error.Both of the bugs are reproducible using provided specs.