Skip to content

Commit 66a1e84

Browse files
committed
date: add regression test for military time parsing tz correctly
1 parent 7a836e7 commit 66a1e84

File tree

1 file changed

+46
-0
lines changed

1 file changed

+46
-0
lines changed

tests/by-util/test_date.rs

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1132,6 +1132,52 @@ fn test_date_military_timezone_with_offset_variations() {
11321132
}
11331133
}
11341134

1135+
#[test]
1136+
fn test_date_military_timezone_with_offset_and_date() {
1137+
use chrono::{Duration, Utc};
1138+
1139+
let today = Utc::now().date_naive();
1140+
1141+
let test_cases = vec![
1142+
("m", -1), // M = UTC+12
1143+
("a", -1), // A = UTC+1
1144+
("n", 0), // N = UTC-1
1145+
("y", 0), // N = UTC-12
1146+
("z", 0), // Z = UTC
1147+
1148+
// same day hour offsets
1149+
("n2", 0),
1150+
1151+
// midnight crossings with hour offsets back to today
1152+
("a1", 0), // exactly to midnight
1153+
("a5", 0), // "overflow" midnight
1154+
("m23", 0),
1155+
1156+
// midnight crossings with hour offsets to tomorrow
1157+
("n23", 1),
1158+
("y23", 1),
1159+
];
1160+
1161+
for (input, day_delta) in test_cases {
1162+
let expected_date = today
1163+
.checked_add_signed(Duration::days(day_delta))
1164+
.unwrap();
1165+
1166+
let expected = format!(
1167+
"{}\n",
1168+
expected_date.format("%F"),
1169+
);
1170+
1171+
new_ucmd!()
1172+
.env("TZ", "UTC")
1173+
.arg("-d")
1174+
.arg(input)
1175+
.arg("+%F")
1176+
.succeeds()
1177+
.stdout_is(expected);
1178+
}
1179+
}
1180+
11351181
// Locale-aware hour formatting tests
11361182
#[test]
11371183
#[cfg(unix)]

0 commit comments

Comments
 (0)