{"version":3,"file":"utils.js","sources":["../../../../../../packages/components/time-picker/src/utils.ts"],"sourcesContent":["import dayjs from 'dayjs'\nimport { isArray, isDate, isEmpty } from '@element-plus/utils'\n\nimport type { Dayjs } from 'dayjs'\nexport type TimeList = [number | undefined, number, undefined | number]\n\nexport const buildTimeList = (value: number, bound: number): TimeList => {\n return [\n value > 0 ? value - 1 : undefined,\n value,\n value < bound ? value + 1 : undefined,\n ]\n}\n\nexport const rangeArr = (n: number) =>\n Array.from(Array.from({ length: n }).keys())\n\nexport const extractDateFormat = (format: string) => {\n return format\n .replace(/\\W?m{1,2}|\\W?ZZ/g, '')\n .replace(/\\W?h{1,2}|\\W?s{1,3}|\\W?a/gi, '')\n .trim()\n}\n\nexport const extractTimeFormat = (format: string) => {\n return format\n .replace(/\\W?D{1,2}|\\W?Do|\\W?d{1,4}|\\W?M{1,4}|\\W?Y{2,4}/g, '')\n .trim()\n}\n\nexport const dateEquals = function (a: Date | unknown, b: Date | unknown) {\n const aIsDate = isDate(a)\n const bIsDate = isDate(b)\n if (aIsDate && bIsDate) {\n return a.getTime() === b.getTime()\n }\n if (!aIsDate && !bIsDate) {\n return a === b\n }\n return false\n}\n\nexport const valueEquals = function (\n a: Array | unknown,\n b: Array | unknown\n) {\n const aIsArray = isArray(a)\n const bIsArray = isArray(b)\n if (aIsArray && bIsArray) {\n if (a.length !== b.length) {\n return false\n }\n return a.every((item, index) => dateEquals(item, b[index]))\n }\n if (!aIsArray && !bIsArray) {\n return dateEquals(a, b)\n }\n return false\n}\n\nexport const parseDate = function (\n date: string | number | Date,\n format: string | undefined,\n lang: string\n) {\n const day =\n isEmpty(format) || format === 'x'\n ? dayjs(date).locale(lang)\n : dayjs(date, format).locale(lang)\n return day.isValid() ? day : undefined\n}\n\nexport const formatter = function (\n date: string | number | Date | Dayjs,\n format: string | undefined,\n lang: string\n) {\n if (isEmpty(format)) return date\n if (format === 'x') return +date\n return dayjs(date).locale(lang).format(format)\n}\n\nexport const makeList = (total: number, method?: () => number[]) => {\n const arr: boolean[] = []\n const disabledArr = method?.()\n for (let i = 0; i < total; i++) {\n arr.push(disabledArr?.includes(i) ?? false)\n }\n return arr\n}\n"],"names":["isDate","isArray","isEmpty","dayjs"],"mappings":";;;;;;;;;;;;;AAEY,MAAC,aAAa,GAAG,CAAC,KAAK,EAAE,KAAK,KAAK;AAC/C,EAAE,OAAO;AACT,IAAI,KAAK,GAAG,CAAC,GAAG,KAAK,GAAG,CAAC,GAAG,KAAK,CAAC;AAClC,IAAI,KAAK;AACT,IAAI,KAAK,GAAG,KAAK,GAAG,KAAK,GAAG,CAAC,GAAG,KAAK,CAAC;AACtC,GAAG,CAAC;AACJ,EAAE;AACU,MAAC,QAAQ,GAAG,CAAC,CAAC,KAAK,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,CAAC,CAAC,IAAI,EAAE,EAAE;AAChE,MAAC,iBAAiB,GAAG,CAAC,MAAM,KAAK;AAC7C,EAAE,OAAO,MAAM,CAAC,OAAO,CAAC,kBAAkB,EAAE,EAAE,CAAC,CAAC,OAAO,CAAC,4BAA4B,EAAE,EAAE,CAAC,CAAC,IAAI,EAAE,CAAC;AACjG,EAAE;AACU,MAAC,iBAAiB,GAAG,CAAC,MAAM,KAAK;AAC7C,EAAE,OAAO,MAAM,CAAC,OAAO,CAAC,gDAAgD,EAAE,EAAE,CAAC,CAAC,IAAI,EAAE,CAAC;AACrF,EAAE;AACU,MAAC,UAAU,GAAG,SAAS,CAAC,EAAE,CAAC,EAAE;AACzC,EAAE,MAAM,OAAO,GAAGA,aAAM,CAAC,CAAC,CAAC,CAAC;AAC5B,EAAE,MAAM,OAAO,GAAGA,aAAM,CAAC,CAAC,CAAC,CAAC;AAC5B,EAAE,IAAI,OAAO,IAAI,OAAO,EAAE;AAC1B,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,KAAK,CAAC,CAAC,OAAO,EAAE,CAAC;AACvC,GAAG;A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