Skip to content

Commit d140ad4

Browse files
committed
refactor
- place expectations to the right, actuals on the left. - fix test expectation and make clear that relative dates are all UTC.
1 parent 3082d40 commit d140ad4

File tree

1 file changed

+25
-13
lines changed

1 file changed

+25
-13
lines changed

gix-date/tests/time/parse.rs

+25-13
Original file line numberDiff line numberDiff line change
@@ -226,21 +226,33 @@ mod relative {
226226
let time = gix_date::parse(input, Some(now)).expect("relative time string should parse to a Time");
227227
(input, time)
228228
});
229-
assert_eq!(with_times.map(|_| Sign::Plus), with_times.map(|(_, time)| time.sign));
230-
assert_eq!(with_times.map(|_| 0), with_times.map(|(_, time)| time.offset));
229+
assert_eq!(
230+
with_times.map(|(_, time)| time.sign),
231+
with_times.map(|_| Sign::Plus),
232+
"Despite being in the past, the dates produced are positive, as they are still post-epoch"
233+
);
234+
assert_eq!(
235+
with_times.map(|(_, time)| time.offset),
236+
with_times.map(|_| 0),
237+
"They don't pick up local time"
238+
);
231239

232240
let with_expected = cases.map(|(input, span)| {
233-
let expected = Zoned::try_from(now)
234-
.expect("test needs to convert current time to a timestamp")
235-
// account for the loss of precision when creating `Time` with seconds
236-
.round(
237-
jiff::ZonedRound::new()
238-
.smallest(jiff::Unit::Second)
239-
.mode(jiff::RoundMode::Trunc),
240-
)
241-
.expect("test needs to truncate current timestamp to seconds")
242-
.saturating_sub(span)
243-
.timestamp();
241+
let expected = Zoned::new(
242+
now.try_into().expect("system time is representable"),
243+
// As relative dates are always UTC in Git, we do the same, and must
244+
// compare to UTC as well or else time might be off due to daylight savings, etc.
245+
jiff::tz::TimeZone::UTC,
246+
)
247+
// account for the loss of precision when creating `Time` with seconds
248+
.round(
249+
jiff::ZonedRound::new()
250+
.smallest(jiff::Unit::Second)
251+
.mode(jiff::RoundMode::Trunc),
252+
)
253+
.expect("test needs to truncate current timestamp to seconds")
254+
.saturating_sub(span)
255+
.timestamp();
244256

245257
(input, expected)
246258
});

0 commit comments

Comments
 (0)