1
Fork 0
mirror of https://github.com/RGBCube/uutils-coreutils synced 2025-07-27 19:17:43 +00:00

test_date: Expand on test_date_utc_time

Using the current time requires a bit of care, but it's nice
to have a test that doesn't use a fixed date as input.
This commit is contained in:
Nicolas Boichat 2025-06-01 20:00:42 +02:00
parent 5d75e28b87
commit 66d1e8a872

View file

@ -657,7 +657,39 @@ fn test_date_tz_with_relative_time() {
#[test]
fn test_date_utc_time() {
// Test that -u flag shows correct UTC time
new_ucmd!().arg("-u").arg("+%H:%M").succeeds();
// We get 2 UTC times just in case we're really unlucky and this runs around
// an hour change.
let utc_hour_1: i32 = new_ucmd!()
.env("TZ", "Asia/Taipei")
.arg("-u")
.arg("+%-H")
.succeeds()
.stdout_str()
.trim_end()
.parse()
.unwrap();
let tpe_hour: i32 = new_ucmd!()
.env("TZ", "Asia/Taipei")
.arg("+%-H")
.succeeds()
.stdout_str()
.trim_end()
.parse()
.unwrap();
let utc_hour_2: i32 = new_ucmd!()
.env("TZ", "Asia/Taipei")
.arg("-u")
.arg("+%-H")
.succeeds()
.stdout_str()
.trim_end()
.parse()
.unwrap();
// Taipei is always 8 hours ahead of UTC (no daylight savings)
assert!(
(tpe_hour - utc_hour_1 + 24) % 24 == 8 || (tpe_hour - utc_hour_2 + 24) % 24 == 8,
"TPE: {tpe_hour} UTC: {utc_hour_1}/{utc_hour_2}"
);
// Test that -u flag shows UTC timezone
new_ucmd!()