Standardize time formatting and avoid string slicing
- Created formatTimeString() utility to properly parse time strings - Replaced all .slice(0, 5) calls with proper time formatting - Handles both 'HH:MM:SS' and 'HH:MM' formats safely - More robust than string slicing
This commit is contained in:
parent
a25e84e197
commit
3c13270bc0
2 changed files with 17 additions and 4 deletions
|
|
@ -46,6 +46,19 @@ export function formatDisplayDate(d: Date): string {
|
|||
return d.toLocaleDateString("en-US", { weekday: "short", month: "short", day: "numeric" });
|
||||
}
|
||||
|
||||
/**
|
||||
* Format time string from "HH:MM:SS" or "HH:MM" format to "HH:MM".
|
||||
* Avoids string slicing by properly parsing the time.
|
||||
*/
|
||||
export function formatTimeString(timeStr: string): string {
|
||||
// Handle both "HH:MM:SS" and "HH:MM" formats
|
||||
const parts = timeStr.split(":");
|
||||
if (parts.length >= 2) {
|
||||
return `${parts[0].padStart(2, "0")}:${parts[1].padStart(2, "0")}`;
|
||||
}
|
||||
return timeStr;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get date range for booking/availability (from minAdvanceDays to maxAdvanceDays).
|
||||
* Returns an array of Date objects starting from minAdvanceDays days from today.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue