-
Notifications
You must be signed in to change notification settings - Fork 25
fallible offset conversion #145
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
fallible offset conversion #145
Conversation
1799a31
to
e96aedd
Compare
please add test to make sure it doesn't happen in the future, thanks! |
e96aedd
to
ab91b2b
Compare
#[test] | ||
fn offset_overflow() { | ||
assert!(parse_datetime("m+12").is_err()); | ||
assert!(parse_datetime("24:00").is_err()); |
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.
In another PR I had the fuzzer fail on "m1y-12".
Maybe worth adding?
assert!(parse_datetime("m1y-12").is_ok());
(-12 is an acceptable offset)
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.
Maybe I misunderstand something, but shouldn't it be:
assert!(parse_datetime("m1y-12").is_err());
and
assert!(parse_datetime("m+12").is_ok());
With GNU date
I get:
$ date -d "m1y-12"
date: invalid date ‘m1y-12’
$ date -d "m+12"
Sun May 25 02:00:00 AM CEST 2025
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.
Goodness....
So I have no idea what m1y
is supposed to parse to ,-P But it seems like we accept it, while GNU coreutils always rejects it. So I think this is orthogonal to the problem here. So maybe let's drop my suggestion. Filed #147.
BUT, GNU coreutils accepts all offsets between -24 and +24, so we should do that too:
$ date -d "m"
Sun May 25 02:00:00 PM CEST 2025
$ date -d "m+24"
Sat May 24 02:00:00 PM CEST 2025
$ date -d "m+25"
date: invalid date ‘m+25’
$ date -d "m-25"
date: invalid date ‘m-25’
$ date -d "m-24"
Mon May 26 02:00:00 PM CEST 2025
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.
We are using chrono::FixedOffset
to represent offsets, which accepts offsets only in the range -24 to +24. Note that the literal m+12
will overflow because the letter m
already denotes a +12 offset. Achieving GNU date compatibility in this regard will require re-working the underlining data models. Since this PR is just a trivial fix, I suggest we merge it first and address the larger redesign in a separate effort.
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.
It looks good to me.
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.
Yeah this is fine, let's iterate on that (also curious if jiff
can or cannot help with this, but my conversion has other problems right now...)
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #145 +/- ##
===========================
===========================
☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
No description provided.