Skip to content

Commit 438ee47

Browse files
authored
Merge pull request #1697 from EliahKagan/run-ci/duration
Reveal local-time DST ambiguity where it occurs
2 parents 197d31a + ac17b62 commit 438ee47

File tree

3 files changed

+38
-19
lines changed

3 files changed

+38
-19
lines changed

Cargo.lock

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

gix-date/Cargo.toml

+2-1
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,10 @@ thiserror = "2.0.0"
2828
document-features = { version = "0.2.0", optional = true }
2929

3030
[dev-dependencies]
31+
gix-hash = { path = "../gix-hash" }
3132
gix-testtools = { path = "../tests/tools" }
3233
once_cell = "1.12.0"
33-
gix-hash = { path = "../gix-hash" }
34+
pretty_assertions = "1.4.1"
3435

3536
[package.metadata.docs.rs]
3637
all-features = true

gix-date/tests/time/parse.rs

+35-18
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,7 @@ mod relative {
156156

157157
use gix_date::time::Sign;
158158
use jiff::{ToSpan, Zoned};
159+
use pretty_assertions::assert_eq;
159160

160161
#[test]
161162
fn large_offsets() {
@@ -179,24 +180,40 @@ mod relative {
179180
#[test]
180181
fn various() {
181182
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"
199-
);
183+
184+
let cases = [
185+
("2 weeks ago", 2.weeks()),
186+
("14 weeks ago", 14.weeks()),
187+
("26 weeks ago", 26.weeks()),
188+
("38 weeks ago", 38.weeks()),
189+
("50 weeks ago", 50.weeks()),
190+
("20160 minutes ago", 20_160.minutes()), // 2 weeks
191+
("141120 minutes ago", 141_120.minutes()), // 14 weeks
192+
("262080 minutes ago", 262_080.minutes()), // 26 weeks
193+
("383040 minutes ago", 383_040.minutes()), // 38 weeks
194+
("504000 minutes ago", 504_000.minutes()), // 50 weeks
195+
];
196+
197+
let times = cases.map(|(input, _)| gix_date::parse(input, Some(now)).unwrap());
198+
199+
assert_eq!(times.map(|_| Sign::Plus), times.map(|time| time.sign));
200+
assert_eq!(times.map(|_| 0), times.map(|time| time.offset));
201+
202+
let expected = cases.map(|(_, span)| {
203+
Zoned::try_from(now)
204+
.unwrap()
205+
// account for the loss of precision when creating `Time` with seconds
206+
.round(
207+
jiff::ZonedRound::new()
208+
.smallest(jiff::Unit::Second)
209+
.mode(jiff::RoundMode::Trunc),
210+
)
211+
.unwrap()
212+
.saturating_sub(span)
213+
.timestamp()
214+
});
215+
let actual = times.map(|time| jiff::Timestamp::from_second(time.seconds).unwrap());
216+
assert_eq!(actual, expected, "relative times differ");
200217
}
201218
}
202219

0 commit comments

Comments
 (0)