|
|
@@ -1,4 +1,4 @@
|
|
|
-import { DateTimeFormat } from "src/locale";
|
|
|
+import { formatDateTime } from "src/locale";
|
|
|
import { afterAll, beforeAll, describe, expect, it } from "vitest";
|
|
|
|
|
|
describe("DateFormatter", () => {
|
|
|
@@ -17,10 +17,7 @@ describe("DateFormatter", () => {
|
|
|
|
|
|
// Mock Intl.DateTimeFormat so formatting is stable regardless of host
|
|
|
const MockedDateTimeFormat = class extends RealIntl.DateTimeFormat {
|
|
|
- constructor(
|
|
|
- _locales?: string | string[],
|
|
|
- options?: Intl.DateTimeFormatOptions,
|
|
|
- ) {
|
|
|
+ constructor(_locales?: string | string[], options?: Intl.DateTimeFormatOptions) {
|
|
|
super(desiredLocale, {
|
|
|
...options,
|
|
|
timeZone: desiredTimeZone,
|
|
|
@@ -41,37 +38,37 @@ describe("DateFormatter", () => {
|
|
|
|
|
|
it("format date from iso date", () => {
|
|
|
const value = "2024-01-01T00:00:00.000Z";
|
|
|
- const text = DateTimeFormat(value);
|
|
|
+ const text = formatDateTime(value);
|
|
|
expect(text).toBe("Monday, 01/01/2024, 12:00:00 am");
|
|
|
});
|
|
|
|
|
|
it("format date from unix timestamp number", () => {
|
|
|
const value = 1762476112;
|
|
|
- const text = DateTimeFormat(value);
|
|
|
+ const text = formatDateTime(value);
|
|
|
expect(text).toBe("Friday, 07/11/2025, 12:41:52 am");
|
|
|
});
|
|
|
|
|
|
it("format date from unix timestamp string", () => {
|
|
|
const value = "1762476112";
|
|
|
- const text = DateTimeFormat(value);
|
|
|
+ const text = formatDateTime(value);
|
|
|
expect(text).toBe("Friday, 07/11/2025, 12:41:52 am");
|
|
|
});
|
|
|
|
|
|
it("catch bad format from string", () => {
|
|
|
const value = "this is not a good date";
|
|
|
- const text = DateTimeFormat(value);
|
|
|
+ const text = formatDateTime(value);
|
|
|
expect(text).toBe("this is not a good date");
|
|
|
});
|
|
|
|
|
|
it("catch bad format from number", () => {
|
|
|
const value = -100;
|
|
|
- const text = DateTimeFormat(value);
|
|
|
+ const text = formatDateTime(value);
|
|
|
expect(text).toBe("-100");
|
|
|
});
|
|
|
|
|
|
it("catch bad format from number as string", () => {
|
|
|
const value = "-100";
|
|
|
- const text = DateTimeFormat(value);
|
|
|
+ const text = formatDateTime(value);
|
|
|
expect(text).toBe("-100");
|
|
|
});
|
|
|
});
|