date: add tests to match GNU's (#10939)

* date: add test for rel-2b GNU test

Test correct month arithmetic maintaining same day of month, and
month overflow when day doesn't exist in target month.

* date: add test for cross-TZ-mishandled GNU test

Test parsing dates with embedded timezone specifications.
This commit is contained in:
Sylvestre Ledru
2026-02-14 13:55:16 -08:00
committed by GitHub
parent c4e3ca658a
commit 6d9af5ae77
+35
View File
@@ -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");
}