Download src/plugin-sdk/test-helpers/envelope-timestamp.ts from SaylorTwift/openclaw: direct link, hf CLI and curl.
- Browser
- Download file 1.73 kB
-
https://huggingface.co/SaylorTwift/openclaw/resolve/main/src/plugin-sdk/test-helpers/envelope-timestamp.ts
- Command line
-
hf download hf://SaylorTwift/openclaw/src/plugin-sdk/test-helpers/envelope-timestamp.ts
-
curl -L -o envelope-timestamp.ts https://huggingface.co/SaylorTwift/openclaw/resolve/main/src/plugin-sdk/test-helpers/envelope-timestamp.ts
1.73 kB
| /** | |
| * Shared helpers for asserting envelope timestamp normalization in channel tests. | |
| */ | |
| import { | |
| formatUtcTimestamp, | |
| formatZonedTimestamp, | |
| } from "../../infra/format-time/format-datetime.js"; | |
| export { escapeRegExp } from "../../utils.js"; | |
| type EnvelopeTimestampZone = string; | |
| export function formatEnvelopeTimestamp(date: Date, zone: EnvelopeTimestampZone = "utc"): string { | |
| const trimmedZone = zone.trim(); | |
| const normalized = trimmedZone.toLowerCase(); | |
| const weekday = (() => { | |
| try { | |
| if (normalized === "utc" || normalized === "gmt") { | |
| return new Intl.DateTimeFormat("en-US", { timeZone: "UTC", weekday: "short" }).format(date); | |
| } | |
| if (normalized === "local" || normalized === "host") { | |
| return new Intl.DateTimeFormat("en-US", { weekday: "short" }).format(date); | |
| } | |
| return new Intl.DateTimeFormat("en-US", { timeZone: trimmedZone, weekday: "short" }).format( | |
| date, | |
| ); | |
| } catch { | |
| return undefined; | |
| } | |
| })(); | |
| if (normalized === "utc" || normalized === "gmt") { | |
| const ts = formatUtcTimestamp(date, { displaySeconds: true }); | |
| return weekday ? `${weekday} ${ts}` : ts; | |
| } | |
| if (normalized === "local" || normalized === "host") { | |
| const ts = | |
| formatZonedTimestamp(date, { displaySeconds: true }) ?? | |
| formatUtcTimestamp(date, { displaySeconds: true }); | |
| return weekday ? `${weekday} ${ts}` : ts; | |
| } | |
| const ts = | |
| formatZonedTimestamp(date, { timeZone: trimmedZone, displaySeconds: true }) ?? | |
| formatUtcTimestamp(date, { displaySeconds: true }); | |
| return weekday ? `${weekday} ${ts}` : ts; | |
| } | |
| export function formatLocalEnvelopeTimestamp(date: Date): string { | |
| return formatEnvelopeTimestamp(date, "local"); | |
| } | |