import { nextTimeUnit, showDate, strToSeconds, TimeSecond } from "../../utils/time"; describe("Date with correct timezone", () => { const map = new Map([["u_time_at", "@"]]); const date = new Date(1727434767686); { const name = "fr"; test(name, () => { expect(showDate(name, map, date)).toBe("27/09/2024 @ 12:59:27"); }); } { const name = "en-US"; test(name, () => { expect(showDate(name, map, date)).toBe("9/27/24, @ 1:59:27"); }); } { const name = "unknown"; // Depends on the system // The important is that the date is in the correct timezone (UTC) test(name, () => { expect(["27/09/2024 @ 10:59:27", "9/27/24, @ 10:59:27"]).toContain(showDate(name, map, date)); }); } { const name = "zh-CN"; test(name, () => { expect(showDate(name, map, date)).toBe("2024/9/27 @ 18:59:27"); }); } }); describe("String time to seconds", () => { { const name = "10m30"; test(name, () => { expect(strToSeconds(name)).toBe(630); }); } { const name = "12h30"; test(name, () => { expect(strToSeconds(name)).toBe(45000); }); } { const name = "12s30"; test(name, () => { expect(strToSeconds(name)).toBe(42); }); } { const name = "1w30h20"; test(name, () => { expect(strToSeconds(name)).toBe(714000); }); } }); describe("Next time unit", () => { { const name = TimeSecond.Minute; test(name.toString(), () => { expect(nextTimeUnit(name)).toBe(TimeSecond.Second); }); } { const name = TimeSecond.Hour; test(name.toString(), () => { expect(nextTimeUnit(name)).toBe(TimeSecond.Minute); }); } { const name = TimeSecond.Second; test(name.toString(), () => { expect(nextTimeUnit(name)).toBe(TimeSecond.Second); }); } { const name = TimeSecond.Year; test(name.toString(), () => { expect(nextTimeUnit(name)).toBe(TimeSecond.Week); }); } });