Skip to content

The IDE you know, rebuilt in Rust. IntelliJ IDEA–style keymap, tool windows and search-everywhere in a fast native app: editor, code insight, debugger, Git, terminal, database and HTTP clients for 60+ languages.

1.0 KB
Raw Blame
import { describe, expect, it } from "vitest";
import { DEFAULT_DATE_FORMAT, formatClock, formatDay, formatPattern } from "./dateFormat";

describe("dateFormat", () => {
  const d = new Date(2026, 10, 5, 9, 7);
  const system = { ...DEFAULT_DATE_FORMAT, overrideSystem: false };
  const long = { year: "numeric", month: "short", day: "numeric" } as const;

  it("formats like the locale methods it replaces", () => {
    expect(formatDay(d, system)).toBe(d.toLocaleDateString(undefined, long));
    expect(formatDay(d, system, true)).toBe(
      d.toLocaleDateString(undefined, { year: "2-digit", month: "2-digit", day: "2-digit" }),
    );
    expect(formatClock(d, system)).toBe(d.toLocaleTimeString(undefined, { hour: "2-digit", minute: "2-digit" }));
    expect(formatPattern(d, "MMMM MMM dd.MM.yyyy")).toBe("November Nov 05.11.2026");
  });

  it("formats another date with the same cached formatter", () => {
    const e = new Date(2025, 0, 31);
    formatDay(d, system);
    expect(formatDay(e, system)).toBe(e.toLocaleDateString(undefined, long));
  });
});