mirror of
https://github.com/uutils/coreutils.git
synced 2026-06-10 15:48:22 -07: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:
@@ -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!()
|
||||
|
||||
Reference in New Issue
Block a user