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:
parent
eefdfd714f
commit
6ff3c0a133
9 changed files with 78 additions and 98 deletions
|
|
@ -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, formatDisplayDate } from "../../utils/date";
|
||||
|
||||
const { slotDurationMinutes, maxAdvanceDays } = constants.booking;
|
||||
|
||||
|
|
@ -15,14 +16,6 @@ type AvailabilityDay = components["schemas"]["AvailabilityDay"];
|
|||
type AvailabilityResponse = components["schemas"]["AvailabilityResponse"];
|
||||
type TimeSlot = components["schemas"]["TimeSlot"];
|
||||
|
||||
// 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 get next N days starting from tomorrow
|
||||
function getDateRange(): Date[] {
|
||||
const dates: Date[] = [];
|
||||
|
|
@ -223,10 +216,6 @@ export default function AdminAvailabilityPage() {
|
|||
}
|
||||
};
|
||||
|
||||
const formatDisplayDate = (d: Date): string => {
|
||||
return d.toLocaleDateString("en-US", { weekday: "short", month: "short", day: "numeric" });
|
||||
};
|
||||
|
||||
const formatSlotTime = (slot: TimeSlot): string => {
|
||||
return `${slot.start_time.slice(0, 5)} - ${slot.end_time.slice(0, 5)}`;
|
||||
};
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue