Skip to content

Commit 04c82ca

Browse files
committed
Let time::parse::relative::various fail more often
This tests four inputs representing relative times, instead of one, in order to: 1. Reveal GitoxideLabs#1696 during more of the year when the tests are run on machines set to local time in time zones whose rules include daylight savings clock adjustments. 2. Illuminate the nature and limited extent of GitoxideLabs#1696 by trying both "weeks ago" and "minutes ago" input. (It looks like the "minutes ago" input always passes the test, while the "weeks ago" input can fail the test if the interval includes a DST adjustment.) 3. Cover a wider range of inputs more generally, which is probably a good idea even where GitoxideLabs#1696 is not involved. Although these change intend to, and appear to succeed at, triggering more failures due to that but on affected systems set to local time, they are not expected to produce any new failures on CI, since all platforms' GitHub-hosted GHA runners are set to use UTC. With these changes, the failure, when it occurs, looks like: --- STDERR: gix-date::date time::parse::relative::various --- thread 'time::parse::relative::various' panicked at gix-date\tests\time\parse.rs:209:9: assertion `left == right` failed: relative times differ left: [2024-11-08T21:10:19Z, 2024-11-08T21:10:19Z, 2024-07-05T21:10:19Z, 2024-07-05T21:10:19Z] right: [2024-11-08T21:10:19Z, 2024-11-08T21:10:19Z, 2024-07-05T20:10:19Z, 2024-07-05T21:10:19Z]
1 parent 197d31a commit 04c82ca

File tree

1 file changed

+27
-17
lines changed

1 file changed

+27
-17
lines changed

gix-date/tests/time/parse.rs

+27-17
Original file line numberDiff line numberDiff line change
@@ -179,24 +179,34 @@ mod relative {
179179
#[test]
180180
fn various() {
181181
let now = SystemTime::now();
182-
let two_weeks_ago = gix_date::parse("2 weeks ago", Some(now)).unwrap();
183-
assert_eq!(Sign::Plus, two_weeks_ago.sign);
184-
assert_eq!(0, two_weeks_ago.offset);
185-
let expected = Zoned::try_from(now)
186-
.unwrap()
187-
// account for the loss of precision when creating `Time` with seconds
188-
.round(
189-
jiff::ZonedRound::new()
190-
.smallest(jiff::Unit::Second)
191-
.mode(jiff::RoundMode::Trunc),
192-
)
193-
.unwrap()
194-
.saturating_sub(2.weeks());
195-
assert_eq!(
196-
jiff::Timestamp::from_second(two_weeks_ago.seconds).unwrap(),
197-
expected.timestamp(),
198-
"relative times differ"
182+
183+
let cases = [
184+
("2 weeks ago", 2.weeks()),
185+
("20160 minutes ago", 20_160.minutes()), // 2 weeks
186+
("20 weeks ago", 20.weeks()),
187+
("201600 minutes ago", 201_600.minutes()), // 20 weeks
188+
];
189+
190+
let times = cases.map(|(input, _)| gix_date::parse(input, Some(now)).unwrap());
191+
192+
assert_eq!(times.map(|_| Sign::Plus), times.map(|time| time.sign));
193+
assert_eq!(times.map(|_| 0), times.map(|time| time.offset));
194+
195+
let expected = cases.map(|(_, span)|
196+
Zoned::try_from(now)
197+
.unwrap()
198+
// account for the loss of precision when creating `Time` with seconds
199+
.round(
200+
jiff::ZonedRound::new()
201+
.smallest(jiff::Unit::Second)
202+
.mode(jiff::RoundMode::Trunc),
203+
)
204+
.unwrap()
205+
.saturating_sub(span)
206+
.timestamp()
199207
);
208+
let actual = times.map(|time| jiff::Timestamp::from_second(time.seconds).unwrap());
209+
assert_eq!(actual, expected, "relative times differ");
200210
}
201211
}
202212

0 commit comments

Comments
 (0)