Skip to content

Commit

Permalink
refactor
Browse files Browse the repository at this point in the history
 - place expectations to the right, actuals on the left.
 - fix test expectation and make clear that relative dates are all UTC.
  • Loading branch information
Byron committed Nov 25, 2024
1 parent 3082d40 commit d140ad4
Showing 1 changed file with 25 additions and 13 deletions.
38 changes: 25 additions & 13 deletions gix-date/tests/time/parse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -226,21 +226,33 @@ mod relative {
let time = gix_date::parse(input, Some(now)).expect("relative time string should parse to a Time");
(input, time)
});
assert_eq!(with_times.map(|_| Sign::Plus), with_times.map(|(_, time)| time.sign));
assert_eq!(with_times.map(|_| 0), with_times.map(|(_, time)| time.offset));
assert_eq!(
with_times.map(|(_, time)| time.sign),
with_times.map(|_| Sign::Plus),
"Despite being in the past, the dates produced are positive, as they are still post-epoch"
);
assert_eq!(
with_times.map(|(_, time)| time.offset),
with_times.map(|_| 0),
"They don't pick up local time"
);

let with_expected = cases.map(|(input, span)| {
let expected = Zoned::try_from(now)
.expect("test needs to convert current time to a timestamp")
// account for the loss of precision when creating `Time` with seconds
.round(
jiff::ZonedRound::new()
.smallest(jiff::Unit::Second)
.mode(jiff::RoundMode::Trunc),
)
.expect("test needs to truncate current timestamp to seconds")
.saturating_sub(span)
.timestamp();
let expected = Zoned::new(
now.try_into().expect("system time is representable"),
// As relative dates are always UTC in Git, we do the same, and must
// compare to UTC as well or else time might be off due to daylight savings, etc.
jiff::tz::TimeZone::UTC,
)
// account for the loss of precision when creating `Time` with seconds
.round(
jiff::ZonedRound::new()
.smallest(jiff::Unit::Second)
.mode(jiff::RoundMode::Trunc),
)
.expect("test needs to truncate current timestamp to seconds")
.saturating_sub(span)
.timestamp();

(input, expected)
});
Expand Down

0 comments on commit d140ad4

Please sign in to comment.