UNPKG

@mantine/dates

Version:

Calendars, date and time pickers based on Mantine components

18 lines (17 loc) 1.15 kB
"use client"; import { padTime } from "../../TimePicker/utils/pad-time/pad-time.mjs"; import { splitTimeString } from "../../TimePicker/utils/split-time-string/split-time-string.mjs"; //#region packages/@mantine/dates/src/components/TimeValue/get-formatted-time/get-formatted-time.ts function getTimeFromDate(date, withSeconds) { return `${date.getHours()}:${date.getMinutes()}${withSeconds ? `:${date.getSeconds()}` : ""}`; } function getFormattedTime({ value, format, amPmLabels, withSeconds }) { const splitted = splitTimeString(typeof value === "string" ? value : getTimeFromDate(value, withSeconds)); if (splitted.hours === null || splitted.minutes === null) return null; if (format === "24h") return `${padTime(splitted.hours)}:${padTime(splitted.minutes)}${withSeconds ? `:${padTime(splitted.seconds || 0)}` : ""}`; const isPm = splitted.hours >= 12; return `${splitted.hours % 12 === 0 ? 12 : splitted.hours % 12}:${padTime(splitted.minutes)}${withSeconds ? `:${padTime(splitted.seconds || 0)}` : ""} ${isPm ? amPmLabels.pm : amPmLabels.am}`; } //#endregion export { getFormattedTime }; //# sourceMappingURL=get-formatted-time.mjs.map