-
Notifications
You must be signed in to change notification settings - Fork 13.9k
Expand file tree
/
Copy pathweekday.test.ts
More file actions
88 lines (68 loc) · 2.9 KB
/
weekday.test.ts
File metadata and controls
88 lines (68 loc) · 2.9 KB
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
import { describe, expect, it } from "vitest";
import "@calcom/dayjs/locales";
import { getWeekStartForLocale, nameOfDay, weekdayNames } from "./weekday";
describe("Weekday tests", () => {
describe("fn: weekdayNames", () => {
it("should return the weekday names for a given locale", () => {
const locales = ["en-US", "en-CA", "en-GB", "en-AU"];
for (const locale of locales) {
const result = weekdayNames(locale);
const expected = ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"];
expect(result).toEqual(expected);
}
});
it("should return the weekday names for a given locale and format", () => {
const locales = ["en-US", "en-CA", "en-GB", "en-AU"];
for (const locale of locales) {
const result = weekdayNames(locale, 0, "short");
const expected = ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"];
expect(result).toEqual(expected);
}
});
it("should return the weekday names for a given locale and week start offset", () => {
const locales = ["en-US", "en-CA", "en-GB", "en-AU"];
for (const locale of locales) {
const result = weekdayNames(locale, 1);
const expected = ["Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"];
expect(result).toEqual(expected);
}
});
});
describe("fn: nameOfDay", () => {
it("should return the name of the day for a given locale", () => {
const locales = ["en-US", "en-CA", "en-GB", "en-AU"];
const days = [
{ day: 0, expected: "Sunday" },
{ day: 1, expected: "Monday" },
{ day: 2, expected: "Tuesday" },
{ day: 3, expected: "Wednesday" },
{ day: 4, expected: "Thursday" },
{ day: 5, expected: "Friday" },
{ day: 6, expected: "Saturday" },
];
for (const locale of locales) {
for (const { day, expected } of days) {
const result = nameOfDay(locale, day);
expect(result).toEqual(expected);
}
}
});
it("should work with Icelandic, Lithuanian, and Norwegian locales", () => {
expect(nameOfDay("is", 1, "long")).toMatch(/mánudagur/i); // Monday in Icelandic
expect(nameOfDay("lt", 1, "long")).toMatch(/pirmadienis/i); // Monday in Lithuanian
expect(nameOfDay("nb", 1, "long")).toMatch(/mandag/i); // Monday in Norwegian
});
});
describe("fn: getWeekStartForLocale", () => {
it("defaults to Saturday (6) for Persian locales", () => {
expect(getWeekStartForLocale("fa")).toBe(6);
expect(getWeekStartForLocale("fa-IR")).toBe(6);
expect(getWeekStartForLocale(["fa-IR", "fa"])).toBe(6);
});
it("defaults to Sunday (0) for non-Persian locales", () => {
expect(getWeekStartForLocale("en")).toBe(0);
expect(getWeekStartForLocale("ar")).toBe(0);
expect(getWeekStartForLocale(undefined)).toBe(0);
});
});
});