Cotton code
1206 lines · 36.1 KB · RustRaw
//! Every case of `packages/core/__tests__/engine/zonedClock.test.ts`, plus the//! vectors computed by running the TypeScript in Node — 133 wall-clock//! readings and 32 `instantFromZoned` answers across seven zones and every//! 2026 DST transition of the four the product cares about.//!//! These are the vectors that would catch a tzdata skew between ICU (which//! `Intl` reads) and `chrono-tz` (which this crate compiles in), so they are//! the point of the file rather than decoration on it.use super::*;/// `(instant_ms, zone, [y, mo, d, h, mi, s], offset_ms)` — straight out of Node.const READINGS: &[(i64, &str, [i64; 6], i64)] = &[    (        1768478400000,        "Asia/Kolkata",        [2026, 1, 15, 17, 30, 0],        19800000,    ),    (        1781524800000,        "Asia/Kolkata",        [2026, 6, 15, 17, 30, 0],        19800000,    ),    (        1774745999999,        "Asia/Kolkata",        [2026, 3, 29, 6, 29, 59],        19800000,    ),    (        1774746000000,        "Asia/Kolkata",        [2026, 3, 29, 6, 30, 0],        19800000,    ),    (        1792889999999,        "Asia/Kolkata",        [2026, 10, 25, 6, 29, 59],        19800000,    ),    (        1792890000000,        "Asia/Kolkata",        [2026, 10, 25, 6, 30, 0],        19800000,    ),    (        1772953199999,        "Asia/Kolkata",        [2026, 3, 8, 12, 29, 59],        19800000,    ),    (        1772953200000,        "Asia/Kolkata",        [2026, 3, 8, 12, 30, 0],        19800000,    ),    (        1793512799999,        "Asia/Kolkata",        [2026, 11, 1, 11, 29, 59],        19800000,    ),    (        1793512800000,        "Asia/Kolkata",        [2026, 11, 1, 11, 30, 0],        19800000,    ),    (        1775318399999,        "Asia/Kolkata",        [2026, 4, 4, 21, 29, 59],        19800000,    ),    (        1775318400000,        "Asia/Kolkata",        [2026, 4, 4, 21, 30, 0],        19800000,    ),    (        1791043199999,        "Asia/Kolkata",        [2026, 10, 3, 21, 29, 59],        19800000,    ),    (        1791043200000,        "Asia/Kolkata",        [2026, 10, 3, 21, 30, 0],        19800000,    ),    (        1771180200250,        "Asia/Kolkata",        [2026, 2, 16, 0, 0, 0],        19800000,    ),    (        946684799999,        "Asia/Kolkata",        [2000, 1, 1, 5, 29, 59],        19800000,    ),    (        2147483647000,        "Asia/Kolkata",        [2038, 1, 19, 8, 44, 7],        19800000,    ),    (0, "Asia/Kolkata", [1970, 1, 1, 5, 30, 0], 19800000),    (-1, "Asia/Kolkata", [1970, 1, 1, 5, 29, 59], 19800000),    (1768478400000, "Europe/London", [2026, 1, 15, 12, 0, 0], 0),    (        1781524800000,        "Europe/London",        [2026, 6, 15, 13, 0, 0],        3600000,    ),    (1774745999999, "Europe/London", [2026, 3, 29, 0, 59, 59], 0),    (        1774746000000,        "Europe/London",        [2026, 3, 29, 2, 0, 0],        3600000,    ),    (        1792889999999,        "Europe/London",        [2026, 10, 25, 1, 59, 59],        3600000,    ),    (1792890000000, "Europe/London", [2026, 10, 25, 1, 0, 0], 0),    (1772953199999, "Europe/London", [2026, 3, 8, 6, 59, 59], 0),    (1772953200000, "Europe/London", [2026, 3, 8, 7, 0, 0], 0),    (1793512799999, "Europe/London", [2026, 11, 1, 5, 59, 59], 0),    (1793512800000, "Europe/London", [2026, 11, 1, 6, 0, 0], 0),    (        1775318399999,        "Europe/London",        [2026, 4, 4, 16, 59, 59],        3600000,    ),    (        1775318400000,        "Europe/London",        [2026, 4, 4, 17, 0, 0],        3600000,    ),    (        1791043199999,        "Europe/London",        [2026, 10, 3, 16, 59, 59],        3600000,    ),    (        1791043200000,        "Europe/London",        [2026, 10, 3, 17, 0, 0],        3600000,    ),    (1771180200250, "Europe/London", [2026, 2, 15, 18, 30, 0], 0),    (946684799999, "Europe/London", [1999, 12, 31, 23, 59, 59], 0),    (2147483647000, "Europe/London", [2038, 1, 19, 3, 14, 7], 0),    (0, "Europe/London", [1970, 1, 1, 1, 0, 0], 3600000),    (-1, "Europe/London", [1970, 1, 1, 0, 59, 59], 3600000),    (        1768478400000,        "America/New_York",        [2026, 1, 15, 7, 0, 0],        -18000000,    ),    (        1781524800000,        "America/New_York",        [2026, 6, 15, 8, 0, 0],        -14400000,    ),    (        1774745999999,        "America/New_York",        [2026, 3, 28, 20, 59, 59],        -14400000,    ),    (        1774746000000,        "America/New_York",        [2026, 3, 28, 21, 0, 0],        -14400000,    ),    (        1792889999999,        "America/New_York",        [2026, 10, 24, 20, 59, 59],        -14400000,    ),    (        1792890000000,        "America/New_York",        [2026, 10, 24, 21, 0, 0],        -14400000,    ),    (        1772953199999,        "America/New_York",        [2026, 3, 8, 1, 59, 59],        -18000000,    ),    (        1772953200000,        "America/New_York",        [2026, 3, 8, 3, 0, 0],        -14400000,    ),    (        1793512799999,        "America/New_York",        [2026, 11, 1, 1, 59, 59],        -14400000,    ),    (        1793512800000,        "America/New_York",        [2026, 11, 1, 1, 0, 0],        -18000000,    ),    (        1775318399999,        "America/New_York",        [2026, 4, 4, 11, 59, 59],        -14400000,    ),    (        1775318400000,        "America/New_York",        [2026, 4, 4, 12, 0, 0],        -14400000,    ),    (        1791043199999,        "America/New_York",        [2026, 10, 3, 11, 59, 59],        -14400000,    ),    (        1791043200000,        "America/New_York",        [2026, 10, 3, 12, 0, 0],        -14400000,    ),    (        1771180200250,        "America/New_York",        [2026, 2, 15, 13, 30, 0],        -18000000,    ),    (        946684799999,        "America/New_York",        [1999, 12, 31, 18, 59, 59],        -18000000,    ),    (        2147483647000,        "America/New_York",        [2038, 1, 18, 22, 14, 7],        -18000000,    ),    (0, "America/New_York", [1969, 12, 31, 19, 0, 0], -18000000),    (        -1,        "America/New_York",        [1969, 12, 31, 18, 59, 59],        -18000000,    ),    (        1768478400000,        "Australia/Sydney",        [2026, 1, 15, 23, 0, 0],        39600000,    ),    (        1781524800000,        "Australia/Sydney",        [2026, 6, 15, 22, 0, 0],        36000000,    ),    (        1774745999999,        "Australia/Sydney",        [2026, 3, 29, 11, 59, 59],        39600000,    ),    (        1774746000000,        "Australia/Sydney",        [2026, 3, 29, 12, 0, 0],        39600000,    ),    (        1792889999999,        "Australia/Sydney",        [2026, 10, 25, 11, 59, 59],        39600000,    ),    (        1792890000000,        "Australia/Sydney",        [2026, 10, 25, 12, 0, 0],        39600000,    ),    (        1772953199999,        "Australia/Sydney",        [2026, 3, 8, 17, 59, 59],        39600000,    ),    (        1772953200000,        "Australia/Sydney",        [2026, 3, 8, 18, 0, 0],        39600000,    ),    (        1793512799999,        "Australia/Sydney",        [2026, 11, 1, 16, 59, 59],        39600000,    ),    (        1793512800000,        "Australia/Sydney",        [2026, 11, 1, 17, 0, 0],        39600000,    ),    (        1775318399999,        "Australia/Sydney",        [2026, 4, 5, 2, 59, 59],        39600000,    ),    (        1775318400000,        "Australia/Sydney",        [2026, 4, 5, 2, 0, 0],        36000000,    ),    (        1791043199999,        "Australia/Sydney",        [2026, 10, 4, 1, 59, 59],        36000000,    ),    (        1791043200000,        "Australia/Sydney",        [2026, 10, 4, 3, 0, 0],        39600000,    ),    (        1771180200250,        "Australia/Sydney",        [2026, 2, 16, 5, 30, 0],        39600000,    ),    (        946684799999,        "Australia/Sydney",        [2000, 1, 1, 10, 59, 59],        39600000,    ),    (        2147483647000,        "Australia/Sydney",        [2038, 1, 19, 14, 14, 7],        39600000,    ),    (0, "Australia/Sydney", [1970, 1, 1, 10, 0, 0], 36000000),    (-1, "Australia/Sydney", [1970, 1, 1, 9, 59, 59], 36000000),    (1768478400000, "UTC", [2026, 1, 15, 12, 0, 0], 0),    (1781524800000, "UTC", [2026, 6, 15, 12, 0, 0], 0),    (1774745999999, "UTC", [2026, 3, 29, 0, 59, 59], 0),    (1774746000000, "UTC", [2026, 3, 29, 1, 0, 0], 0),    (1792889999999, "UTC", [2026, 10, 25, 0, 59, 59], 0),    (1792890000000, "UTC", [2026, 10, 25, 1, 0, 0], 0),    (1772953199999, "UTC", [2026, 3, 8, 6, 59, 59], 0),    (1772953200000, "UTC", [2026, 3, 8, 7, 0, 0], 0),    (1793512799999, "UTC", [2026, 11, 1, 5, 59, 59], 0),    (1793512800000, "UTC", [2026, 11, 1, 6, 0, 0], 0),    (1775318399999, "UTC", [2026, 4, 4, 15, 59, 59], 0),    (1775318400000, "UTC", [2026, 4, 4, 16, 0, 0], 0),    (1791043199999, "UTC", [2026, 10, 3, 15, 59, 59], 0),    (1791043200000, "UTC", [2026, 10, 3, 16, 0, 0], 0),    (1771180200250, "UTC", [2026, 2, 15, 18, 30, 0], 0),    (946684799999, "UTC", [1999, 12, 31, 23, 59, 59], 0),    (2147483647000, "UTC", [2038, 1, 19, 3, 14, 7], 0),    (0, "UTC", [1970, 1, 1, 0, 0, 0], 0),    (-1, "UTC", [1969, 12, 31, 23, 59, 59], 0),    (        1768478400000,        "Pacific/Chatham",        [2026, 1, 16, 1, 45, 0],        49500000,    ),    (        1781524800000,        "Pacific/Chatham",        [2026, 6, 16, 0, 45, 0],        45900000,    ),    (        1774745999999,        "Pacific/Chatham",        [2026, 3, 29, 14, 44, 59],        49500000,    ),    (        1774746000000,        "Pacific/Chatham",        [2026, 3, 29, 14, 45, 0],        49500000,    ),    (        1792889999999,        "Pacific/Chatham",        [2026, 10, 25, 14, 44, 59],        49500000,    ),    (        1792890000000,        "Pacific/Chatham",        [2026, 10, 25, 14, 45, 0],        49500000,    ),    (        1772953199999,        "Pacific/Chatham",        [2026, 3, 8, 20, 44, 59],        49500000,    ),    (        1772953200000,        "Pacific/Chatham",        [2026, 3, 8, 20, 45, 0],        49500000,    ),    (        1793512799999,        "Pacific/Chatham",        [2026, 11, 1, 19, 44, 59],        49500000,    ),    (        1793512800000,        "Pacific/Chatham",        [2026, 11, 1, 19, 45, 0],        49500000,    ),    (        1775318399999,        "Pacific/Chatham",        [2026, 4, 5, 4, 44, 59],        45900000,    ),    (        1775318400000,        "Pacific/Chatham",        [2026, 4, 5, 4, 45, 0],        45900000,    ),    (        1791043199999,        "Pacific/Chatham",        [2026, 10, 4, 5, 44, 59],        49500000,    ),    (        1791043200000,        "Pacific/Chatham",        [2026, 10, 4, 5, 45, 0],        49500000,    ),    (        1771180200250,        "Pacific/Chatham",        [2026, 2, 16, 8, 15, 0],        49500000,    ),    (        946684799999,        "Pacific/Chatham",        [2000, 1, 1, 13, 44, 59],        49500000,    ),    (        2147483647000,        "Pacific/Chatham",        [2038, 1, 19, 16, 59, 7],        49500000,    ),    (0, "Pacific/Chatham", [1970, 1, 1, 12, 45, 0], 45900000),    (-1, "Pacific/Chatham", [1970, 1, 1, 12, 44, 59], 45900000),    (        1768478400000,        "America/Sao_Paulo",        [2026, 1, 15, 9, 0, 0],        -10800000,    ),    (        1781524800000,        "America/Sao_Paulo",        [2026, 6, 15, 9, 0, 0],        -10800000,    ),    (        1774745999999,        "America/Sao_Paulo",        [2026, 3, 28, 21, 59, 59],        -10800000,    ),    (        1774746000000,        "America/Sao_Paulo",        [2026, 3, 28, 22, 0, 0],        -10800000,    ),    (        1792889999999,        "America/Sao_Paulo",        [2026, 10, 24, 21, 59, 59],        -10800000,    ),    (        1792890000000,        "America/Sao_Paulo",        [2026, 10, 24, 22, 0, 0],        -10800000,    ),    (        1772953199999,        "America/Sao_Paulo",        [2026, 3, 8, 3, 59, 59],        -10800000,    ),    (        1772953200000,        "America/Sao_Paulo",        [2026, 3, 8, 4, 0, 0],        -10800000,    ),    (        1793512799999,        "America/Sao_Paulo",        [2026, 11, 1, 2, 59, 59],        -10800000,    ),    (        1793512800000,        "America/Sao_Paulo",        [2026, 11, 1, 3, 0, 0],        -10800000,    ),    (        1775318399999,        "America/Sao_Paulo",        [2026, 4, 4, 12, 59, 59],        -10800000,    ),    (        1775318400000,        "America/Sao_Paulo",        [2026, 4, 4, 13, 0, 0],        -10800000,    ),    (        1791043199999,        "America/Sao_Paulo",        [2026, 10, 3, 12, 59, 59],        -10800000,    ),    (        1791043200000,        "America/Sao_Paulo",        [2026, 10, 3, 13, 0, 0],        -10800000,    ),    (        1771180200250,        "America/Sao_Paulo",        [2026, 2, 15, 15, 30, 0],        -10800000,    ),    (        946684799999,        "America/Sao_Paulo",        [1999, 12, 31, 21, 59, 59],        -7200000,    ),    (        2147483647000,        "America/Sao_Paulo",        [2038, 1, 19, 0, 14, 7],        -10800000,    ),    (0, "America/Sao_Paulo", [1969, 12, 31, 21, 0, 0], -10800000),    (        -1,        "America/Sao_Paulo",        [1969, 12, 31, 20, 59, 59],        -10800000,    ),];/// `(zone, [y, mo, d, h, mi, s], ms, instant_ms)` — straight out of Node.const WALL_CLOCKS: &[(&str, [i64; 6], i64, i64)] = &[    ("Asia/Kolkata", [2026, 2, 15, 9, 30, 0], 0, 1771128000000),    ("Asia/Kolkata", [2026, 2, 15, 9, 30, 0], 250, 1771128000250),    ("Asia/Kolkata", [2026, 12, 31, 23, 59, 59], 0, 1798741799000),    (        "Asia/Kolkata",        [2026, 12, 31, 23, 59, 59],        250,        1798741799250,    ),    ("Europe/London", [2026, 3, 29, 0, 59, 0], 0, 1774745940000),    ("Europe/London", [2026, 3, 29, 0, 59, 0], 250, 1774745940250),    ("Europe/London", [2026, 3, 29, 1, 30, 0], 0, 1774747800000),    ("Europe/London", [2026, 3, 29, 1, 30, 0], 250, 1774747800250),    ("Europe/London", [2026, 3, 29, 2, 0, 0], 0, 1774746000000),    ("Europe/London", [2026, 3, 29, 2, 0, 0], 250, 1774746000250),    ("Europe/London", [2026, 10, 25, 1, 30, 0], 0, 1792891800000),    (        "Europe/London",        [2026, 10, 25, 1, 30, 0],        250,        1792891800250,    ),    ("Europe/London", [2026, 6, 15, 12, 0, 0], 0, 1781521200000),    ("Europe/London", [2026, 6, 15, 12, 0, 0], 250, 1781521200250),    ("America/New_York", [2026, 3, 8, 2, 30, 0], 0, 1772951400000),    (        "America/New_York",        [2026, 3, 8, 2, 30, 0],        250,        1772951400250,    ),    (        "America/New_York",        [2026, 11, 1, 1, 30, 0],        0,        1793511000000,    ),    (        "America/New_York",        [2026, 11, 1, 1, 30, 0],        250,        1793511000250,    ),    ("America/New_York", [2026, 7, 4, 20, 0, 0], 0, 1783209600000),    (        "America/New_York",        [2026, 7, 4, 20, 0, 0],        250,        1783209600250,    ),    (        "Australia/Sydney",        [2026, 10, 4, 2, 30, 0],        0,        1791045000000,    ),    (        "Australia/Sydney",        [2026, 10, 4, 2, 30, 0],        250,        1791045000250,    ),    ("Australia/Sydney", [2026, 4, 5, 2, 30, 0], 0, 1775320200000),    (        "Australia/Sydney",        [2026, 4, 5, 2, 30, 0],        250,        1775320200250,    ),    ("Australia/Sydney", [2026, 1, 1, 0, 0, 0], 0, 1767186000000),    (        "Australia/Sydney",        [2026, 1, 1, 0, 0, 0],        250,        1767186000250,    ),    ("UTC", [2026, 5, 5, 5, 5, 5], 0, 1777957505000),    ("UTC", [2026, 5, 5, 5, 5, 5], 250, 1777957505250),    ("Pacific/Chatham", [2026, 9, 27, 2, 45, 0], 0, 1790431200000),    (        "Pacific/Chatham",        [2026, 9, 27, 2, 45, 0],        250,        1790431200250,    ),    (        "America/Sao_Paulo",        [2026, 2, 20, 0, 30, 0],        0,        1771558200000,    ),    (        "America/Sao_Paulo",        [2026, 2, 20, 0, 30, 0],        250,        1771558200250,    ),];#[test]fn zoned_parts_matches_node_across_every_probed_zone_and_transition() {    for (instant, zone, expected, _) in READINGS {        let got = zoned_parts(*instant, zone).expect("a known zone reads");        assert_eq!(            [got.year, got.month, got.day, got.hour, got.minute, got.second],            *expected,            "zoned_parts({instant}, {zone})"        );    }}#[test]fn zone_offset_ms_matches_node_across_every_probed_zone_and_transition() {    for (instant, zone, _, expected) in READINGS {        assert_eq!(            zone_offset_ms(*instant, zone),            Ok(*expected),            "zone_offset_ms({instant}, {zone})"        );    }}#[test]fn instant_from_zoned_matches_node_including_the_gaps_and_the_overlaps() {    for (zone, wall, ms, expected) in WALL_CLOCKS {        let parts = ZonedParts {            year: wall[0],            month: wall[1],            day: wall[2],            hour: wall[3],            minute: wall[4],            second: wall[5],        };        assert_eq!(            instant_from_zoned(parts, *ms, zone),            Ok(*expected),            "instant_from_zoned({zone}, {wall:?}, {ms})"        );    }}/// Reading a clock and asking for the instant that clock names, for every one/// of the 133 readings — against what NODE answers, not against the instant we/// started from.////// The distinction is the whole test. 130 of them round-trip exactly. The/// other three do not, and must not: a wall clock inside a fall-back overlap/// happens TWICE, so `1792889999999` in Europe/London (23:59:59.999 UTC on the/// last BST millisecond) reads 01:59:59.999 and the two-lookup rule resolves/// that back to the GMT instant an hour later. That is not a bug to be fixed/// on either side — it is why the TypeScript's comment says only that every/// runtime must compute the same one, and this table is how we know Rust does.#[test]fn a_wall_clock_reading_names_the_instant_node_says_it_names() {    const ROUND_TRIPS: &[(i64, &str, i64)] = &[        (1768478400000, "Asia/Kolkata", 1768478400000),        (1781524800000, "Asia/Kolkata", 1781524800000),        (1774745999999, "Asia/Kolkata", 1774745999999),        (1774746000000, "Asia/Kolkata", 1774746000000),        (1792889999999, "Asia/Kolkata", 1792889999999),        (1792890000000, "Asia/Kolkata", 1792890000000),        (1772953199999, "Asia/Kolkata", 1772953199999),        (1772953200000, "Asia/Kolkata", 1772953200000),        (1793512799999, "Asia/Kolkata", 1793512799999),        (1793512800000, "Asia/Kolkata", 1793512800000),        (1775318399999, "Asia/Kolkata", 1775318399999),        (1775318400000, "Asia/Kolkata", 1775318400000),        (1791043199999, "Asia/Kolkata", 1791043199999),        (1791043200000, "Asia/Kolkata", 1791043200000),        (1771180200250, "Asia/Kolkata", 1771180200250),        (946684799999, "Asia/Kolkata", 946684799999),        (2147483647000, "Asia/Kolkata", 2147483647000),        (0, "Asia/Kolkata", 0),        (-1, "Asia/Kolkata", -1),        (1768478400000, "Europe/London", 1768478400000),        (1781524800000, "Europe/London", 1781524800000),        (1774745999999, "Europe/London", 1774745999999),        (1774746000000, "Europe/London", 1774746000000),        (1792889999999, "Europe/London", 1792893599999),        (1792890000000, "Europe/London", 1792890000000),        (1772953199999, "Europe/London", 1772953199999),        (1772953200000, "Europe/London", 1772953200000),        (1793512799999, "Europe/London", 1793512799999),        (1793512800000, "Europe/London", 1793512800000),        (1775318399999, "Europe/London", 1775318399999),        (1775318400000, "Europe/London", 1775318400000),        (1791043199999, "Europe/London", 1791043199999),        (1791043200000, "Europe/London", 1791043200000),        (1771180200250, "Europe/London", 1771180200250),        (946684799999, "Europe/London", 946684799999),        (2147483647000, "Europe/London", 2147483647000),        (0, "Europe/London", 0),        (-1, "Europe/London", -1),        (1768478400000, "America/New_York", 1768478400000),        (1781524800000, "America/New_York", 1781524800000),        (1774745999999, "America/New_York", 1774745999999),        (1774746000000, "America/New_York", 1774746000000),        (1792889999999, "America/New_York", 1792889999999),        (1792890000000, "America/New_York", 1792890000000),        (1772953199999, "America/New_York", 1772953199999),        (1772953200000, "America/New_York", 1772953200000),        (1793512799999, "America/New_York", 1793512799999),        (1793512800000, "America/New_York", 1793509200000),        (1775318399999, "America/New_York", 1775318399999),        (1775318400000, "America/New_York", 1775318400000),        (1791043199999, "America/New_York", 1791043199999),        (1791043200000, "America/New_York", 1791043200000),        (1771180200250, "America/New_York", 1771180200250),        (946684799999, "America/New_York", 946684799999),        (2147483647000, "America/New_York", 2147483647000),        (0, "America/New_York", 0),        (-1, "America/New_York", -1),        (1768478400000, "Australia/Sydney", 1768478400000),        (1781524800000, "Australia/Sydney", 1781524800000),        (1774745999999, "Australia/Sydney", 1774745999999),        (1774746000000, "Australia/Sydney", 1774746000000),        (1792889999999, "Australia/Sydney", 1792889999999),        (1792890000000, "Australia/Sydney", 1792890000000),        (1772953199999, "Australia/Sydney", 1772953199999),        (1772953200000, "Australia/Sydney", 1772953200000),        (1793512799999, "Australia/Sydney", 1793512799999),        (1793512800000, "Australia/Sydney", 1793512800000),        (1775318399999, "Australia/Sydney", 1775321999999),        (1775318400000, "Australia/Sydney", 1775318400000),        (1791043199999, "Australia/Sydney", 1791043199999),        (1791043200000, "Australia/Sydney", 1791043200000),        (1771180200250, "Australia/Sydney", 1771180200250),        (946684799999, "Australia/Sydney", 946684799999),        (2147483647000, "Australia/Sydney", 2147483647000),        (0, "Australia/Sydney", 0),        (-1, "Australia/Sydney", -1),        (1768478400000, "UTC", 1768478400000),        (1781524800000, "UTC", 1781524800000),        (1774745999999, "UTC", 1774745999999),        (1774746000000, "UTC", 1774746000000),        (1792889999999, "UTC", 1792889999999),        (1792890000000, "UTC", 1792890000000),        (1772953199999, "UTC", 1772953199999),        (1772953200000, "UTC", 1772953200000),        (1793512799999, "UTC", 1793512799999),        (1793512800000, "UTC", 1793512800000),        (1775318399999, "UTC", 1775318399999),        (1775318400000, "UTC", 1775318400000),        (1791043199999, "UTC", 1791043199999),        (1791043200000, "UTC", 1791043200000),        (1771180200250, "UTC", 1771180200250),        (946684799999, "UTC", 946684799999),        (2147483647000, "UTC", 2147483647000),        (0, "UTC", 0),        (-1, "UTC", -1),        (1768478400000, "Pacific/Chatham", 1768478400000),        (1781524800000, "Pacific/Chatham", 1781524800000),        (1774745999999, "Pacific/Chatham", 1774745999999),        (1774746000000, "Pacific/Chatham", 1774746000000),        (1792889999999, "Pacific/Chatham", 1792889999999),        (1792890000000, "Pacific/Chatham", 1792890000000),        (1772953199999, "Pacific/Chatham", 1772953199999),        (1772953200000, "Pacific/Chatham", 1772953200000),        (1793512799999, "Pacific/Chatham", 1793512799999),        (1793512800000, "Pacific/Chatham", 1793512800000),        (1775318399999, "Pacific/Chatham", 1775318399999),        (1775318400000, "Pacific/Chatham", 1775318400000),        (1791043199999, "Pacific/Chatham", 1791043199999),        (1791043200000, "Pacific/Chatham", 1791043200000),        (1771180200250, "Pacific/Chatham", 1771180200250),        (946684799999, "Pacific/Chatham", 946684799999),        (2147483647000, "Pacific/Chatham", 2147483647000),        (0, "Pacific/Chatham", 0),        (-1, "Pacific/Chatham", -1),        (1768478400000, "America/Sao_Paulo", 1768478400000),        (1781524800000, "America/Sao_Paulo", 1781524800000),        (1774745999999, "America/Sao_Paulo", 1774745999999),        (1774746000000, "America/Sao_Paulo", 1774746000000),        (1792889999999, "America/Sao_Paulo", 1792889999999),        (1792890000000, "America/Sao_Paulo", 1792890000000),        (1772953199999, "America/Sao_Paulo", 1772953199999),        (1772953200000, "America/Sao_Paulo", 1772953200000),        (1793512799999, "America/Sao_Paulo", 1793512799999),        (1793512800000, "America/Sao_Paulo", 1793512800000),        (1775318399999, "America/Sao_Paulo", 1775318399999),        (1775318400000, "America/Sao_Paulo", 1775318400000),        (1791043199999, "America/Sao_Paulo", 1791043199999),        (1791043200000, "America/Sao_Paulo", 1791043200000),        (1771180200250, "America/Sao_Paulo", 1771180200250),        (946684799999, "America/Sao_Paulo", 946684799999),        (2147483647000, "America/Sao_Paulo", 2147483647000),        (0, "America/Sao_Paulo", 0),        (-1, "America/Sao_Paulo", -1),    ];    let mut differed = 0usize;    for (instant, zone, expected) in ROUND_TRIPS {        let parts = zoned_parts(*instant, zone).expect("a known zone reads");        let sub_second = instant.rem_euclid(1000);        assert_eq!(            instant_from_zoned(parts, sub_second, zone),            Ok(*expected),            "round trip {instant} in {zone}"        );        if expected != instant {            differed += 1;        }    }    assert_eq!(        differed, 3,        "the ambiguous fall-back readings are the only ones that may not round-trip"    );}// ── the refusals ─────────────────────────────────────────────────────────────#[test]fn refuses_a_zone_it_does_not_know_in_the_typescripts_own_words() {    assert_eq!(        zoned_parts(0, "Not/AZone"),        Err(ZoneError::UnknownTimeZone("Not/AZone".to_string()))    );    // The sentence reaches a person through an error body, so it is asserted    // rather than merely produced. Node: `RangeError: cotton: "Not/AZone" is    // not a known time zone`.    assert_eq!(        ZoneError::UnknownTimeZone("Not/AZone".to_string()).to_string(),        "cotton: \"Not/AZone\" is not a known time zone"    );    assert!(zone_offset_ms(0, "Europe/Nowhere").is_err());    assert!(instant_from_zoned(        ZonedParts {            year: 2026,            month: 1,            day: 1,            hour: 0,            minute: 0,            second: 0        },        0,        "Mars/Olympus"    )    .is_err());}#[test]fn utc_is_a_zone_like_any_other_and_reads_zero() {    assert_eq!(zone_offset_ms(1_771_128_000_000, "UTC"), Ok(0));    assert_eq!(zone_offset_ms(1_771_128_000_000, "Etc/UTC"), Ok(0));}// ── Date.UTC ─────────────────────────────────────────────────────────────────#[test]fn date_utc_agrees_with_javascript_on_the_ordinary_cases() {    // `Date.UTC(1970, 0, 1)` is 0; the rest are read off Node.    assert_eq!(date_utc(1970, 0, 1, 0, 0, 0, 0), 0);    assert_eq!(date_utc(2026, 8, 8, 12, 30, 15, 250), 1_788_870_615_250);    assert_eq!(date_utc(1969, 11, 31, 23, 59, 59, 999), -1);    assert_eq!(date_utc(2000, 1, 29, 0, 0, 0, 0), 951_782_400_000);}#[test]fn date_utc_normalises_out_of_range_components_rather_than_failing() {    // How the rrule engine walks a month boundary without special-casing it.    assert_eq!(        date_utc(2026, 12, 1, 0, 0, 0, 0),        date_utc(2027, 0, 1, 0, 0, 0, 0)    );    assert_eq!(        date_utc(2026, -1, 1, 0, 0, 0, 0),        date_utc(2025, 11, 1, 0, 0, 0, 0)    );    // Day 0 is the last day of the previous month; day 32 of a 31-day month is    // the 1st of the next.    assert_eq!(        date_utc(2026, 1, 0, 0, 0, 0, 0),        date_utc(2026, 0, 31, 0, 0, 0, 0)    );    assert_eq!(        date_utc(2026, 0, 32, 0, 0, 0, 0),        date_utc(2026, 1, 1, 0, 0, 0, 0)    );    assert_eq!(        date_utc(2026, 1, 29, 0, 0, 0, 0),        date_utc(2026, 2, 1, 0, 0, 0, 0)    );    // And the time components carry too.    assert_eq!(        date_utc(2026, 0, 1, 24, 0, 0, 0),        date_utc(2026, 0, 2, 0, 0, 0, 0)    );    assert_eq!(        date_utc(2026, 0, 1, 0, 0, 0, 1000),        date_utc(2026, 0, 1, 0, 0, 1, 0)    );}#[test]fn date_utc_maps_a_two_digit_year_into_the_twentieth_century() {    // `Date.UTC(50, 0, 1)` is 1950 in every JavaScript runtime. No caller here    // passes one; the rule is ported so the two implementations cannot differ.    assert_eq!(        date_utc(50, 0, 1, 0, 0, 0, 0),        date_utc(1950, 0, 1, 0, 0, 0, 0)    );    assert_eq!(        date_utc(99, 0, 1, 0, 0, 0, 0),        date_utc(1999, 0, 1, 0, 0, 0, 0)    );    assert_eq!(        date_utc(0, 0, 1, 0, 0, 0, 0),        date_utc(1900, 0, 1, 0, 0, 0, 0)    );    // 100 is a year, not an offset.    assert_ne!(        date_utc(100, 0, 1, 0, 0, 0, 0),        date_utc(2000, 0, 1, 0, 0, 0, 0)    );}#[test]fn date_utc_handles_leap_years_the_gregorian_way() {    // 2000 is a leap year, 1900 and 2100 are not.    assert_eq!(        date_utc(2000, 1, 29, 0, 0, 0, 0),        date_utc(2000, 1, 29, 0, 0, 0, 0)    );    assert_eq!(        date_utc(1900, 1, 29, 0, 0, 0, 0),        date_utc(1900, 2, 1, 0, 0, 0, 0)    );    assert_eq!(        date_utc(2100, 1, 29, 0, 0, 0, 0),        date_utc(2100, 2, 1, 0, 0, 0, 0)    );    assert_ne!(        date_utc(2024, 1, 29, 0, 0, 0, 0),        date_utc(2024, 2, 1, 0, 0, 0, 0)    );}// ─────────────────────────────────────────────────────────────────────────────// `packages/core/__tests__/engine/zonedClock.test.ts`, case for case.//// THE EXPECTED VALUES ARE HAND-WRITTEN, and that is the whole point of the// TypeScript file. Its first version computed its "independent" expectation as// `instant + zoneOffsetMs(instant, zone)` — and `zoneOffsetMs` calls// `zonedParts`, the function under test. A reader wrong by −12h produced an// offset wrong by −12h and the two agreed perfectly: a green light wired to// nothing. So the offsets below are written down as facts about the world// (IST is +5:30; Berlin is +1 in January and +2 in August) and the expected// wall clock is plain civil-calendar arithmetic on those numbers. No zone// database on the expectation side, at all.//// The two `simulateHermes` cases do NOT come over: they exist to prove the// reader survives a runtime that ignores `Intl`'s `hourCycle` option, and this// implementation asks `Intl` nothing. The property they were defending — the// afternoon hours read as themselves — is asserted directly below, and the// 133 Node vectors above cover the rest.// ─────────────────────────────────────────────────────────────────────────────/// Zone offsets as FACTS, not as anything this module computed. Each row fixes/// a date on which the offset is constant, so no DST reasoning is needed to/// know the answer.const FIXED: &[(&str, [i64; 3], i64)] = &[    ("Asia/Kolkata", [2026, 7, 23], 330),    ("Asia/Kolkata", [2026, 0, 15], 330),    ("Europe/Berlin", [2026, 7, 23], 120),    ("Europe/Berlin", [2026, 0, 15], 60),    ("UTC", [2026, 7, 23], 0),];/// The oracle's calendar: epoch milliseconds to UTC components, by arithmetic/// alone. This is `getUTCFullYear()` and friends — it consults no zone/// database and none of the code under test.fn utc_parts(ms: i64) -> [i64; 6] {    let days = ms.div_euclid(86_400_000);    let rest = ms.rem_euclid(86_400_000);    // Howard Hinnant's `civil_from_days`, the inverse of `days_from_civil`.    let z = days + 719_468;    let era = if z >= 0 { z } else { z - 146_096 } / 146_097;    let doe = z - era * 146_097;    let yoe = (doe - doe / 1460 + doe / 36_524 - doe / 146_096) / 365;    let y = yoe + era * 400;    let doy = doe - (365 * yoe + yoe / 4 - yoe / 100);    let mp = (5 * doy + 2) / 153;    let d = doy - (153 * mp + 2) / 5 + 1;    let m = if mp < 10 { mp + 3 } else { mp - 9 };    let year = if m <= 2 { y + 1 } else { y };    [        year,        m,        d,        rest / 3_600_000,        (rest / 60_000) % 60,        (rest / 1_000) % 60,    ]}#[test]fn zoned_parts_against_hand_written_offsets_all_twenty_four_hours() {    for (zone, [y, m, d], offset_minutes) in FIXED {        for hour in 0..24 {            let instant = date_utc(*y, *m, *d, hour, 17, 5, 0);            // The oracle: shift by the WRITTEN-DOWN offset and read the civil            // calendar. Nothing on this side can be broken by a broken reader.            let wall = utc_parts(instant + offset_minutes * 60_000);            let got = zoned_parts(instant, zone).expect("a known zone reads");            assert_eq!(                [got.year, got.month, got.day, got.hour, got.minute, got.second],                wall,                "{zone} at UTC hour {hour}"            );        }    }}#[test]fn reads_a_known_offset_exactly_ist_is_plus_five_thirty() {    // Not +5, and not −6:30.    let instant = date_utc(2026, 7, 23, 18, 30, 0, 0);    assert_eq!(        zoned_parts(instant, "Asia/Kolkata"),        Ok(ZonedParts {            year: 2026,            month: 8,            day: 24,            hour: 0,            minute: 0,            second: 0        })    );}#[test]fn reads_the_afternoon_hours_correctly() {    // 13:00–23:00 is precisely the band a twelve-hour fallback renders 12 low.    for hour in 13..24 {        let parts =            zoned_parts(date_utc(2026, 7, 23, hour, 0, 0, 0), "UTC").expect("a known zone reads");        assert_eq!(parts.hour, hour, "asked for {hour}");    }}#[test]fn reads_midnight_as_zero_never_twenty_four() {    // The case the `% 24` exists for: a formatter can render midnight as "24",    // which would read back as the next day.    let parts = zoned_parts(date_utc(2026, 7, 23, 0, 0, 0, 0), "UTC").expect("a known zone reads");    assert_eq!(parts.hour, 0);}#[test]fn reports_the_written_down_offset_back_for_the_zones_that_never_shift() {    // Derived from `zoned_parts`, so this is a consequence rather than    // independent evidence — but a consequence worth pinning, since every    // caller reads the offset rather than the parts.    let at = date_utc(2026, 7, 23, 9, 0, 0, 0);    assert_eq!(zone_offset_ms(at, "Asia/Kolkata"), Ok(330 * 60_000));    assert_eq!(zone_offset_ms(at, "UTC"), Ok(0));    assert_eq!(zone_offset_ms(at, "Europe/Berlin"), Ok(120 * 60_000));    assert_eq!(        zone_offset_ms(date_utc(2026, 0, 15, 9, 0, 0, 0), "Europe/Berlin"),        Ok(60 * 60_000)    );}#[test]fn instant_from_zoned_round_trips_every_hour_of_the_fixed_days() {    // Honest about its limits: this composes the reader with the writer, and a    // reader wrong by −12h paired with a writer wrong by +12h would still round    // trip. It pins the pairing, not the absolute answer — the sweeps above are    // what pin the absolute answer.    for (zone, [y, m, d], _) in FIXED {        for hour in 0..24 {            let instant = date_utc(*y, *m, *d, hour, 17, 5, 0);            let parts = zoned_parts(instant, zone).expect("a known zone reads");            assert_eq!(                instant_from_zoned(parts, 0, zone),                Ok(instant),                "{zone} at UTC hour {hour}"            );        }    }}#[test]fn it_refuses_to_guess() {    let refusal = zoned_parts(0, "Mars/Olympus_Mons").expect_err("no such zone");    assert!(refusal.to_string().contains("not a known time zone"));}