Files
BetterSEQTA-Plus/src/seqta/utils/convertTo12HourFormat.ts
T
2026-11-03 09:23:27 +10:30

20 lines
550 B
TypeScript

export function convertTo12HourFormat(time: string, noMinutes: boolean = false): string {
const [hoursRaw, minutes] = time.split(":").map(Number);
let hours = hoursRaw;
let period = "am";
if (hours >= 12) {
period = "pm";
if (hours > 12) hours -= 12;
} else if (hours === 0) {
hours = 12;
}
let hoursStr = hours.toString();
if (hoursStr.length === 2 && hoursStr.startsWith("0")) {
hoursStr = hoursStr.substring(1);
}
return `${hoursStr}${noMinutes ? "" : `:${minutes.toString().padStart(2, "0")}`}${period}`;
}