-
Notifications
You must be signed in to change notification settings - Fork 100
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
LocalDateTime arithmetic #66
Comments
The problem with
Somewhat surprisingly, these two approaches give different results. The first one is easier to implement, but it is also often wrong. The reason for that is daylight saving time transitions: if clocks were moved an hour back "during" the addition, then adding two hours to the current time actually represents waiting for three hours. It's easy to forget to handle daylight saving time, and the resulting errors are very annoying, as they won't show up in testing and will most likely cause problems in production. As
This may be either correct or not correct, depending on what you wish to do here, and I'd guess that it's incorrect. In fact, it says to return the wall clock readings after val futureLocalDateTime = localDateTime.toInstant(timeZone)
.plus(7, DateTimeUnit.DAY, timeZone)
.toLocalDateTime(timeZone) This doesn't still guarantee that val futureLocalDateTime = localDateTime.date.plus(DatePeriod(days = 7))
.atTime(localDateTime.hour, localDateTime.minute, localDateTime.second, localDateTime.nanosecond) This will probably be simpler when we implement #57: // doesn't actually work now, subject to change
val futureLocalDateTime = localDateTime.date.plus(DatePeriod(days = 7))
.atTime(localDateTime.time) The bottom line: adding time-based periods to a EDIT: fixed some inaccuracies. |
Currently, the ReadMe does not cover
LocalDateTime
arithmetic. Either make this arithmetic clear by adding this to theInstant
arithmetic, with needs a timeZone.Or add
LocalDateTime
arithmetic without aTimeZone
, which can result into an overflow, like thejava.time
API.I can submit a PR with
LocalDateTime
arithmetic, if wanted.The text was updated successfully, but these errors were encountered: