@mantine/dates
Version:
Calendars, date and time pickers based on Mantine components
42 lines (41 loc) • 1.31 kB
JavaScript
"use client";
const require_pad_time = require("../pad-time/pad-time.cjs");
//#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 `${require_pad_time.padTime(_hours)}:${require_pad_time.padTime(minutes)}${withSeconds ? `:${require_pad_time.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: `${require_pad_time.padTime(hours)}:${require_pad_time.padTime(minutes)}${withSeconds ? `:${require_pad_time.padTime(seconds)}` : ""}`
};
if (amPm === null) return {
valid: false,
value: ""
};
return {
valid: true,
value: convertTo24HourFormat({
hours,
minutes,
seconds,
amPm,
amPmLabels,
withSeconds
})
};
}
//#endregion
exports.getTimeString = getTimeString;
//# sourceMappingURL=get-time-string.cjs.map