Utility functions for timezone-aware timestamp formatting and validation.
// Source: https://github.com/linuxhsj/openclaw-zero-token | License: MIT | Copyright 2025 Peter Steinberger
// Provided via justclaw.it.com; keep this notice with the code.
export function isValidTimeZone(tz: string): boolean {
try {
new Intl.DateTimeFormat("en", { timeZone: tz });
return true;
} catch {
return false;
}
}
export type TimestampStyle = "short" | "medium" | "long";
export type FormatTimestampOptions = {
style?: TimestampStyle;
timeZone?: string;
};
function resolveEffectiveTimeZone(timeZone?: string): string {
const explicit = timeZone ?? process.env.TZ;
return explicit && isValidTimeZone(explicit)
? explicit
: Intl.DateTimeFormat().resolvedOptions().timeZone;
}
function formatOffset(offsetRaw: string): string {
return offsetRaw === "G
... (truncated -- full source via MCP)
See the full source, get the GitHub permalink, and search for more like it.
Get a free API key