Skip to content

Commit

Permalink
Test 12-week increments from 2 to 50
Browse files Browse the repository at this point in the history
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 GitoxideLabs#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.
  • Loading branch information
EliahKagan committed Nov 23, 2024
1 parent 5d51bd1 commit ac17b62
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 6 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion gix-date/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,10 @@ thiserror = "2.0.0"
document-features = { version = "0.2.0", optional = true }

[dev-dependencies]
gix-hash = { path = "../gix-hash" }
gix-testtools = { path = "../tests/tools" }
once_cell = "1.12.0"
gix-hash = { path = "../gix-hash" }
pretty_assertions = "1.4.1"

[package.metadata.docs.rs]
all-features = true
Expand Down
15 changes: 10 additions & 5 deletions gix-date/tests/time/parse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@ mod relative {

use gix_date::time::Sign;
use jiff::{ToSpan, Zoned};
use pretty_assertions::assert_eq;

#[test]
fn large_offsets() {
Expand All @@ -182,11 +183,15 @@ mod relative {

let cases = [
("2 weeks ago", 2.weeks()),
("20160 minutes ago", 20_160.minutes()), // 2 weeks
("20 weeks ago", 20.weeks()),
("201600 minutes ago", 201_600.minutes()), // 20 weeks
("40 weeks ago", 40.weeks()),
("403200 minutes ago", 403_200.minutes()), // 40 weeks
("14 weeks ago", 14.weeks()),
("26 weeks ago", 26.weeks()),
("38 weeks ago", 38.weeks()),
("50 weeks ago", 50.weeks()),
("20160 minutes ago", 20_160.minutes()), // 2 weeks
("141120 minutes ago", 141_120.minutes()), // 14 weeks
("262080 minutes ago", 262_080.minutes()), // 26 weeks
("383040 minutes ago", 383_040.minutes()), // 38 weeks
("504000 minutes ago", 504_000.minutes()), // 50 weeks
];

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

0 comments on commit ac17b62

Please sign in to comment.