Botanique/tests/utils/time.test.ts

51 lines
1.2 KiB
TypeScript
Raw Normal View History

2024-09-27 13:16:17 +02:00
import { showDate } from "../../src/utils/time";
describe("Date with correct timezone", () => {
2024-09-27 13:21:31 +02:00
const map = new Map([["u_time_at", "@"]]);
2024-09-27 13:16:17 +02:00
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";
2024-09-27 14:49:11 +02:00
// Depends on the system
// The important is that the date is in the correct timezone (UTC)
2024-09-27 13:16:17 +02:00
test(name, () => {
2024-09-27 14:48:03 +02:00
expect(["27/09/2024 @ 10:59:27", "9/27/24, @ 10:59:27"]).toContain(showDate(name, map, date));
2024-09-27 13:16:17 +02:00
});
}
{
const name = "zh-CN";
test(name, () => {
expect(showDate(name, map, date)).toBe("2024/9/27 @ 18:59:27");
});
}
});
2024-09-27 15:13:48 +02:00
/* describe("String time to seconds", () => {
2024-09-27 13:21:31 +02:00
{
2024-09-27 15:13:48 +02:00
const name = "10m30";
2024-09-27 13:21:31 +02:00
test(name, () => {
2024-09-27 15:13:48 +02:00
expect(strToSeconds(name)).toBe(630);
2024-09-27 13:21:31 +02:00
});
}
2024-09-27 15:13:48 +02:00
}); */
2024-09-27 13:21:31 +02:00
2024-09-27 15:13:48 +02:00
/* describe("Time delta", () => {
2024-09-27 13:21:31 +02:00
{
2024-09-27 15:13:48 +02:00
const name = 1312;
test(name.toString(), () => {
expect(timeDeltaToString(name)).toBe("0 secs");
2024-09-27 13:21:31 +02:00
});
}
2024-09-27 15:13:48 +02:00
}); */