Skip to content

Commit 7edd045

Browse files
committed
date: use UTC if TZ is empty
1 parent ada1886 commit 7edd045

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

src/uu/date/src/date.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
277277
// TODO - Revisit when chrono 0.5 is released. https://github.com/chronotope/chrono/issues/970
278278
let tz = match std::env::var("TZ") {
279279
// TODO Support other time zones...
280-
Ok(s) if s == "UTC0" => Tz::Etc__UTC,
280+
Ok(s) if s == "UTC0" || s.is_empty() => Tz::Etc__UTC,
281281
_ => match get_timezone() {
282282
Ok(tz_str) => tz_str.parse().unwrap(),
283283
Err(_) => Tz::Etc__UTC,

tests/by-util/test_date.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -482,3 +482,12 @@ fn test_date_from_stdin() {
482482
Sat Apr 15 18:30:00 UTC 2023\n",
483483
);
484484
}
485+
486+
#[test]
487+
fn test_date_empty_tz() {
488+
new_ucmd!()
489+
.env("TZ", "")
490+
.arg("+%Z")
491+
.succeeds()
492+
.stdout_only("UTC\n");
493+
}

0 commit comments

Comments
 (0)