feat: add agent identity avatars (#1329) (thanks @dlauer)
This commit is contained in:
32
test/helpers/envelope-timestamp.ts
Normal file
32
test/helpers/envelope-timestamp.ts
Normal file
@@ -0,0 +1,32 @@
|
||||
export function formatLocalEnvelopeTimestamp(date: Date): string {
|
||||
const parts = new Intl.DateTimeFormat("en-US", {
|
||||
year: "numeric",
|
||||
month: "2-digit",
|
||||
day: "2-digit",
|
||||
hour: "2-digit",
|
||||
minute: "2-digit",
|
||||
hourCycle: "h23",
|
||||
timeZoneName: "short",
|
||||
}).formatToParts(date);
|
||||
|
||||
const pick = (type: string) => parts.find((part) => part.type === type)?.value;
|
||||
const yyyy = pick("year");
|
||||
const mm = pick("month");
|
||||
const dd = pick("day");
|
||||
const hh = pick("hour");
|
||||
const min = pick("minute");
|
||||
const tz = [...parts]
|
||||
.reverse()
|
||||
.find((part) => part.type === "timeZoneName")
|
||||
?.value?.trim();
|
||||
|
||||
if (!yyyy || !mm || !dd || !hh || !min) {
|
||||
throw new Error("Missing date parts for envelope timestamp formatting.");
|
||||
}
|
||||
|
||||
return `${yyyy}-${mm}-${dd} ${hh}:${min}${tz ? ` ${tz}` : ""}`;
|
||||
}
|
||||
|
||||
export function escapeRegExp(value: string): string {
|
||||
return value.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
||||
}
|
||||
Reference in New Issue
Block a user