Use only geographic time zones (#1033)

This commit is contained in:
Luke Vella 2024-02-24 09:12:05 +08:00 committed by GitHub
parent 39a22acaa7
commit 27dda65ca5
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
31 changed files with 1416 additions and 618 deletions

View file

@ -0,0 +1,38 @@
import dayjs from "dayjs";
import timezone from "dayjs/plugin/timezone";
import utc from "dayjs/plugin/utc";
import { describe, expect, it } from "vitest";
import { supportedTimeZones } from "@/utils/supported-time-zones";
import { resolveGeographicTimeZone } from "./date-time-utils";
dayjs.extend(utc);
dayjs.extend(timezone);
describe("resolveGeographicTimezone", () => {
it("should return same timezone when given a geographic timezone", () => {
const browserTimeZone = resolveGeographicTimeZone("Europe/London");
// Assert that the browser time zone is one of the supported time zones
expect(browserTimeZone).toBe("Europe/London");
});
it("should return a supported timezone when given a fixed offset timezone", () => {
const browserTimeZone = resolveGeographicTimeZone("Etc/GMT-1");
// Assert that the browser time zone is one of the supported time zones
expect(supportedTimeZones.includes(browserTimeZone)).toBe(true);
});
it("should return a supported timezone when given GMT", () => {
const browserTimeZone = resolveGeographicTimeZone("GMT");
// Assert that the browser time zone is one of the supported time zones
expect(supportedTimeZones.includes(browserTimeZone)).toBe(true);
});
it("should return a supported timezone when given UTC", () => {
const browserTimeZone = resolveGeographicTimeZone("UTC");
// Assert that the browser time zone is one of the supported time zones
expect(supportedTimeZones.includes(browserTimeZone)).toBe(true);
});
});