mirror of
https://github.com/BetterSEQTA/BetterSEQTA-Plus.git
synced 2026-12-06 19:56:45 +10:30
20 lines
550 B
TypeScript
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}`;
|
|
}
|