Skip to content

Commit ac17b62

Browse files
committed
Test 12-week increments from 2 to 50
The idea here is to make it so that: 1. If we are using local time, in a time zone with DST adjustments, then no matter when we run the test, at least one "X weeks ago" case will have exactly one DST adjustment between then and now. (Thus, if our local time can observe #1696, it will.) 2. It is easy to verify that this is so. The rules are somewhat variable, and adjustments cannot be approximated as happening every half-year: - In multiple time zones with DST-related adjustments, an adjustment and its reversal can be separated by only four months (November to March). - Countries may institute rules that may be hard for people not familiar with them to anticipate. For example, Morocco used to have DST-related adjustments; when it did, if the (lunar) month of Ramadan occurred during the usual (Gregorian-based) DST period, standard time (rather than DST) was in effect during Ramadan. Thus, in some years, there were four DST-related clock adjustments. It is hard to predict (or, at least, I do not know how to predict) if, or what kind of, new DST adjustments may be put in place somewhere. With that said, the current test probably has more intervals than necessary. Furthermore, if it turns out to be feasible, it may be better to make this a true unit test by using a set time instad of `now` to take "X weeks ago" times relative to, and by somehow specifying or mocking out the time zone, so as to test the tricky cases in exactly the same way no matter where, when, or in what local configuration the test is run. Failure, when it occurs, now looks like: --- STDERR: gix-date::date time::parse::relative::various --- thread 'time::parse::relative::various' panicked at gix-date\tests\time\parse.rs:216:9: assertion failed: `(left == right)`: relative times differ Diff < left / right > : [ 2024-11-09T04:22:21Z, < 2024-08-17T04:22:21Z, < 2024-05-25T04:22:21Z, > 2024-08-17T03:22:21Z, > 2024-05-25T03:22:21Z, 2024-03-02T04:22:21Z, 2023-12-09T04:22:21Z, 2024-11-09T04:22:21Z, 2024-08-17T04:22:21Z, 2024-05-25T04:22:21Z, 2024-03-02T04:22:21Z, 2023-12-09T04:22:21Z, ] Equivalent cases with weeks and minutes were interleaved before, but now all the "weeks" cases are listed before all the "minutes" cases, because that produces more readable output when `pretty_assertions::assert_eq!` is used.
1 parent 5d51bd1 commit ac17b62

File tree

3 files changed

+13
-6
lines changed

3 files changed

+13
-6
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

+10-5
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() {
@@ -182,11 +183,15 @@ mod relative {
182183

183184
let cases = [
184185
("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-
("40 weeks ago", 40.weeks()),
189-
("403200 minutes ago", 403_200.minutes()), // 40 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
190195
];
191196

192197
let times = cases.map(|(input, _)| gix_date::parse(input, Some(now)).unwrap());

0 commit comments

Comments
 (0)