diff --git a/npm/test.mjs b/npm/test.mjs index fe40c4c..15ca1af 100644 --- a/npm/test.mjs +++ b/npm/test.mjs @@ -129,6 +129,14 @@ check("pascha matches the published dates", () => { assert.equal(iso(typikon.pascha(2027, "old")), "2027-05-02"); }); +check("a two-digit year is that year, not 19xx", () => { + // The Date constructor reads 0..99 as 1900 + n, which would have made the + // Paschalion for the year 50 answer for 1950 without a word. + assert.equal(typikon.pascha(50, "old").getFullYear(), 50); + assert.equal(typikon.pascha(99, "old").getFullYear(), 99); + assert.equal(typikon.pascha(100, "old").getFullYear(), 100); +}); + check("every listed jurisdiction reckons", () => { const all = typikon.jurisdictions(); assert.ok(all.length > 20); diff --git a/src/wasm.rs b/src/wasm.rs index 3ae7552..8bca2e1 100644 --- a/src/wasm.rs +++ b/src/wasm.rs @@ -164,7 +164,14 @@ fn from_js_date(d: &js_sys::Date) -> Result { fn to_js_date(d: Date) -> js_sys::Date { let (y, m, day) = d.ymd(); - js_sys::Date::new_with_year_month_day(y as u32, m as i32 - 1, day as i32) + let out = js_sys::Date::new_with_year_month_day(y as u32, m as i32 - 1, day as i32); + // `new Date(50, 0, 1)` is 1950, not the year 50: the two-digit-year rule is + // in the constructor and not in the setter. This calendar answers from the + // year 1, so the rule has to be undone rather than lived with. + if (0..=99).contains(&y) { + out.set_full_year(y as u32); + } + out } // ──────────────────────────────── the api ─────────────────────────────────