26 lines
876 B
TypeScript
26 lines
876 B
TypeScript
/** e.g. "Aug 12, 2026, 3:45 PM" -- absolute, not relative, so it doesn't
|
|
* need to be re-rendered on a timer just to stay accurate. */
|
|
export function formatDateTime(iso: string): string {
|
|
return new Date(iso).toLocaleString(undefined, {
|
|
year: "numeric",
|
|
month: "short",
|
|
day: "numeric",
|
|
hour: "numeric",
|
|
minute: "2-digit",
|
|
});
|
|
}
|
|
|
|
/** e.g. "Monday, Aug 17" from a "YYYY-MM-DD" date key. Forces UTC
|
|
* interpretation -- these keys are calendar dates, not instants, so
|
|
* rendering them in the viewer's local timezone could shift midnight UTC
|
|
* to the wrong day (e.g. showing "Sunday" for a Monday date key west of
|
|
* UTC). */
|
|
export function formatWeekdayDate(dateKey: string): string {
|
|
return new Date(`${dateKey}T00:00:00Z`).toLocaleDateString(undefined, {
|
|
weekday: "long",
|
|
month: "short",
|
|
day: "numeric",
|
|
timeZone: "UTC",
|
|
});
|
|
}
|