-
Notifications
You must be signed in to change notification settings - Fork 8
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
Panic when shifting to a DST transition #11
Comments
I am working an a pull request to resolve this issue. |
• `delta::shift_months`, `delta::shift_years` and `delta::with_month` all now have opt counterparts. `delta::day` doesn't need any counterpart as it already behaves as olliemath#11 proposes. • Add a few test assertions for checking `delta::with_month_opt` which, unlike the other new functions, isn't already fully covered by the existing tests.
…trating that issue is resolved.
Hey, thanks for the comprehensive issue. Ah, that's annoying that the fold is not handled by chrono (usually the way you resolve this with datetime types is by having a "fold" attribute which is either 0 or 1, depending on if it's the first or second 2am). A |
Thanks @olliemath, I've sent the PR #12 adding the |
* Issue #11: Add panicking test cases illustrating DST transition issue. * Issue #11: Add `_opt` versions of shift utils. • `delta::shift_months`, `delta::shift_years` and `delta::with_month` all now have opt counterparts. `delta::day` doesn't need any counterpart as it already behaves as #11 proposes. • Add a few test assertions for checking `delta::with_month_opt` which, unlike the other new functions, isn't already fully covered by the existing tests. * Issue #11: Add non-panicking DST transition test cases illustrating that issue is resolved. * Issue #11: Document new `*_opt` shfit utils. * Issue #11 -- Satisfy CI linting checks.
|
Great @olliemath . Much appreciated. |
Firstly, thanks for the library.
Problem
I'm in a timezone which regrettably uses daylight saving tIme.
When taking a
chrono
DST timezone datetime and attempting to applychronoutils
shift utility functions (either directly or indirectly via a relative addition),chronoutils
panics if the computed datetime lands on a DST transition.Examples
Cause
These panics are due to the shift utils unwrapping calls to the
chrono::Datelike::with_*
functions, with the latter's doc currently stating:Proposed Solution
It would be helpful to have
*_opt
versions of the shift utils which return anOption
rather than aDatelike
, for examplepub fn shift_months_opt( .. ) -> Option<Datelike>
This way, the caller can choose how to handle DST issues. A returned
None
won't help the caller distinguish nonsensical input args from args which result in a DST transition, but callers should be able to determine that for themselves.The text was updated successfully, but these errors were encountered: