- Created frontend/app/utils/date.ts with formatDate, formatTime, formatDateTime, formatDisplayDate - Created frontend/e2e/helpers/date.ts with formatDateLocal, getTomorrowDateStr - Updated all frontend pages and e2e tests to use shared utilities - Removed duplicate date formatting code from 6 files
48 lines
1.1 KiB
TypeScript
48 lines
1.1 KiB
TypeScript
/**
|
|
* Shared date formatting utilities.
|
|
*/
|
|
|
|
/**
|
|
* Format date as YYYY-MM-DD in local timezone.
|
|
*/
|
|
export function formatDate(d: Date): string {
|
|
const year = d.getFullYear();
|
|
const month = String(d.getMonth() + 1).padStart(2, "0");
|
|
const day = String(d.getDate()).padStart(2, "0");
|
|
return `${year}-${month}-${day}`;
|
|
}
|
|
|
|
/**
|
|
* Format time from ISO string to HH:MM format.
|
|
*/
|
|
export function formatTime(isoString: string): string {
|
|
const d = new Date(isoString);
|
|
return d.toLocaleTimeString("en-US", {
|
|
hour: "2-digit",
|
|
minute: "2-digit",
|
|
hour12: false,
|
|
});
|
|
}
|
|
|
|
/**
|
|
* Format datetime from ISO string to a readable format.
|
|
*/
|
|
export function formatDateTime(isoString: string): string {
|
|
const d = new Date(isoString);
|
|
return d.toLocaleString("en-US", {
|
|
weekday: "short",
|
|
month: "short",
|
|
day: "numeric",
|
|
hour: "2-digit",
|
|
minute: "2-digit",
|
|
hour12: false,
|
|
});
|
|
}
|
|
|
|
/**
|
|
* Format date for display (e.g., "Mon, Jan 15").
|
|
*/
|
|
export function formatDisplayDate(d: Date): string {
|
|
return d.toLocaleDateString("en-US", { weekday: "short", month: "short", day: "numeric" });
|
|
}
|
|
|