File size: 1,444 Bytes
cf86710 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 | import { toGregorianDate } from "../utils";
import { getWeek } from "./getWeek";
describe("getWeek", () => {
test("should return 1 for first week of year", () => {
const date = toGregorianDate({
year: 2016,
month: 1,
day: 1,
}); // Greg: Sep 12, 2023
expect(getWeek(date)).toBe(1);
});
test("should handle dates in last month of year to be either 52 or 1", () => {
// part of the last week of the previous year
const date52 = toGregorianDate({
year: 2016,
month: 13,
day: 1,
}); // Greg: Sep 10, 202
expect(getWeek(date52)).toBe(52);
// part of the first week of the new year
const date1 = toGregorianDate({
year: 2016,
month: 13,
day: 5,
}); // Greg: Sep 10, 202
expect(getWeek(date1)).toBe(1);
});
test("should handle dates at week boundaries", () => {
// Sunday week 1
const sunday = toGregorianDate({
year: 2016,
month: 1,
day: 6,
}); // Greg: Sep 17, 2023
expect(getWeek(sunday)).toBe(1);
// Monday week 2
const monday = toGregorianDate({
year: 2016,
month: 1,
day: 7,
}); // Greg: Sep 18, 2023
expect(getWeek(monday)).toBe(2);
});
test("should handle dates in middle of year", () => {
const midYear = toGregorianDate({
year: 2016,
month: 6,
day: 15,
}); // Greg: Feb 23, 2024
expect(getWeek(midYear)).toBe(24);
});
});
|