-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
date: add support for TZ='timezone' date_spec syntax for GNU compatibility #8607
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
base: main
Are you sure you want to change the base?
Conversation
GNU testsuite comparison:
|
|
||
let output = result.stdout_str(); | ||
// Should show the parsed date in UTC timezone | ||
assert!(output.contains("2020-01-01 12:00:00+00:00")); |
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.
Hm, with GNU date
I get a different result:
$ date --rfc-3339=seconds --date='TZ="UTC" 2020-01-01 12:00:00'
2020-01-01 13:00:00+01:00
$ cargo run -q date --rfc-3339=seconds --date='TZ="UTC" 2020-01-01 12:00:00'
2020-01-01 12:00:00+00:00
As I'm in UTC+1, it looks like GNU date
gives some local setting a higher priority than the TZ="UTC"
in the date string.
// Also verify with regular format that it doesn't contain 2020 | ||
let regular_result = new_ucmd!() | ||
.arg("-d") | ||
.arg("TZ=\"INVALID_TZ\" 2020-01-01") | ||
.succeeds(); | ||
assert!(!regular_result.stdout_str().contains("2020")); |
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.
Here I also get a different result with GNU date
as the output contains the specified date:
$ date --date="TZ=\"INVALID_TZ\" 2020-01-01"
Wed Jan 1 01:00:00 AM CET 2020
$ cargo run -q date --date="TZ=\"INVALID_TZ\" 2020-01-01"
Thu Sep 11 10:33:02 CEST 2025
Isn't this feature more appropriate to be implemented in the parse_datetime crate? The parse_datetime crate already has the infrastructure to make the parsing of the "TZ='timezone'" spec easy. We are waiting for this PR. Since it has been stalled for some time, I will take up and implement it sometime this weekend. |
No description provided.