test: align envelope timestamp expectations (#1329) (thanks @dlauer)

This commit is contained in:
Peter Steinberger
2026-01-22 05:51:42 +00:00
parent a59ac5cf6f
commit d425f1ebea
5 changed files with 36 additions and 25 deletions

View File

@@ -1,5 +1,17 @@
export function formatLocalEnvelopeTimestamp(date: Date): string {
type EnvelopeTimestampZone = string;
function formatUtcTimestamp(date: Date): string {
const yyyy = String(date.getUTCFullYear()).padStart(4, "0");
const mm = String(date.getUTCMonth() + 1).padStart(2, "0");
const dd = String(date.getUTCDate()).padStart(2, "0");
const hh = String(date.getUTCHours()).padStart(2, "0");
const min = String(date.getUTCMinutes()).padStart(2, "0");
return `${yyyy}-${mm}-${dd}T${hh}:${min}Z`;
}
function formatZonedTimestamp(date: Date, timeZone?: string): string {
const parts = new Intl.DateTimeFormat("en-US", {
timeZone,
year: "numeric",
month: "2-digit",
day: "2-digit",
@@ -27,6 +39,17 @@ export function formatLocalEnvelopeTimestamp(date: Date): string {
return `${yyyy}-${mm}-${dd} ${hh}:${min}${tz ? ` ${tz}` : ""}`;
}
export function formatEnvelopeTimestamp(date: Date, zone: EnvelopeTimestampZone = "utc"): string {
const normalized = zone.trim().toLowerCase();
if (normalized === "utc" || normalized === "gmt") return formatUtcTimestamp(date);
if (normalized === "local" || normalized === "host") return formatZonedTimestamp(date);
return formatZonedTimestamp(date, zone);
}
export function formatLocalEnvelopeTimestamp(date: Date): string {
return formatEnvelopeTimestamp(date, "local");
}
export function escapeRegExp(value: string): string {
return value.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
}