diff --git a/tests/by-util/test_date.rs b/tests/by-util/test_date.rs index 0748fd322..ffbb4a2be 100644 --- a/tests/by-util/test_date.rs +++ b/tests/by-util/test_date.rs @@ -2136,3 +2136,38 @@ fn test_date_leap1_leap_year_overflow() { .succeeds() .stdout_is("2000-02-29\n"); } + +// Tests for GNU test rel-2b: month arithmetic precision +#[test] +fn test_date_rel2b_month_arithmetic() { + // GNU test rel-2b: Subtracting months should maintain same day of month + new_ucmd!() + .args(&[ + "--date", + "1997-01-19 08:17:48 +0 7 months ago", + "+%Y-%m-%d %T", + ]) + .succeeds() + .stdout_contains("1996-06-19"); + + // Month overflow: Adding months should overflow to next month if day doesn't exist + new_ucmd!() + .args(&["--date", "1996-01-31 + 1 month", "+%Y-%m-%d"]) + .succeeds() + .stdout_is("1996-03-02\n"); +} + +// Tests for GNU test cross-TZ-mishandled: embedded timezone parsing +#[test] +fn test_date_cross_tz_mishandled() { + // GNU test cross-TZ-mishandled: Parse date with embedded timezone + // Date should be interpreted in embedded TZ, then displayed in environment TZ + new_ucmd!() + .env("TZ", "PST8") + .env("LC_ALL", "C") + .args(&["-d", r#"TZ="EST5" 1970-01-01 00:00"#]) + .succeeds() + .stdout_contains("Dec 31") + .stdout_contains("21:00:00") + .stdout_contains("1969"); +}