@mantine/dates
Version:
Calendars, date and time pickers based on Mantine components
1 lines • 2.08 kB
Source Map (JSON)
{"version":3,"file":"get-formatted-time.mjs","names":[],"sources":["../../../../src/components/TimeValue/get-formatted-time/get-formatted-time.ts"],"sourcesContent":["import type { TimePickerAmPmLabels, TimePickerFormat } from '../../TimePicker';\nimport { padTime } from '../../TimePicker/utils/pad-time/pad-time';\nimport { splitTimeString } from '../../TimePicker/utils/split-time-string/split-time-string';\n\nfunction getTimeFromDate(date: Date, withSeconds: boolean) {\n return `${date.getHours()}:${date.getMinutes()}${withSeconds ? `:${date.getSeconds()}` : ''}`;\n}\n\nexport interface GetFormattedTimeInput {\n value: string | Date;\n format: TimePickerFormat;\n amPmLabels: TimePickerAmPmLabels;\n withSeconds: boolean;\n}\n\nexport function getFormattedTime({\n value,\n format,\n amPmLabels,\n withSeconds,\n}: GetFormattedTimeInput) {\n const splitted = splitTimeString(\n typeof value === 'string' ? value : getTimeFromDate(value, withSeconds)\n );\n\n if (splitted.hours === null || splitted.minutes === null) {\n return null;\n }\n\n if (format === '24h') {\n return `${padTime(splitted.hours)}:${padTime(splitted.minutes)}${withSeconds ? `:${padTime(splitted.seconds || 0)}` : ''}`;\n }\n\n const isPm = splitted.hours >= 12;\n const hours = splitted.hours % 12 === 0 ? 12 : splitted.hours % 12;\n\n return `${hours}:${padTime(splitted.minutes)}${withSeconds ? `:${padTime(splitted.seconds || 0)}` : ''} ${\n isPm ? amPmLabels.pm : amPmLabels.am\n }`;\n}\n"],"mappings":";;;;AAIA,SAAS,gBAAgB,MAAY,aAAsB;CACzD,OAAO,GAAG,KAAK,SAAS,EAAE,GAAG,KAAK,WAAW,IAAI,cAAc,IAAI,KAAK,WAAW,MAAM;AAC3F;AASA,SAAgB,iBAAiB,EAC/B,OACA,QACA,YACA,eACwB;CACxB,MAAM,WAAW,gBACf,OAAO,UAAU,WAAW,QAAQ,gBAAgB,OAAO,WAAW,CACxE;CAEA,IAAI,SAAS,UAAU,QAAQ,SAAS,YAAY,MAClD,OAAO;CAGT,IAAI,WAAW,OACb,OAAO,GAAG,QAAQ,SAAS,KAAK,EAAE,GAAG,QAAQ,SAAS,OAAO,IAAI,cAAc,IAAI,QAAQ,SAAS,WAAW,CAAC,MAAM;CAGxH,MAAM,OAAO,SAAS,SAAS;CAG/B,OAAO,GAFO,SAAS,QAAQ,OAAO,IAAI,KAAK,SAAS,QAAQ,GAEhD,GAAG,QAAQ,SAAS,OAAO,IAAI,cAAc,IAAI,QAAQ,SAAS,WAAW,CAAC,MAAM,GAAG,GACrG,OAAO,WAAW,KAAK,WAAW;AAEtC"}