date: add support for TZ='timezone' date_spec syntax for GNU compatibility#8607
Closed
sylvestre wants to merge 1 commit intouutils:mainfrom
Closed
date: add support for TZ='timezone' date_spec syntax for GNU compatibility#8607sylvestre wants to merge 1 commit intouutils:mainfrom
sylvestre wants to merge 1 commit intouutils:mainfrom
Conversation
|
GNU testsuite comparison: |
cakebaker
reviewed
Sep 11, 2025
|
|
||
| let output = result.stdout_str(); | ||
| // Should show the parsed date in UTC timezone | ||
| assert!(output.contains("2020-01-01 12:00:00+00:00")); |
Contributor
There was a problem hiding this comment.
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.
cakebaker
reviewed
Sep 11, 2025
Comment on lines
+775
to
+780
| // 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")); |
Contributor
There was a problem hiding this comment.
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
Contributor
|
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. |
Contributor
Author
|
@yuankunzhang yeah, good call. thanks :) |
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
No description provided.