Extract duplicate date formatting functions to shared utilities

- 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
This commit is contained in:
counterweight 2025-12-21 17:48:17 +01:00
parent eefdfd714f
commit 6ff3c0a133
Signed by: counterweight
GPG key ID: 883EDBAA726BD96C
9 changed files with 78 additions and 98 deletions

View file

@ -8,6 +8,7 @@ import { Header } from "../components/Header";
import { useRequireAuth } from "../hooks/useRequireAuth";
import { components } from "../generated/api";
import constants from "../../../shared/constants.json";
import { formatDate, formatTime } from "../utils/date";
const { slotDurationMinutes, maxAdvanceDays, minAdvanceDays, noteMaxLength } = constants.booking;
@ -15,24 +16,6 @@ type BookableSlot = components["schemas"]["BookableSlot"];
type AvailableSlotsResponse = components["schemas"]["AvailableSlotsResponse"];
type AppointmentResponse = components["schemas"]["AppointmentResponse"];
// Helper to format date as YYYY-MM-DD in local timezone
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}`;
}
// Helper to format time from ISO string
function formatTime(isoString: string): string {
const d = new Date(isoString);
return d.toLocaleTimeString("en-US", {
hour: "2-digit",
minute: "2-digit",
hour12: false,
});
}
// Get date range for booking (tomorrow to +30 days)
function getBookableDates(): Date[] {
const dates: Date[] = [];