@mantine/dates
Version:
Calendars, date and time pickers based on Mantine components
42 lines (41 loc) • 1.19 kB
JavaScript
"use client";
import { padTime } from "../pad-time/pad-time.mjs";
//#region packages/@mantine/dates/src/components/TimePicker/utils/get-time-string/get-time-string.ts
function convertTo24HourFormat({ hours, minutes, seconds, amPm, amPmLabels, withSeconds }) {
let _hours = hours;
if (amPm === amPmLabels.pm && hours !== 12) _hours += 12;
else if (amPm === amPmLabels.am && hours === 12) _hours = 0;
return `${padTime(_hours)}:${padTime(minutes)}${withSeconds ? `:${padTime(seconds || 0)}` : ""}`;
}
function getTimeString({ hours, minutes, seconds, format, withSeconds, amPm, amPmLabels }) {
if (hours === null || minutes === null) return {
valid: false,
value: ""
};
if (withSeconds && seconds === null) return {
valid: false,
value: ""
};
if (format === "24h") return {
valid: true,
value: `${padTime(hours)}:${padTime(minutes)}${withSeconds ? `:${padTime(seconds)}` : ""}`
};
if (amPm === null) return {
valid: false,
value: ""
};
return {
valid: true,
value: convertTo24HourFormat({
hours,
minutes,
seconds,
amPm,
amPmLabels,
withSeconds
})
};
}
//#endregion
export { getTimeString };
//# sourceMappingURL=get-time-string.mjs.map