-
Notifications
You must be signed in to change notification settings - Fork 41
fix(offset): treat a numeric offset after a time of day as a zone correction #326
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
Open
Socialpranker
wants to merge
1
commit into
uutils:main
Choose a base branch
from
Socialpranker:fix-numeric-offset-before-relative
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+57
−8
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -31,7 +31,7 @@ use winnow::{ | |
| combinator::{alt, peek}, | ||
| error::{ContextError, ErrMode}, | ||
| stream::{AsChar, Stream}, | ||
| token::take_while, | ||
| token::{one_of, take_while}, | ||
| ModalResult, Parser, | ||
| }; | ||
|
|
||
|
|
@@ -193,12 +193,18 @@ pub(super) fn parse_local(input: &mut &str) -> ModalResult<()> { | |
|
|
||
| /// Parse a timezone starting with `+` or `-`. | ||
| pub(super) fn timezone_offset(input: &mut &str) -> ModalResult<Offset> { | ||
| // Strings like "+8 years" are ambiguous, they can either be parsed as a | ||
| // timezone offset "+8" and a relative time "years", or just a relative time | ||
| // "+8 years". GNU date parses them the second way, so we do the same here. | ||
| // | ||
| // Return early if the input can be parsed as a relative time. | ||
| if peek(relative::parse).parse_next(input).is_ok() { | ||
| // A number with a fractional part is never a zone correction: GNU `date` | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 4 lines of comment for this guard, could you please make it one or two? |
||
| // reads `12:00 +1.5 seconds` as the relative item `+1.5 seconds`, not as | ||
| // the offset `+01:00` followed by a stray `.5 seconds`. Backtrack so that | ||
| // the relative parser gets a chance at it. | ||
| let fraction: ModalResult<_> = peek(( | ||
| plus_or_minus, | ||
| s(dec_uint_str), | ||
| '.', | ||
| one_of(AsChar::is_dec_digit), | ||
| )) | ||
| .parse_next(input); | ||
| if fraction.is_ok() { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| return Err(ErrMode::Backtrack(ContextError::new())); | ||
| } | ||
|
|
||
|
|
@@ -433,7 +439,7 @@ mod tests { | |
| "+2500", // invalid: hours > 24 | ||
| "-2361", // invalid: minutes > 60 | ||
| "+2401", // invalid: minutes > 0 when hours == 24 | ||
| "+23 days", // invalid: ambiguous with relative time parsing | ||
| "+25 days", // invalid: hours > 24, even when followed by a relative item | ||
| ] { | ||
| let mut s = input; | ||
| assert!(timezone_offset(&mut s).is_err(), "{input}"); | ||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
out of range is a hard error now, so please check what
date -d '12:00 +30 hours'prints, it should still look like gnu's invalid date