Something went wrong. Try again.
[READ-ONLY] Mirror of https://github.com/openstatusHQ/openstatus. 🫖 Status page with uptime monitoring & API monitoring as code 🫖 openstatus.dev
bun drizzle-orm monitoring monitoring-as-code nextjs observability on-call open-source shadcn-ui status-page statuspage synthetic-monitoring tinybird turso uptime uptime-checker uptime-monitor
Something went wrong. Try again.
1.1 kB · 31 lines
TypeScript
1234567891011121314151617181920212223242526272829303132import { describe, expect, it } from "vitest";
import { formatTimestamp } from "./timestamp";
describe("formatTimestamp", () => { it("formats a valid epoch timestamp as an ISO string", () => { expect(formatTimestamp(1700000000000)).toBe("2023-11-14T22:13:20.000Z"); });
it("formats timestamps before the unix epoch", () => { expect(formatTimestamp(-1000)).toBe("1969-12-31T23:59:59.000Z"); });
it("returns Unknown for 0, since it is falsy", () => { expect(formatTimestamp(0)).toBe("Unknown"); });
it("returns Unknown for NaN", () => { expect(formatTimestamp(Number.NaN)).toBe("Unknown"); });
it("returns Unknown for non finite values", () => { expect(formatTimestamp(Number.POSITIVE_INFINITY)).toBe("Unknown"); expect(formatTimestamp(Number.NEGATIVE_INFINITY)).toBe("Unknown"); });
it("returns Unknown when the timestamp is beyond the maximum valid date", () => { // The largest date JS can represent is 8.64e15 ms; one past it is invalid. expect(formatTimestamp(8.64e15 + 1)).toBe("Unknown"); });});