date: use UTC if TZ is empty

This commit is contained in:
Daniel Hofstetter
2025-01-16 11:44:45 +01:00
parent ada18863a7
commit 7edd045206
2 changed files with 10 additions and 1 deletions
+1 -1
View File
@@ -277,7 +277,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
// TODO - Revisit when chrono 0.5 is released. https://github.com/chronotope/chrono/issues/970
let tz = match std::env::var("TZ") {
// TODO Support other time zones...
Ok(s) if s == "UTC0" => Tz::Etc__UTC,
Ok(s) if s == "UTC0" || s.is_empty() => Tz::Etc__UTC,
_ => match get_timezone() {
Ok(tz_str) => tz_str.parse().unwrap(),
Err(_) => Tz::Etc__UTC,
+9
View File
@@ -482,3 +482,12 @@ fn test_date_from_stdin() {
Sat Apr 15 18:30:00 UTC 2023\n",
);
}
#[test]
fn test_date_empty_tz() {
new_ucmd!()
.env("TZ", "")
.arg("+%Z")
.succeeds()
.stdout_only("UTC\n");
}