Skip to content

date: allow negative date offsets #7548

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

Merged
merged 1 commit into from
Mar 26, 2025

Conversation

lewisboon
Copy link
Contributor

Clap needs to be specifically configured to allow values with a leading hyphen

date -d '-2 weeks' is a valid offset.

target/debug/coreutils date -d '-2 weeks'
Sun Mar  9 22:18:35 GMT 2025
date -d '-2 weeks'
Sun  9 Mar 22:18:57 GMT 2025

closes #7515

@@ -410,6 +410,14 @@ fn test_date_string_human() {
}
}

#[test]
fn test_negative_offset() {
let data_formats = vec!["-1 day", "-2 weeks"];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could you please add a check that -1 day is in the past and not in the future ? thanks

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good idea, thanks. I've improved the test to check that the result is +-10 minutes from what we expect. That should give better confidence, but not cause the test to fail intermittently.

Weirdly, I struggled to parse the date when it wasn't rfc-3339, so I ended up adding the --rfc-3339=seconds flag. I can continue to try and get it working if you'd prefer.

Copy link

GNU testsuite comparison:

Skip an intermittent issue tests/timeout/timeout (fails in this run but passes in the 'main' branch)

Issue uutils#7515
Clap needs to be specifically configured to allow values
with a leading hyphen.
@lewisboon lewisboon force-pushed the bugfix/date-negative-offset branch from 68db5fe to b02e3d5 Compare March 24, 2025 22:04
@sylvestre sylvestre merged commit d33d731 into uutils:main Mar 26, 2025
68 checks passed
@sylvestre
Copy link
Contributor

thanks!

@lewisboon lewisboon deleted the bugfix/date-negative-offset branch March 26, 2025 12:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

coreutils date -ud '-2 weeks' produces error: unexpected argument '-2' found
2 participants