mirror of
https://github.com/moltbot/moltbot.git
synced 2026-03-07 22:44:16 +00:00
Tests: trim timezone in envelope timestamp helper (#12446)
This commit is contained in:
@@ -106,6 +106,11 @@ describe("web auto-reply", () => {
|
||||
vi.useRealTimers();
|
||||
});
|
||||
|
||||
it("handles helper envelope timestamps with trimmed timezones (regression)", () => {
|
||||
const d = new Date("2025-01-01T00:00:00.000Z");
|
||||
expect(() => formatEnvelopeTimestamp(d, " America/Los_Angeles ")).not.toThrow();
|
||||
});
|
||||
|
||||
it("reconnects after a connection close", async () => {
|
||||
const closeResolvers: Array<() => void> = [];
|
||||
const sleep = vi.fn(async () => {});
|
||||
|
||||
@@ -8,7 +8,8 @@ export { escapeRegExp } from "../../src/utils.js";
|
||||
type EnvelopeTimestampZone = string;
|
||||
|
||||
export function formatEnvelopeTimestamp(date: Date, zone: EnvelopeTimestampZone = "utc"): string {
|
||||
const normalized = zone.trim().toLowerCase();
|
||||
const trimmedZone = zone.trim();
|
||||
const normalized = trimmedZone.toLowerCase();
|
||||
const weekday = (() => {
|
||||
try {
|
||||
if (normalized === "utc" || normalized === "gmt") {
|
||||
@@ -17,7 +18,9 @@ export function formatEnvelopeTimestamp(date: Date, zone: EnvelopeTimestampZone
|
||||
if (normalized === "local" || normalized === "host") {
|
||||
return new Intl.DateTimeFormat("en-US", { weekday: "short" }).format(date);
|
||||
}
|
||||
return new Intl.DateTimeFormat("en-US", { timeZone: zone, weekday: "short" }).format(date);
|
||||
return new Intl.DateTimeFormat("en-US", { timeZone: trimmedZone, weekday: "short" }).format(
|
||||
date,
|
||||
);
|
||||
} catch {
|
||||
return undefined;
|
||||
}
|
||||
@@ -31,7 +34,7 @@ export function formatEnvelopeTimestamp(date: Date, zone: EnvelopeTimestampZone
|
||||
const ts = formatZonedTimestamp(date) ?? formatUtcTimestamp(date);
|
||||
return weekday ? `${weekday} ${ts}` : ts;
|
||||
}
|
||||
const ts = formatZonedTimestamp(date, { timeZone: zone }) ?? formatUtcTimestamp(date);
|
||||
const ts = formatZonedTimestamp(date, { timeZone: trimmedZone }) ?? formatUtcTimestamp(date);
|
||||
return weekday ? `${weekday} ${ts}` : ts;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user