-
-
Notifications
You must be signed in to change notification settings - Fork 982
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 from Long.MIN_VALUE or MAX_VALUE #190
Comments
In essence, the code has been fixed to avoid overflowing the date-time. Given that, I'm not sure what the correct answer is here. Accepting those constructors would require adjusting the millisecond instant to be valid, but resulting in an object that did not match the constructor request. |
I see. Could you explain why this is not the case? I mean - disregarding the Big Bang (or Genesis, for those who are so inclined), the end of the universe (or the Armageddon, again if so inclined), and possibly Einstein's relativity - any number, no matter how big or small, of milliseconds prior or since a defined instant (i.e. epoch) should be a valid time indication, no? Either way, if for whatever theoretical, conceptual or technical reason the range of
This would then make it easy for client code to avoid trying to construct Edit: I do agree with you that making the constructor accept invalid millisecond values but then internally adjusting these (thereby producing an object that does not match the request) would not be a desirable solution. So I'd prefer the |
Any new thoughts on this? |
The problem with allowing min/max is that they tend to result in bugs, especially in time-zone handling, where you need to increase/decrease the value by the time-zone offset. It would be desirable to have known bounds that are tested for. I don't have any immediate plans to work on that, but a well-tested PR with sensible bounds would probably be accepted. See how JSR-310 does it in Java SE 8. |
I am facing this problem as well. It's hard to adopt this change from a backwards compatibility perspective, since I already have a number of dates and ranges created using Long.MAX_VALUE. Moreover, I discovered that only the DateTime constructor was affected by this change. For example, it is still possible to create an Interval with Long.MAX_VALUE, which leads to hard-to-detect, possible runtime errors. Interval bigInterval = new Interval(0,Long.MAX_VALUE);
System.out.println(bigInterval);
System.out.println(bigInterval.getEnd()); Output: 1969-12-31T16:00:00.000-08:00/292278994-08-17T00:12:55.807-07:00
Exception thrown
org.joda.time.IllegalFieldValueException: Value 292278994 for year must be in the range [-292275054,292278993]
at org.joda.time.field.FieldUtils.verifyValueBounds(FieldUtils.java:234)
at org.joda.time.chrono.BasicYearDateTimeField.set(BasicYearDateTimeField.java:83)
at org.joda.time.chrono.ZonedChronology$ZonedDateTimeField.set(ZonedChronology.java:482)
at org.joda.time.base.BaseDateTime.<init>(BaseDateTime.java:129)
at org.joda.time.DateTime.<init>(DateTime.java:236)
at org.joda.time.base.AbstractInterval.getEnd(AbstractInterval.java:83)
at org.joda.time.ReadableInterval$getEnd.call(Unknown Source) |
See issue #100 |
TLDR, no solution likely here |
Thanks for looking into this some more Stephen. |
Doing so may be possible but it would be a lot of work. It would also break compatibility with even more users. My opinion is that the only acceptable solution would be to make Long.MAX_VALUE work, however doing so looks like an equally futile task, and certainly not one I've got time for! |
I understand your reasoning, Stephen. What's your opinion on the Interval constructor issue I reported above? |
Perhaps Interval should be made to match. It is certainly logical. Although as shown here, each fix can cause problems elsewhere! |
Do you have any new thoughts on this? This problem means I've been suck at v2.3 for a long time. |
Try the min/max branch. I won't merge the changes unless I hear they are suitable. |
Hi Stephen, Thanks for spending time on this! I've been running a bunch of tests (I've made my own, not relying on the min/max tests I saw you added in 295f43e).
All these tests passed. So if you ask me the min/max branch is ready to be merged. By the way, when do you think we could expect a new Joda-time release with these changes? Oh and would that release also include tzdata 2015g which was released earlier this month? Best & thanks again! Matthias |
Thanks for testing. When a new release occurs it will include the latest time-zone data. |
…E/MIN_VALUE issue is finally fixed) Signed-off-by: Matthias Stevens <matthias.stevens@gmail.com>
Provide some form of support for date-times up to the min/max of Long At the margins, calculations will be slightly imperfect UTC is used for the min/max Fixes JodaOrg#297 Fixes JodaOrg#190
In joda-time version 2.3 both this ...
... and this ...
... worked perfectly fine.
But since version 2.4 (and still in 2.5) either expression causes an
ArithmeticException
to be thrown:The text was updated successfully, but these errors were encountered: