-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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
Date Rounding #17037
Date Rounding #17037
Conversation
We already have |
Yes, huge 👍 to this. Great PR, @spurll |
|
||
This means that rounding seconds, minutes, hours, or years (because the ISO 8601 | ||
specification includes a year zero) to an even multiple will result in that field having | ||
an even value, while rounding to an even multiple of months will result in that field |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what's the difference here? rounding to an even multiple (of what) results in even, when rounding to an even multiple of months results in odd?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, I think I worded that poorly. It should read, "This means that rounding a DateTime
to an even multiple of seconds, minutes, ... will result in that field having an even value in the resulting DateTime
, while rounding a DateTime
to an even multiple of months will result in the months field having an odd value."
I'm not sure if the use case would be sufficiently common for it to warrant comment, but I figured somebody might wonder why rounding a Date
(Time
) to Month(2)
returns an odd-numbered month instead of an even-numbered month (as might be expected).
Hm. Of the three Travis jobs, one was successful (Linux 32), one ran out of storage space (Linux 64), and one was terminated because it took too long (OS X). |
Nice! Will this also be able to handle when the provided strings are overspecified? See http://stackoverflow.com/questions/37971649/parsing-zulu-dates-in-julia-throws-inexacterror for an example of what I mean. |
@tlycken: That behaviour will not be affected by this PR. The |
Hi @spurll, can you rebase to make this mergeable? |
Absolutely. Doing that now. Just had to add a quick fix to disallow rounding to non-positive |
Dependent on [PR #17037](JuliaLang/julia#17037) in Base Julia
Throw DomainError on rounding to an invalid (non-positive) resolution Clean up test cases for rounding dates that don't need rounding Add test cases for rounding to invalid (non-positive) resolutions
This is good to go now; would be nice to get it in for 0.5. |
* Added floor, ceil, round for Date and DateTime. * Refactoring and documentation for date rounding. * Added PR reference in NEWS.md. * Bugfix for date rounding test in 32-bit. Doc clarifications. * Round to nonpositive resolution throws DomainError Throw DomainError on rounding to an invalid (non-positive) resolution Clean up test cases for rounding dates that don't need rounding Add test cases for rounding to invalid (non-positive) resolutions
Adds methods to allow rounding
Date
andDateTime
values to a specified resolution (1 month, 15 minutes, etc.) withfloor
,ceil
, andround
.While we at Invenia believe that this functionality is useful and appropriate for base Julia, it could also be put in an external package in JuliaTime if the community feels otherwise.