Skip to content
Myr

parse-iso-week.test.ts

This file

Path

test/asks/parse-iso-week.test.ts

21 lines · 1023 bytes · TypeScript

Last changed by

opened parse-iso-weekby ines-v25ecd66

History of this file

Take it

1import { expect, test } from "bun:test";23import { isValid, parseISO } from "../../src/index.ts";45const day = (text: string) => parseISO(text).getTime();67test("parseISO reads ISO week dates to the UTC midnight of their day", () => {8  // Week 41 of 2026 runs from Monday, October 5 to Sunday, October 11.9  expect(day("2026-W41-3")).toBe(Date.UTC(2026, 9, 7));10  expect(day("2026W413")).toBe(Date.UTC(2026, 9, 7));11  // A week with no day is its Monday.12  expect(day("2026-W41")).toBe(Date.UTC(2026, 9, 5));13  // Week 1 is the week with the year's first Thursday, so it can start in14  // December, and a year that starts on a Thursday has 53 weeks.15  expect(day("2026-W01-1")).toBe(Date.UTC(2025, 11, 29));16  expect(day("2026-W53-7")).toBe(Date.UTC(2027, 0, 3));17  expect(day("2026-W41-3T14:30Z")).toBe(Date.UTC(2026, 9, 7, 14, 30));18  // 2027 starts on a Friday, so it has 52 weeks; and a week has 7 days.19  expect(isValid(parseISO("2027-W53-1"))).toBe(false);20  expect(isValid(parseISO("2026-W41-8"))).toBe(false);21});