@internationalized/date 3.5.6 → 3.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +201 -0
- package/dist/BuddhistCalendar.main.js +1 -2
- package/dist/BuddhistCalendar.main.js.map +1 -1
- package/dist/BuddhistCalendar.mjs +1 -2
- package/dist/BuddhistCalendar.module.js +1 -2
- package/dist/BuddhistCalendar.module.js.map +1 -1
- package/dist/DateFormatter.main.js.map +1 -1
- package/dist/DateFormatter.module.js.map +1 -1
- package/dist/EthiopicCalendar.main.js +2 -4
- package/dist/EthiopicCalendar.main.js.map +1 -1
- package/dist/EthiopicCalendar.mjs +2 -4
- package/dist/EthiopicCalendar.module.js +2 -4
- package/dist/EthiopicCalendar.module.js.map +1 -1
- package/dist/IndianCalendar.main.js +1 -2
- package/dist/IndianCalendar.main.js.map +1 -1
- package/dist/IndianCalendar.mjs +1 -2
- package/dist/IndianCalendar.module.js +1 -2
- package/dist/IndianCalendar.module.js.map +1 -1
- package/dist/IslamicCalendar.main.js +2 -4
- package/dist/IslamicCalendar.main.js.map +1 -1
- package/dist/IslamicCalendar.mjs +2 -4
- package/dist/IslamicCalendar.module.js +2 -4
- package/dist/IslamicCalendar.module.js.map +1 -1
- package/dist/JapaneseCalendar.main.js +1 -2
- package/dist/JapaneseCalendar.main.js.map +1 -1
- package/dist/JapaneseCalendar.mjs +1 -2
- package/dist/JapaneseCalendar.module.js +1 -2
- package/dist/JapaneseCalendar.module.js.map +1 -1
- package/dist/TaiwanCalendar.main.js +1 -2
- package/dist/TaiwanCalendar.main.js.map +1 -1
- package/dist/TaiwanCalendar.mjs +1 -2
- package/dist/TaiwanCalendar.module.js +1 -2
- package/dist/TaiwanCalendar.module.js.map +1 -1
- package/dist/conversion.main.js +1 -1
- package/dist/conversion.main.js.map +1 -1
- package/dist/conversion.mjs +1 -1
- package/dist/conversion.module.js +1 -1
- package/dist/conversion.module.js.map +1 -1
- package/dist/queries.main.js +18 -8
- package/dist/queries.main.js.map +1 -1
- package/dist/queries.mjs +18 -8
- package/dist/queries.module.js +18 -8
- package/dist/queries.module.js.map +1 -1
- package/dist/string.main.js +26 -17
- package/dist/string.main.js.map +1 -1
- package/dist/string.mjs +26 -17
- package/dist/string.module.js +26 -17
- package/dist/string.module.js.map +1 -1
- package/dist/types.d.ts +12 -14
- package/dist/types.d.ts.map +1 -1
- package/package.json +4 -3
- package/src/DateFormatter.ts +4 -8
- package/src/conversion.ts +1 -1
- package/src/queries.ts +29 -16
- package/src/string.ts +37 -19
|
@@ -1 +1 @@
|
|
|
1
|
-
{"mappings":";;;;;AAAA;;;;;;;;;;CAUC,GAED,uFAAuF;AACvF,gGAAgG;;;;;AASzF,SAAS,yCAAc,IAAiB;IAC7C,OAAO,0CAAW,MAAM,IAAI,CAAA,GAAA,yCAAgB;IAC5C,IAAI,OAAO,CAAA,GAAA,yCAAc,EAAE,KAAK,GAAG,EAAE,KAAK,IAAI;IAC9C,OAAO,qCAAe,MAAM,KAAK,KAAK,EAAE,KAAK,GAAG,EAAE,KAAK,IAAI,EAAE,KAAK,MAAM,EAAE,KAAK,MAAM,EAAE,KAAK,WAAW;AACzG;AAEA,SAAS,qCAAe,IAAY,EAAE,KAAa,EAAE,GAAW,EAAE,IAAY,EAAE,MAAc,EAAE,MAAc,EAAE,WAAmB;IACjI,sEAAsE;IACtE,gCAAgC;IAChC,IAAI,OAAO,IAAI;IACf,KAAK,WAAW,CAAC,MAAM,QAAQ,QAAQ;IACvC,KAAK,cAAc,CAAC,MAAM,QAAQ,GAAG;IACrC,OAAO,KAAK,OAAO;AACrB;AAEO,SAAS,0CAAkB,EAAU,EAAE,QAAgB;IAC5D,qBAAqB;IACrB,IAAI,aAAa,OACf,OAAO;IAGT,6DAA6D;IAC7D,IAAI,KAAK,KAAK,aAAa,CAAA,GAAA,yCAAe,KACxC,OAAO,IAAI,KAAK,IAAI,iBAAiB,KAA9B;IAGT,IAAI,QAAC,IAAI,SAAE,KAA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IAAI,OAAmB,KAAK,IAAI;IAChC,KAAK,QAAQ,GAAG;IAChB,KAAK,GAAG,GAAG,aAAa,GAAG;IAC3B,KAAK,IAAI,GAAG,aAAa,IAAI;IAC7B,KAAK,KAAK,GAAG,aAAa,KAAK;IAC/B,KAAK,GAAG,GAAG,aAAa,GAAG;IAC3B,CAAA,GAAA,yCAAQ,EAAE;IACV,OAAO;AACT;AAMO,SAAS,0CAAQ,IAAqD,EAAE,QAAgB,EAAE,cAA+B;IAC9H,IAAI,gBAAgB,CAAA,GAAA,yCAAY,GAAG;QACjC,IAAI,KAAK,QAAQ,KAAK,UACpB,OAAO;QAGT,OAAO,0CAAW,MAAM;IAC1B;IAEA,IAAI,KAAK,0CAAW,MAAM,UAAU;IACpC,OAAO,0CAAa,IAAI;AAC1B;AAEO,SAAS,yCAAY,IAAmB;IAC7C,IAAI,KAAK,yCAAc,QAAQ,KAAK,MAAM;IAC1C,OAAO,IAAI,KAAK;AAClB;AAGO,SAAS,0CAAW,IAAmB,EAAE,QAAgB;IAC9D,IAAI,KAAK,yCAAc,QAAQ,KAAK,MAAM;IAC1C,OAAO,0CAAW,0CAAa,IAAI,WAAW,KAAK,QAAQ;AAC7D;AAGO,SAAS,0CAAgB,IAAmB;IACjD,OAAO,0CAAW,MAAM,CAAA,GAAA,yCAAe;AACzC","sources":["packages/@internationalized/date/src/conversion.ts"],"sourcesContent":["/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\n// Portions of the code in this file are based on code from the TC39 Temporal proposal.\n// Original licensing can be found in the NOTICE file in the root directory of this source tree.\n\nimport {AnyCalendarDate, AnyDateTime, AnyTime, Calendar, DateFields, Disambiguation, TimeFields} from './types';\nimport {CalendarDate, CalendarDateTime, Time, ZonedDateTime} from './CalendarDate';\nimport {constrain} from './manipulation';\nimport {getExtendedYear, GregorianCalendar} from './calendars/GregorianCalendar';\nimport {getLocalTimeZone} from './queries';\nimport {Mutable} from './utils';\n\nexport function epochFromDate(date: AnyDateTime) {\n date = toCalendar(date, new GregorianCalendar());\n let year = getExtendedYear(date.era, date.year);\n return epochFromParts(year, date.month, date.day, date.hour, date.minute, date.second, date.millisecond);\n}\n\nfunction epochFromParts(year: number, month: number, day: number, hour: number, minute: number, second: number, millisecond: number) {\n // Note: Date.UTC() interprets one and two-digit years as being in the\n // 20th century, so don't use it\n let date = new Date();\n date.setUTCHours(hour, minute, second, millisecond);\n date.setUTCFullYear(year, month - 1, day);\n return date.getTime();\n}\n\nexport function getTimeZoneOffset(ms: number, timeZone: string) {\n // Fast path for UTC.\n if (timeZone === 'UTC') {\n return 0;\n }\n\n // Fast path: for local timezone after 1970, use native Date.\n if (ms > 0 && timeZone === getLocalTimeZone()) {\n return new Date(ms).getTimezoneOffset() * -60 * 1000;\n }\n\n let {year, month, day, hour, minute, second} = getTimeZoneParts(ms, timeZone);\n let utc = epochFromParts(year, month, day, hour, minute, second, 0);\n return utc - Math.floor(ms / 1000) * 1000;\n}\n\nconst formattersByTimeZone = new Map<string, Intl.DateTimeFormat>();\n\nfunction getTimeZoneParts(ms: number, timeZone: string) {\n let formatter = formattersByTimeZone.get(timeZone);\n if (!formatter) {\n formatter = new Intl.DateTimeFormat('en-US', {\n timeZone,\n hour12: false,\n era: 'short',\n year: 'numeric',\n month: 'numeric',\n day: 'numeric',\n hour: 'numeric',\n minute: 'numeric',\n second: 'numeric'\n });\n\n formattersByTimeZone.set(timeZone, formatter);\n }\n\n let parts = formatter.formatToParts(new Date(ms));\n let namedParts: {[name: string]: string} = {};\n for (let part of parts) {\n if (part.type !== 'literal') {\n namedParts[part.type] = part.value;\n }\n }\n\n\n return {\n // Firefox returns B instead of BC... https://bugzilla.mozilla.org/show_bug.cgi?id=1752253\n year: namedParts.era === 'BC' || namedParts.era === 'B' ? -namedParts.year + 1 : +namedParts.year,\n month: +namedParts.month,\n day: +namedParts.day,\n hour: namedParts.hour === '24' ? 0 : +namedParts.hour, // bugs.chromium.org/p/chromium/issues/detail?id=1045791\n minute: +namedParts.minute,\n second: +namedParts.second\n };\n}\n\nconst DAYMILLIS = 86400000;\n\nexport function possibleAbsolutes(date: CalendarDateTime, timeZone: string): number[] {\n let ms = epochFromDate(date);\n let earlier = ms - getTimeZoneOffset(ms - DAYMILLIS, timeZone);\n let later = ms - getTimeZoneOffset(ms + DAYMILLIS, timeZone);\n return getValidWallTimes(date, timeZone, earlier, later);\n}\n\nfunction getValidWallTimes(date: CalendarDateTime, timeZone: string, earlier: number, later: number): number[] {\n let found = earlier === later ? [earlier] : [earlier, later];\n return found.filter(absolute => isValidWallTime(date, timeZone, absolute));\n}\n\nfunction isValidWallTime(date: CalendarDateTime, timeZone: string, absolute: number) {\n let parts = getTimeZoneParts(absolute, timeZone);\n return date.year === parts.year\n && date.month === parts.month\n && date.day === parts.day\n && date.hour === parts.hour\n && date.minute === parts.minute\n && date.second === parts.second;\n}\n\nexport function toAbsolute(date: CalendarDate | CalendarDateTime, timeZone: string, disambiguation: Disambiguation = 'compatible'): number {\n let dateTime = toCalendarDateTime(date);\n\n // Fast path: if the time zone is UTC, use native Date.\n if (timeZone === 'UTC') {\n return epochFromDate(dateTime);\n }\n\n // Fast path: if the time zone is the local timezone and disambiguation is compatible, use native Date.\n if (timeZone === getLocalTimeZone() && disambiguation === 'compatible') {\n dateTime = toCalendar(dateTime, new GregorianCalendar());\n\n // Don't use Date constructor here because two-digit years are interpreted in the 20th century.\n let date = new Date();\n let year = getExtendedYear(dateTime.era, dateTime.year);\n date.setFullYear(year, dateTime.month - 1, dateTime.day);\n date.setHours(dateTime.hour, dateTime.minute, dateTime.second, dateTime.millisecond);\n return date.getTime();\n }\n\n let ms = epochFromDate(dateTime);\n let offsetBefore = getTimeZoneOffset(ms - DAYMILLIS, timeZone);\n let offsetAfter = getTimeZoneOffset(ms + DAYMILLIS, timeZone);\n let valid = getValidWallTimes(dateTime, timeZone, ms - offsetBefore, ms - offsetAfter);\n\n if (valid.length === 1) {\n return valid[0];\n }\n\n if (valid.length > 1) {\n switch (disambiguation) {\n // 'compatible' means 'earlier' for \"fall back\" transitions\n case 'compatible':\n case 'earlier':\n return valid[0];\n case 'later':\n return valid[valid.length - 1];\n case 'reject':\n throw new RangeError('Multiple possible absolute times found');\n }\n }\n\n switch (disambiguation) {\n case 'earlier':\n return Math.min(ms - offsetBefore, ms - offsetAfter);\n // 'compatible' means 'later' for \"spring forward\" transitions\n case 'compatible':\n case 'later':\n return Math.max(ms - offsetBefore, ms - offsetAfter);\n case 'reject':\n throw new RangeError('No such absolute time found');\n }\n}\n\nexport function toDate(dateTime: CalendarDate | CalendarDateTime, timeZone: string, disambiguation: Disambiguation = 'compatible'): Date {\n return new Date(toAbsolute(dateTime, timeZone, disambiguation));\n}\n\n/**\n * Takes a Unix epoch (milliseconds since 1970) and converts it to the provided time zone.\n */\nexport function fromAbsolute(ms: number, timeZone: string): ZonedDateTime {\n let offset = getTimeZoneOffset(ms, timeZone);\n let date = new Date(ms + offset);\n let year = date.getUTCFullYear();\n let month = date.getUTCMonth() + 1;\n let day = date.getUTCDate();\n let hour = date.getUTCHours();\n let minute = date.getUTCMinutes();\n let second = date.getUTCSeconds();\n let millisecond = date.getUTCMilliseconds();\n\n return new ZonedDateTime(year, month, day, timeZone, offset, hour, minute, second, millisecond);\n}\n\n/**\n * Takes a `Date` object and converts it to the provided time zone.\n */\nexport function fromDate(date: Date, timeZone: string): ZonedDateTime {\n return fromAbsolute(date.getTime(), timeZone);\n}\n\nexport function fromDateToLocal(date: Date): ZonedDateTime {\n return fromDate(date, getLocalTimeZone());\n}\n\n/** Converts a value with date components such as a `CalendarDateTime` or `ZonedDateTime` into a `CalendarDate`. */\nexport function toCalendarDate(dateTime: AnyCalendarDate): CalendarDate {\n return new CalendarDate(dateTime.calendar, dateTime.era, dateTime.year, dateTime.month, dateTime.day);\n}\n\nexport function toDateFields(date: AnyCalendarDate): DateFields {\n return {\n era: date.era,\n year: date.year,\n month: date.month,\n day: date.day\n };\n}\n\nexport function toTimeFields(date: AnyTime): TimeFields {\n return {\n hour: date.hour,\n minute: date.minute,\n second: date.second,\n millisecond: date.millisecond\n };\n}\n\n/**\n * Converts a date value to a `CalendarDateTime`. An optional `Time` value can be passed to set the time\n * of the resulting value, otherwise it will default to midnight.\n */\nexport function toCalendarDateTime(date: CalendarDate | CalendarDateTime | ZonedDateTime, time?: AnyTime): CalendarDateTime {\n let hour = 0, minute = 0, second = 0, millisecond = 0;\n if ('timeZone' in date) {\n ({hour, minute, second, millisecond} = date);\n } else if ('hour' in date && !time) {\n return date;\n }\n\n if (time) {\n ({hour, minute, second, millisecond} = time);\n }\n\n return new CalendarDateTime(\n date.calendar,\n date.era,\n date.year,\n date.month,\n date.day,\n hour,\n minute,\n second,\n millisecond\n );\n}\n\n/** Extracts the time components from a value containing a date and time. */\nexport function toTime(dateTime: CalendarDateTime | ZonedDateTime): Time {\n return new Time(dateTime.hour, dateTime.minute, dateTime.second, dateTime.millisecond);\n}\n\n/** Converts a date from one calendar system to another. */\nexport function toCalendar<T extends AnyCalendarDate>(date: T, calendar: Calendar): T {\n if (date.calendar.identifier === calendar.identifier) {\n return date;\n }\n\n let calendarDate = calendar.fromJulianDay(date.calendar.toJulianDay(date));\n let copy: Mutable<T> = date.copy();\n copy.calendar = calendar;\n copy.era = calendarDate.era;\n copy.year = calendarDate.year;\n copy.month = calendarDate.month;\n copy.day = calendarDate.day;\n constrain(copy);\n return copy;\n}\n\n/**\n * Converts a date value to a `ZonedDateTime` in the provided time zone. The `disambiguation` option can be set\n * to control how values that fall on daylight saving time changes are interpreted.\n */\nexport function toZoned(date: CalendarDate | CalendarDateTime | ZonedDateTime, timeZone: string, disambiguation?: Disambiguation): ZonedDateTime {\n if (date instanceof ZonedDateTime) {\n if (date.timeZone === timeZone) {\n return date;\n }\n\n return toTimeZone(date, timeZone);\n }\n\n let ms = toAbsolute(date, timeZone, disambiguation);\n return fromAbsolute(ms, timeZone);\n}\n\nexport function zonedToDate(date: ZonedDateTime) {\n let ms = epochFromDate(date) - date.offset;\n return new Date(ms);\n}\n\n/** Converts a `ZonedDateTime` from one time zone to another. */\nexport function toTimeZone(date: ZonedDateTime, timeZone: string): ZonedDateTime {\n let ms = epochFromDate(date) - date.offset;\n return toCalendar(fromAbsolute(ms, timeZone), date.calendar);\n}\n\n/** Converts the given `ZonedDateTime` into the user's local time zone. */\nexport function toLocalTimeZone(date: ZonedDateTime): ZonedDateTime {\n return toTimeZone(date, getLocalTimeZone());\n}\n"],"names":[],"version":3,"file":"conversion.module.js.map"}
|
|
1
|
+
{"mappings":";;;;;AAAA;;;;;;;;;;CAUC,GAED,uFAAuF;AACvF,gGAAgG;;;;;AASzF,SAAS,yCAAc,IAAiB;IAC7C,OAAO,0CAAW,MAAM,IAAI,CAAA,GAAA,yCAAgB;IAC5C,IAAI,OAAO,CAAA,GAAA,yCAAc,EAAE,KAAK,GAAG,EAAE,KAAK,IAAI;IAC9C,OAAO,qCAAe,MAAM,KAAK,KAAK,EAAE,KAAK,GAAG,EAAE,KAAK,IAAI,EAAE,KAAK,MAAM,EAAE,KAAK,MAAM,EAAE,KAAK,WAAW;AACzG;AAEA,SAAS,qCAAe,IAAY,EAAE,KAAa,EAAE,GAAW,EAAE,IAAY,EAAE,MAAc,EAAE,MAAc,EAAE,WAAmB;IACjI,sEAAsE;IACtE,gCAAgC;IAChC,IAAI,OAAO,IAAI;IACf,KAAK,WAAW,CAAC,MAAM,QAAQ,QAAQ;IACvC,KAAK,cAAc,CAAC,MAAM,QAAQ,GAAG;IACrC,OAAO,KAAK,OAAO;AACrB;AAEO,SAAS,0CAAkB,EAAU,EAAE,QAAgB;IAC5D,qBAAqB;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AM,EAAE,SAAS,MAAM,EAAE,SAAS,WAAW;AACvF;AAGO,SAAS,0CAAsC,IAAO,EAAE,QAAkB;IAC/E,IAAI,KAAK,QAAQ,CAAC,UAAU,KAAK,SAAS,UAAU,EAClD,OAAO;IAGT,IAAI,eAAe,SAAS,aAAa,CAAC,KAAK,QAAQ,CAAC,WAAW,CAAC;IACpE,IAAI,OAAmB,KAAK,IAAI;IAChC,KAAK,QAAQ,GAAG;IAChB,KAAK,GAAG,GAAG,aAAa,GAAG;IAC3B,KAAK,IAAI,GAAG,aAAa,IAAI;IAC7B,KAAK,KAAK,GAAG,aAAa,KAAK;IAC/B,KAAK,GAAG,GAAG,aAAa,GAAG;IAC3B,CAAA,GAAA,yCAAQ,EAAE;IACV,OAAO;AACT;AAMO,SAAS,0CAAQ,IAAqD,EAAE,QAAgB,EAAE,cAA+B;IAC9H,IAAI,gBAAgB,CAAA,GAAA,yCAAY,GAAG;QACjC,IAAI,KAAK,QAAQ,KAAK,UACpB,OAAO;QAGT,OAAO,0CAAW,MAAM;IAC1B;IAEA,IAAI,KAAK,0CAAW,MAAM,UAAU;IACpC,OAAO,0CAAa,IAAI;AAC1B;AAEO,SAAS,yCAAY,IAAmB;IAC7C,IAAI,KAAK,yCAAc,QAAQ,KAAK,MAAM;IAC1C,OAAO,IAAI,KAAK;AAClB;AAGO,SAAS,0CAAW,IAAmB,EAAE,QAAgB;IAC9D,IAAI,KAAK,yCAAc,QAAQ,KAAK,MAAM;IAC1C,OAAO,0CAAW,0CAAa,IAAI,WAAW,KAAK,QAAQ;AAC7D;AAGO,SAAS,0CAAgB,IAAmB;IACjD,OAAO,0CAAW,MAAM,CAAA,GAAA,yCAAe;AACzC","sources":["packages/@internationalized/date/src/conversion.ts"],"sourcesContent":["/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\n// Portions of the code in this file are based on code from the TC39 Temporal proposal.\n// Original licensing can be found in the NOTICE file in the root directory of this source tree.\n\nimport {AnyCalendarDate, AnyDateTime, AnyTime, Calendar, DateFields, Disambiguation, TimeFields} from './types';\nimport {CalendarDate, CalendarDateTime, Time, ZonedDateTime} from './CalendarDate';\nimport {constrain} from './manipulation';\nimport {getExtendedYear, GregorianCalendar} from './calendars/GregorianCalendar';\nimport {getLocalTimeZone} from './queries';\nimport {Mutable} from './utils';\n\nexport function epochFromDate(date: AnyDateTime) {\n date = toCalendar(date, new GregorianCalendar());\n let year = getExtendedYear(date.era, date.year);\n return epochFromParts(year, date.month, date.day, date.hour, date.minute, date.second, date.millisecond);\n}\n\nfunction epochFromParts(year: number, month: number, day: number, hour: number, minute: number, second: number, millisecond: number) {\n // Note: Date.UTC() interprets one and two-digit years as being in the\n // 20th century, so don't use it\n let date = new Date();\n date.setUTCHours(hour, minute, second, millisecond);\n date.setUTCFullYear(year, month - 1, day);\n return date.getTime();\n}\n\nexport function getTimeZoneOffset(ms: number, timeZone: string) {\n // Fast path for UTC.\n if (timeZone === 'UTC') {\n return 0;\n }\n\n // Fast path: for local timezone after 1970, use native Date.\n if (ms > 0 && timeZone === getLocalTimeZone()) {\n return new Date(ms).getTimezoneOffset() * -60 * 1000;\n }\n\n let {year, month, day, hour, minute, second} = getTimeZoneParts(ms, timeZone);\n let utc = epochFromParts(year, month, day, hour, minute, second, 0);\n return utc - Math.floor(ms / 1000) * 1000;\n}\n\nconst formattersByTimeZone = new Map<string, Intl.DateTimeFormat>();\n\nfunction getTimeZoneParts(ms: number, timeZone: string) {\n let formatter = formattersByTimeZone.get(timeZone);\n if (!formatter) {\n formatter = new Intl.DateTimeFormat('en-US', {\n timeZone,\n hour12: false,\n era: 'short',\n year: 'numeric',\n month: 'numeric',\n day: 'numeric',\n hour: 'numeric',\n minute: 'numeric',\n second: 'numeric'\n });\n\n formattersByTimeZone.set(timeZone, formatter);\n }\n\n let parts = formatter.formatToParts(new Date(ms));\n let namedParts: {[name: string]: string} = {};\n for (let part of parts) {\n if (part.type !== 'literal') {\n namedParts[part.type] = part.value;\n }\n }\n\n\n return {\n // Firefox returns B instead of BC... https://bugzilla.mozilla.org/show_bug.cgi?id=1752253\n year: namedParts.era === 'BC' || namedParts.era === 'B' ? -namedParts.year + 1 : +namedParts.year,\n month: +namedParts.month,\n day: +namedParts.day,\n hour: namedParts.hour === '24' ? 0 : +namedParts.hour, // bugs.chromium.org/p/chromium/issues/detail?id=1045791\n minute: +namedParts.minute,\n second: +namedParts.second\n };\n}\n\nconst DAYMILLIS = 86400000;\n\nexport function possibleAbsolutes(date: CalendarDateTime, timeZone: string): number[] {\n let ms = epochFromDate(date);\n let earlier = ms - getTimeZoneOffset(ms - DAYMILLIS, timeZone);\n let later = ms - getTimeZoneOffset(ms + DAYMILLIS, timeZone);\n return getValidWallTimes(date, timeZone, earlier, later);\n}\n\nfunction getValidWallTimes(date: CalendarDateTime, timeZone: string, earlier: number, later: number): number[] {\n let found = earlier === later ? [earlier] : [earlier, later];\n return found.filter(absolute => isValidWallTime(date, timeZone, absolute));\n}\n\nfunction isValidWallTime(date: CalendarDateTime, timeZone: string, absolute: number) {\n let parts = getTimeZoneParts(absolute, timeZone);\n return date.year === parts.year\n && date.month === parts.month\n && date.day === parts.day\n && date.hour === parts.hour\n && date.minute === parts.minute\n && date.second === parts.second;\n}\n\nexport function toAbsolute(date: CalendarDate | CalendarDateTime, timeZone: string, disambiguation: Disambiguation = 'compatible'): number {\n let dateTime = toCalendarDateTime(date);\n\n // Fast path: if the time zone is UTC, use native Date.\n if (timeZone === 'UTC') {\n return epochFromDate(dateTime);\n }\n\n // Fast path: if the time zone is the local timezone and disambiguation is compatible, use native Date.\n if (timeZone === getLocalTimeZone() && disambiguation === 'compatible') {\n dateTime = toCalendar(dateTime, new GregorianCalendar());\n\n // Don't use Date constructor here because two-digit years are interpreted in the 20th century.\n let date = new Date();\n let year = getExtendedYear(dateTime.era, dateTime.year);\n date.setFullYear(year, dateTime.month - 1, dateTime.day);\n date.setHours(dateTime.hour, dateTime.minute, dateTime.second, dateTime.millisecond);\n return date.getTime();\n }\n\n let ms = epochFromDate(dateTime);\n let offsetBefore = getTimeZoneOffset(ms - DAYMILLIS, timeZone);\n let offsetAfter = getTimeZoneOffset(ms + DAYMILLIS, timeZone);\n let valid = getValidWallTimes(dateTime, timeZone, ms - offsetBefore, ms - offsetAfter);\n\n if (valid.length === 1) {\n return valid[0];\n }\n\n if (valid.length > 1) {\n switch (disambiguation) {\n // 'compatible' means 'earlier' for \"fall back\" transitions\n case 'compatible':\n case 'earlier':\n return valid[0];\n case 'later':\n return valid[valid.length - 1];\n case 'reject':\n throw new RangeError('Multiple possible absolute times found');\n }\n }\n\n switch (disambiguation) {\n case 'earlier':\n return Math.min(ms - offsetBefore, ms - offsetAfter);\n // 'compatible' means 'later' for \"spring forward\" transitions\n case 'compatible':\n case 'later':\n return Math.max(ms - offsetBefore, ms - offsetAfter);\n case 'reject':\n throw new RangeError('No such absolute time found');\n }\n}\n\nexport function toDate(dateTime: CalendarDate | CalendarDateTime, timeZone: string, disambiguation: Disambiguation = 'compatible'): Date {\n return new Date(toAbsolute(dateTime, timeZone, disambiguation));\n}\n\n/**\n * Takes a Unix epoch (milliseconds since 1970) and converts it to the provided time zone.\n */\nexport function fromAbsolute(ms: number, timeZone: string): ZonedDateTime {\n let offset = getTimeZoneOffset(ms, timeZone);\n let date = new Date(ms + offset);\n let year = date.getUTCFullYear();\n let month = date.getUTCMonth() + 1;\n let day = date.getUTCDate();\n let hour = date.getUTCHours();\n let minute = date.getUTCMinutes();\n let second = date.getUTCSeconds();\n let millisecond = date.getUTCMilliseconds();\n\n return new ZonedDateTime(year < 1 ? 'BC' : 'AD', year < 1 ? -year + 1 : year, month, day, timeZone, offset, hour, minute, second, millisecond);\n}\n\n/**\n * Takes a `Date` object and converts it to the provided time zone.\n */\nexport function fromDate(date: Date, timeZone: string): ZonedDateTime {\n return fromAbsolute(date.getTime(), timeZone);\n}\n\nexport function fromDateToLocal(date: Date): ZonedDateTime {\n return fromDate(date, getLocalTimeZone());\n}\n\n/** Converts a value with date components such as a `CalendarDateTime` or `ZonedDateTime` into a `CalendarDate`. */\nexport function toCalendarDate(dateTime: AnyCalendarDate): CalendarDate {\n return new CalendarDate(dateTime.calendar, dateTime.era, dateTime.year, dateTime.month, dateTime.day);\n}\n\nexport function toDateFields(date: AnyCalendarDate): DateFields {\n return {\n era: date.era,\n year: date.year,\n month: date.month,\n day: date.day\n };\n}\n\nexport function toTimeFields(date: AnyTime): TimeFields {\n return {\n hour: date.hour,\n minute: date.minute,\n second: date.second,\n millisecond: date.millisecond\n };\n}\n\n/**\n * Converts a date value to a `CalendarDateTime`. An optional `Time` value can be passed to set the time\n * of the resulting value, otherwise it will default to midnight.\n */\nexport function toCalendarDateTime(date: CalendarDate | CalendarDateTime | ZonedDateTime, time?: AnyTime): CalendarDateTime {\n let hour = 0, minute = 0, second = 0, millisecond = 0;\n if ('timeZone' in date) {\n ({hour, minute, second, millisecond} = date);\n } else if ('hour' in date && !time) {\n return date;\n }\n\n if (time) {\n ({hour, minute, second, millisecond} = time);\n }\n\n return new CalendarDateTime(\n date.calendar,\n date.era,\n date.year,\n date.month,\n date.day,\n hour,\n minute,\n second,\n millisecond\n );\n}\n\n/** Extracts the time components from a value containing a date and time. */\nexport function toTime(dateTime: CalendarDateTime | ZonedDateTime): Time {\n return new Time(dateTime.hour, dateTime.minute, dateTime.second, dateTime.millisecond);\n}\n\n/** Converts a date from one calendar system to another. */\nexport function toCalendar<T extends AnyCalendarDate>(date: T, calendar: Calendar): T {\n if (date.calendar.identifier === calendar.identifier) {\n return date;\n }\n\n let calendarDate = calendar.fromJulianDay(date.calendar.toJulianDay(date));\n let copy: Mutable<T> = date.copy();\n copy.calendar = calendar;\n copy.era = calendarDate.era;\n copy.year = calendarDate.year;\n copy.month = calendarDate.month;\n copy.day = calendarDate.day;\n constrain(copy);\n return copy;\n}\n\n/**\n * Converts a date value to a `ZonedDateTime` in the provided time zone. The `disambiguation` option can be set\n * to control how values that fall on daylight saving time changes are interpreted.\n */\nexport function toZoned(date: CalendarDate | CalendarDateTime | ZonedDateTime, timeZone: string, disambiguation?: Disambiguation): ZonedDateTime {\n if (date instanceof ZonedDateTime) {\n if (date.timeZone === timeZone) {\n return date;\n }\n\n return toTimeZone(date, timeZone);\n }\n\n let ms = toAbsolute(date, timeZone, disambiguation);\n return fromAbsolute(ms, timeZone);\n}\n\nexport function zonedToDate(date: ZonedDateTime) {\n let ms = epochFromDate(date) - date.offset;\n return new Date(ms);\n}\n\n/** Converts a `ZonedDateTime` from one time zone to another. */\nexport function toTimeZone(date: ZonedDateTime, timeZone: string): ZonedDateTime {\n let ms = epochFromDate(date) - date.offset;\n return toCalendar(fromAbsolute(ms, timeZone), date.calendar);\n}\n\n/** Converts the given `ZonedDateTime` into the user's local time zone. */\nexport function toLocalTimeZone(date: ZonedDateTime): ZonedDateTime {\n return toTimeZone(date, getLocalTimeZone());\n}\n"],"names":[],"version":3,"file":"conversion.module.js.map"}
|
package/dist/queries.main.js
CHANGED
|
@@ -78,11 +78,21 @@ function $1f0f7ebf1ae6c530$export$ea840f5a6dda8147(a, b) {
|
|
|
78
78
|
function $1f0f7ebf1ae6c530$export$629b0a497aa65267(date, timeZone) {
|
|
79
79
|
return $1f0f7ebf1ae6c530$export$ea39ec197993aef0(date, $1f0f7ebf1ae6c530$export$d0bdf45af03a6ea3(timeZone));
|
|
80
80
|
}
|
|
81
|
-
|
|
81
|
+
const $1f0f7ebf1ae6c530$var$DAY_MAP = {
|
|
82
|
+
sun: 0,
|
|
83
|
+
mon: 1,
|
|
84
|
+
tue: 2,
|
|
85
|
+
wed: 3,
|
|
86
|
+
thu: 4,
|
|
87
|
+
fri: 5,
|
|
88
|
+
sat: 6
|
|
89
|
+
};
|
|
90
|
+
function $1f0f7ebf1ae6c530$export$2061056d06d7cdf7(date, locale, firstDayOfWeek) {
|
|
82
91
|
let julian = date.calendar.toJulianDay(date);
|
|
83
92
|
// If julian is negative, then julian % 7 will be negative, so we adjust
|
|
84
93
|
// accordingly. Julian day 0 is Monday.
|
|
85
|
-
let
|
|
94
|
+
let weekStart = firstDayOfWeek ? $1f0f7ebf1ae6c530$var$DAY_MAP[firstDayOfWeek] : $1f0f7ebf1ae6c530$var$getWeekStart(locale);
|
|
95
|
+
let dayOfWeek = Math.ceil(julian + 1 - weekStart) % 7;
|
|
86
96
|
if (dayOfWeek < 0) dayOfWeek += 7;
|
|
87
97
|
return dayOfWeek;
|
|
88
98
|
}
|
|
@@ -144,14 +154,14 @@ function $1f0f7ebf1ae6c530$export$b2f4953d301981d5(date) {
|
|
|
144
154
|
if (date.calendar.getMinimumDayInMonth) return date.calendar.getMinimumDayInMonth(date);
|
|
145
155
|
return 1;
|
|
146
156
|
}
|
|
147
|
-
function $1f0f7ebf1ae6c530$export$42c81a444fbfb5d4(date, locale) {
|
|
148
|
-
let dayOfWeek = $1f0f7ebf1ae6c530$export$2061056d06d7cdf7(date, locale);
|
|
157
|
+
function $1f0f7ebf1ae6c530$export$42c81a444fbfb5d4(date, locale, firstDayOfWeek) {
|
|
158
|
+
let dayOfWeek = $1f0f7ebf1ae6c530$export$2061056d06d7cdf7(date, locale, firstDayOfWeek);
|
|
149
159
|
return date.subtract({
|
|
150
160
|
days: dayOfWeek
|
|
151
161
|
});
|
|
152
162
|
}
|
|
153
|
-
function $1f0f7ebf1ae6c530$export$ef8b6d9133084f4e(date, locale) {
|
|
154
|
-
return $1f0f7ebf1ae6c530$export$42c81a444fbfb5d4(date, locale).add({
|
|
163
|
+
function $1f0f7ebf1ae6c530$export$ef8b6d9133084f4e(date, locale, firstDayOfWeek) {
|
|
164
|
+
return $1f0f7ebf1ae6c530$export$42c81a444fbfb5d4(date, locale, firstDayOfWeek).add({
|
|
155
165
|
days: 6
|
|
156
166
|
});
|
|
157
167
|
}
|
|
@@ -182,9 +192,9 @@ function $1f0f7ebf1ae6c530$var$getWeekStart(locale) {
|
|
|
182
192
|
let region = $1f0f7ebf1ae6c530$var$getRegion(locale);
|
|
183
193
|
return region ? (0, $4d88eff242b38a9e$exports.weekStartData)[region] || 0 : 0;
|
|
184
194
|
}
|
|
185
|
-
function $1f0f7ebf1ae6c530$export$ccc1b2479e7dd654(date, locale) {
|
|
195
|
+
function $1f0f7ebf1ae6c530$export$ccc1b2479e7dd654(date, locale, firstDayOfWeek) {
|
|
186
196
|
let days = date.calendar.getDaysInMonth(date);
|
|
187
|
-
return Math.ceil(($1f0f7ebf1ae6c530$export$2061056d06d7cdf7($1f0f7ebf1ae6c530$export$a5a3b454ada2268e(date), locale) + days) / 7);
|
|
197
|
+
return Math.ceil(($1f0f7ebf1ae6c530$export$2061056d06d7cdf7($1f0f7ebf1ae6c530$export$a5a3b454ada2268e(date), locale, firstDayOfWeek) + days) / 7);
|
|
188
198
|
}
|
|
189
199
|
function $1f0f7ebf1ae6c530$export$5c333a116e949cdd(a, b) {
|
|
190
200
|
if (a && b) return a.compare(b) <= 0 ? a : b;
|
package/dist/queries.main.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;;;;;;;;;;CAUC;;AAUM,SAAS,0CAAU,CAAY,EAAE,CAAY;IAClD,IAAI,CAAA,GAAA,oCAAS,EAAE,GAAG,EAAE,QAAQ;IAC5B,OAAO,EAAE,GAAG,KAAK,EAAE,GAAG,IAAI,EAAE,IAAI,KAAK,EAAE,IAAI,IAAI,EAAE,KAAK,KAAK,EAAE,KAAK,IAAI,EAAE,GAAG,KAAK,EAAE,GAAG;AACvF;AAGO,SAAS,0CAAY,CAAY,EAAE,CAAY;IACpD,IAAI,CAAA,GAAA,oCAAS,EAA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U,IAAe,EAAE,MAAc;IACvD,IAAI,SAAS,KAAK,QAAQ,CAAC,WAAW,CAAC;IAEvC,wEAAwE;IACxE,wCAAwC;IACxC,IAAI,YAAY,KAAK,IAAI,CAAC,SAAS,KAAK;IACxC,IAAI,YAAY,GACd,aAAa;IAGf,IAAI,SAAS,gCAAU;IACvB,uDAAuD;IACvD,oDAAoD;IACpD,IAAI,CAAC,OAAO,IAAI,GAAG,kCAAY,CAAC,OAAQ,IAAI;QAAC;QAAG;KAAE;IAClD,OAAO,cAAc,SAAS,cAAc;AAC9C;AAGO,SAAS,0CAAU,IAAe,EAAE,MAAc;IACvD,OAAO,CAAC,yCAAU,MAAM;AAC1B","sources":["packages/@internationalized/date/src/queries.ts"],"sourcesContent":["/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport {AnyCalendarDate, AnyTime} from './types';\nimport {CalendarDate, CalendarDateTime, ZonedDateTime} from './CalendarDate';\nimport {fromAbsolute, toAbsolute, toCalendar, toCalendarDate} from './conversion';\nimport {weekStartData} from './weekStartData';\n\ntype DateValue = CalendarDate | CalendarDateTime | ZonedDateTime;\n\n/** Returns whether the given dates occur on the same day, regardless of the time or calendar system. */\nexport function isSameDay(a: DateValue, b: DateValue): boolean {\n b = toCalendar(b, a.calendar);\n return a.era === b.era && a.year === b.year && a.month === b.month && a.day === b.day;\n}\n\n/** Returns whether the given dates occur in the same month, using the calendar system of the first date. */\nexport function isSameMonth(a: DateValue, b: DateValue): boolean {\n b = toCalendar(b, a.calendar);\n // In the Japanese calendar, months can span multiple eras/years, so only compare the first of the month.\n a = startOfMonth(a);\n b = startOfMonth(b);\n return a.era === b.era && a.year === b.year && a.month === b.month;\n}\n\n/** Returns whether the given dates occur in the same year, using the calendar system of the first date. */\nexport function isSameYear(a: DateValue, b: DateValue): boolean {\n b = toCalendar(b, a.calendar);\n a = startOfYear(a);\n b = startOfYear(b);\n return a.era === b.era && a.year === b.year;\n}\n\n/** Returns whether the given dates occur on the same day, and are of the same calendar system. */\nexport function isEqualDay(a: DateValue, b: DateValue): boolean {\n return a.calendar.identifier === b.calendar.identifier && a.era === b.era && a.year === b.year && a.month === b.month && a.day === b.day;\n}\n\n/** Returns whether the given dates occur in the same month, and are of the same calendar system. */\nexport function isEqualMonth(a: DateValue, b: DateValue): boolean {\n a = startOfMonth(a);\n b = startOfMonth(b);\n return a.calendar.identifier === b.calendar.identifier && a.era === b.era && a.year === b.year && a.month === b.month;\n}\n\n/** Returns whether the given dates occur in the same year, and are of the same calendar system. */\nexport function isEqualYear(a: DateValue, b: DateValue): boolean {\n a = startOfYear(a);\n b = startOfYear(b);\n return a.calendar.identifier === b.calendar.identifier && a.era === b.era && a.year === b.year;\n}\n\n/** Returns whether the date is today in the given time zone. */\nexport function isToday(date: DateValue, timeZone: string): boolean {\n return isSameDay(date, today(timeZone));\n}\n\n/**\n * Returns the day of week for the given date and locale. Days are numbered from zero to six,\n * where zero is the first day of the week in the given locale. For example, in the United States,\n * the first day of the week is Sunday, but in France it is Monday.\n */\nexport function getDayOfWeek(date: DateValue, locale: string): number {\n let julian = date.calendar.toJulianDay(date);\n\n // If julian is negative, then julian % 7 will be negative, so we adjust\n // accordingly. Julian day 0 is Monday.\n let dayOfWeek = Math.ceil(julian + 1 - getWeekStart(locale)) % 7;\n if (dayOfWeek < 0) {\n dayOfWeek += 7;\n }\n\n return dayOfWeek;\n}\n\n/** Returns the current time in the given time zone. */\nexport function now(timeZone: string): ZonedDateTime {\n return fromAbsolute(Date.now(), timeZone);\n}\n\n/** Returns today's date in the given time zone. */\nexport function today(timeZone: string): CalendarDate {\n return toCalendarDate(now(timeZone));\n}\n\nexport function compareDate(a: AnyCalendarDate, b: AnyCalendarDate): number {\n return a.calendar.toJulianDay(a) - b.calendar.toJulianDay(b);\n}\n\nexport function compareTime(a: AnyTime, b: AnyTime): number {\n return timeToMs(a) - timeToMs(b);\n}\n\nfunction timeToMs(a: AnyTime): number {\n return a.hour * 60 * 60 * 1000 + a.minute * 60 * 1000 + a.second * 1000 + a.millisecond;\n}\n\n/**\n * Returns the number of hours in the given date and time zone.\n * Usually this is 24, but it could be 23 or 25 if the date is on a daylight saving transition.\n */\nexport function getHoursInDay(a: CalendarDate, timeZone: string): number {\n let ms = toAbsolute(a, timeZone);\n let tomorrow = a.add({days: 1});\n let tomorrowMs = toAbsolute(tomorrow, timeZone);\n return (tomorrowMs - ms) / 3600000;\n}\n\nlet localTimeZone: string | null = null;\n\n/** Returns the time zone identifier for the current user. */\nexport function getLocalTimeZone(): string {\n // TODO: invalidate this somehow?\n if (localTimeZone == null) {\n localTimeZone = new Intl.DateTimeFormat().resolvedOptions().timeZone;\n }\n\n return localTimeZone!;\n}\n\n/** Returns the first date of the month for the given date. */\nexport function startOfMonth(date: ZonedDateTime): ZonedDateTime;\nexport function startOfMonth(date: CalendarDateTime): CalendarDateTime;\nexport function startOfMonth(date: CalendarDate): CalendarDate;\nexport function startOfMonth(date: DateValue): DateValue;\nexport function startOfMonth(date: DateValue): DateValue {\n // Use `subtract` instead of `set` so we don't get constrained in an era.\n return date.subtract({days: date.day - 1});\n}\n\n/** Returns the last date of the month for the given date. */\nexport function endOfMonth(date: ZonedDateTime): ZonedDateTime;\nexport function endOfMonth(date: CalendarDateTime): CalendarDateTime;\nexport function endOfMonth(date: CalendarDate): CalendarDate;\nexport function endOfMonth(date: DateValue): DateValue;\nexport function endOfMonth(date: DateValue): DateValue {\n return date.add({days: date.calendar.getDaysInMonth(date) - date.day});\n}\n\n/** Returns the first day of the year for the given date. */\nexport function startOfYear(date: ZonedDateTime): ZonedDateTime;\nexport function startOfYear(date: CalendarDateTime): CalendarDateTime;\nexport function startOfYear(date: CalendarDate): CalendarDate;\nexport function startOfYear(date: DateValue): DateValue;\nexport function startOfYear(date: DateValue): DateValue {\n return startOfMonth(date.subtract({months: date.month - 1}));\n}\n\n/** Returns the last day of the year for the given date. */\nexport function endOfYear(date: ZonedDateTime): ZonedDateTime;\nexport function endOfYear(date: CalendarDateTime): CalendarDateTime;\nexport function endOfYear(date: CalendarDate): CalendarDate;\nexport function endOfYear(date: DateValue): DateValue;\nexport function endOfYear(date: DateValue): DateValue {\n return endOfMonth(date.add({months: date.calendar.getMonthsInYear(date) - date.month}));\n}\n\nexport function getMinimumMonthInYear(date: AnyCalendarDate) {\n if (date.calendar.getMinimumMonthInYear) {\n return date.calendar.getMinimumMonthInYear(date);\n }\n\n return 1;\n}\n\nexport function getMinimumDayInMonth(date: AnyCalendarDate) {\n if (date.calendar.getMinimumDayInMonth) {\n return date.calendar.getMinimumDayInMonth(date);\n }\n\n return 1;\n}\n\n/** Returns the first date of the week for the given date and locale. */\nexport function startOfWeek(date: ZonedDateTime, locale: string): ZonedDateTime;\nexport function startOfWeek(date: CalendarDateTime, locale: string): CalendarDateTime;\nexport function startOfWeek(date: CalendarDate, locale: string): CalendarDate;\nexport function startOfWeek(date: DateValue, locale: string): DateValue;\nexport function startOfWeek(date: DateValue, locale: string): DateValue {\n let dayOfWeek = getDayOfWeek(date, locale);\n return date.subtract({days: dayOfWeek});\n}\n\n/** Returns the last date of the week for the given date and locale. */\nexport function endOfWeek(date: ZonedDateTime, locale: string): ZonedDateTime;\nexport function endOfWeek(date: CalendarDateTime, locale: string): CalendarDateTime;\nexport function endOfWeek(date: CalendarDate, locale: string): CalendarDate;\nexport function endOfWeek(date: DateValue, locale: string): DateValue;\nexport function endOfWeek(date: DateValue, locale: string): DateValue {\n return startOfWeek(date, locale).add({days: 6});\n}\n\nconst cachedRegions = new Map<string, string>();\n\nfunction getRegion(locale: string): string | undefined {\n // If the Intl.Locale API is available, use it to get the region for the locale.\n // @ts-ignore\n if (Intl.Locale) {\n // Constructing an Intl.Locale is expensive, so cache the result.\n let region = cachedRegions.get(locale);\n if (!region) {\n // @ts-ignore\n region = new Intl.Locale(locale).maximize().region;\n if (region) {\n cachedRegions.set(locale, region);\n }\n }\n return region;\n }\n\n // If not, just try splitting the string.\n // If the second part of the locale string is 'u',\n // then this is a unicode extension, so ignore it.\n // Otherwise, it should be the region.\n let part = locale.split('-')[1];\n return part === 'u' ? undefined : part;\n}\n\nfunction getWeekStart(locale: string): number {\n // TODO: use Intl.Locale for this once browsers support the weekInfo property\n // https://github.com/tc39/proposal-intl-locale-info\n let region = getRegion(locale);\n return region ? weekStartData[region] || 0 : 0;\n}\n\n/** Returns the number of weeks in the given month and locale. */\nexport function getWeeksInMonth(date: DateValue, locale: string): number {\n let days = date.calendar.getDaysInMonth(date);\n return Math.ceil((getDayOfWeek(startOfMonth(date), locale) + days) / 7);\n}\n\n/** Returns the lesser of the two provider dates. */\nexport function minDate<A extends DateValue, B extends DateValue>(a?: A | null, b?: B | null): A | B | null | undefined {\n if (a && b) {\n return a.compare(b) <= 0 ? a : b;\n }\n\n return a || b;\n}\n\n/** Returns the greater of the two provider dates. */\nexport function maxDate<A extends DateValue, B extends DateValue>(a?: A | null, b?: B | null): A | B | null | undefined {\n if (a && b) {\n return a.compare(b) >= 0 ? a : b;\n }\n\n return a || b;\n}\n\nconst WEEKEND_DATA = {\n AF: [4, 5],\n AE: [5, 6],\n BH: [5, 6],\n DZ: [5, 6],\n EG: [5, 6],\n IL: [5, 6],\n IQ: [5, 6],\n IR: [5, 5],\n JO: [5, 6],\n KW: [5, 6],\n LY: [5, 6],\n OM: [5, 6],\n QA: [5, 6],\n SA: [5, 6],\n SD: [5, 6],\n SY: [5, 6],\n YE: [5, 6]\n};\n\n/** Returns whether the given date is on a weekend in the given locale. */\nexport function isWeekend(date: DateValue, locale: string): boolean {\n let julian = date.calendar.toJulianDay(date);\n\n // If julian is negative, then julian % 7 will be negative, so we adjust\n // accordingly. Julian day 0 is Monday.\n let dayOfWeek = Math.ceil(julian + 1) % 7;\n if (dayOfWeek < 0) {\n dayOfWeek += 7;\n }\n\n let region = getRegion(locale);\n // Use Intl.Locale for this once weekInfo is supported.\n // https://github.com/tc39/proposal-intl-locale-info\n let [start, end] = WEEKEND_DATA[region!] || [6, 0];\n return dayOfWeek === start || dayOfWeek === end;\n}\n\n/** Returns whether the given date is on a weekday in the given locale. */\nexport function isWeekday(date: DateValue, locale: string): boolean {\n return !isWeekend(date, locale);\n}\n"],"names":[],"version":3,"file":"queries.main.js.map"}
|
|
1
|
+
{"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;;;;;;;;;;CAUC;;AAUM,SAAS,0CAAU,CAAY,EAAE,CAAY;IAClD,IAAI,CAAA,GAAA,oCAAS,EAAE,GAAG,EAAE,QAAQ;IAC5B,OAAO,EAAE,GAAG,KAAK,EAAE,GAAG,IAAI,EAAE,IAAI,KAAK,EAAE,IAAI,IAAI,EAAE,KAAK,KAAK,EAAE,KAAK,IAAI,EAAE,GAAG,KAAK,EAAE,GAAG;AACvF;AAGO,SAAS,0CAAY,CAAY,EAAE,CAAY;IACpD,IAAI,CAAA,GAAA,oCAAS,EAAE,GAAG,EAAE,QAAQ;IAC5B,yGAAyG;IACzG,IAAI,0CAAa;IACjB,IAAI,0CAAa;IACjB,OAAO,EAAE,GAAG,KAAK,EAAE,GAAG,IAAI,EAAE,IAAI,KAAK,EAAE,IAAI,IAAI,EAAE,KAAK,KAAK,EAAE,KAAK;AACpE;AAGO,SAAS,0CAAW,CAAY,EAAE,CAAY;IACnD,IAAI,CAAA,GAAA,oCAAS,EAAE,GAAG,EAAE,QAAQ;IAC5B,IAAI,0CAAY;IAChB,IAAI,0CAAY;IAChB,OAAO,EAAE,GAAG,KAAK,EAAE,GAAG,IAAI,EAAE,IAAI,KAAK,EAAE,IAAI;AAC7C;AAGO,SAAS,0CAAW,CAAY,EAAE,CAAY;IACnD,OAAO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IAAI,CAAC,OAAO,IAAI,GAAG,kCAAY,CAAC,OAAQ,IAAI;QAAC;QAAG;KAAE;IAClD,OAAO,cAAc,SAAS,cAAc;AAC9C;AAGO,SAAS,0CAAU,IAAe,EAAE,MAAc;IACvD,OAAO,CAAC,yCAAU,MAAM;AAC1B","sources":["packages/@internationalized/date/src/queries.ts"],"sourcesContent":["/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport {AnyCalendarDate, AnyTime} from './types';\nimport {CalendarDate, CalendarDateTime, ZonedDateTime} from './CalendarDate';\nimport {fromAbsolute, toAbsolute, toCalendar, toCalendarDate} from './conversion';\nimport {weekStartData} from './weekStartData';\n\ntype DateValue = CalendarDate | CalendarDateTime | ZonedDateTime;\n\n/** Returns whether the given dates occur on the same day, regardless of the time or calendar system. */\nexport function isSameDay(a: DateValue, b: DateValue): boolean {\n b = toCalendar(b, a.calendar);\n return a.era === b.era && a.year === b.year && a.month === b.month && a.day === b.day;\n}\n\n/** Returns whether the given dates occur in the same month, using the calendar system of the first date. */\nexport function isSameMonth(a: DateValue, b: DateValue): boolean {\n b = toCalendar(b, a.calendar);\n // In the Japanese calendar, months can span multiple eras/years, so only compare the first of the month.\n a = startOfMonth(a);\n b = startOfMonth(b);\n return a.era === b.era && a.year === b.year && a.month === b.month;\n}\n\n/** Returns whether the given dates occur in the same year, using the calendar system of the first date. */\nexport function isSameYear(a: DateValue, b: DateValue): boolean {\n b = toCalendar(b, a.calendar);\n a = startOfYear(a);\n b = startOfYear(b);\n return a.era === b.era && a.year === b.year;\n}\n\n/** Returns whether the given dates occur on the same day, and are of the same calendar system. */\nexport function isEqualDay(a: DateValue, b: DateValue): boolean {\n return a.calendar.identifier === b.calendar.identifier && a.era === b.era && a.year === b.year && a.month === b.month && a.day === b.day;\n}\n\n/** Returns whether the given dates occur in the same month, and are of the same calendar system. */\nexport function isEqualMonth(a: DateValue, b: DateValue): boolean {\n a = startOfMonth(a);\n b = startOfMonth(b);\n return a.calendar.identifier === b.calendar.identifier && a.era === b.era && a.year === b.year && a.month === b.month;\n}\n\n/** Returns whether the given dates occur in the same year, and are of the same calendar system. */\nexport function isEqualYear(a: DateValue, b: DateValue): boolean {\n a = startOfYear(a);\n b = startOfYear(b);\n return a.calendar.identifier === b.calendar.identifier && a.era === b.era && a.year === b.year;\n}\n\n/** Returns whether the date is today in the given time zone. */\nexport function isToday(date: DateValue, timeZone: string): boolean {\n return isSameDay(date, today(timeZone));\n}\n\nconst DAY_MAP = {\n sun: 0,\n mon: 1,\n tue: 2,\n wed: 3,\n thu: 4,\n fri: 5,\n sat: 6\n};\n\ntype DayOfWeek = 'sun' | 'mon' | 'tue' | 'wed' | 'thu' | 'fri' | 'sat';\n\n/**\n * Returns the day of week for the given date and locale. Days are numbered from zero to six,\n * where zero is the first day of the week in the given locale. For example, in the United States,\n * the first day of the week is Sunday, but in France it is Monday.\n */\nexport function getDayOfWeek(date: DateValue, locale: string, firstDayOfWeek?: DayOfWeek): number {\n let julian = date.calendar.toJulianDay(date);\n\n // If julian is negative, then julian % 7 will be negative, so we adjust\n // accordingly. Julian day 0 is Monday.\n let weekStart = firstDayOfWeek ? DAY_MAP[firstDayOfWeek] : getWeekStart(locale);\n let dayOfWeek = Math.ceil(julian + 1 - weekStart) % 7;\n if (dayOfWeek < 0) {\n dayOfWeek += 7;\n }\n\n return dayOfWeek;\n}\n\n/** Returns the current time in the given time zone. */\nexport function now(timeZone: string): ZonedDateTime {\n return fromAbsolute(Date.now(), timeZone);\n}\n\n/** Returns today's date in the given time zone. */\nexport function today(timeZone: string): CalendarDate {\n return toCalendarDate(now(timeZone));\n}\n\nexport function compareDate(a: AnyCalendarDate, b: AnyCalendarDate): number {\n return a.calendar.toJulianDay(a) - b.calendar.toJulianDay(b);\n}\n\nexport function compareTime(a: AnyTime, b: AnyTime): number {\n return timeToMs(a) - timeToMs(b);\n}\n\nfunction timeToMs(a: AnyTime): number {\n return a.hour * 60 * 60 * 1000 + a.minute * 60 * 1000 + a.second * 1000 + a.millisecond;\n}\n\n/**\n * Returns the number of hours in the given date and time zone.\n * Usually this is 24, but it could be 23 or 25 if the date is on a daylight saving transition.\n */\nexport function getHoursInDay(a: CalendarDate, timeZone: string): number {\n let ms = toAbsolute(a, timeZone);\n let tomorrow = a.add({days: 1});\n let tomorrowMs = toAbsolute(tomorrow, timeZone);\n return (tomorrowMs - ms) / 3600000;\n}\n\nlet localTimeZone: string | null = null;\n\n/** Returns the time zone identifier for the current user. */\nexport function getLocalTimeZone(): string {\n // TODO: invalidate this somehow?\n if (localTimeZone == null) {\n localTimeZone = new Intl.DateTimeFormat().resolvedOptions().timeZone;\n }\n\n return localTimeZone!;\n}\n\n/** Returns the first date of the month for the given date. */\nexport function startOfMonth(date: ZonedDateTime): ZonedDateTime;\nexport function startOfMonth(date: CalendarDateTime): CalendarDateTime;\nexport function startOfMonth(date: CalendarDate): CalendarDate;\nexport function startOfMonth(date: DateValue): DateValue;\nexport function startOfMonth(date: DateValue): DateValue {\n // Use `subtract` instead of `set` so we don't get constrained in an era.\n return date.subtract({days: date.day - 1});\n}\n\n/** Returns the last date of the month for the given date. */\nexport function endOfMonth(date: ZonedDateTime): ZonedDateTime;\nexport function endOfMonth(date: CalendarDateTime): CalendarDateTime;\nexport function endOfMonth(date: CalendarDate): CalendarDate;\nexport function endOfMonth(date: DateValue): DateValue;\nexport function endOfMonth(date: DateValue): DateValue {\n return date.add({days: date.calendar.getDaysInMonth(date) - date.day});\n}\n\n/** Returns the first day of the year for the given date. */\nexport function startOfYear(date: ZonedDateTime): ZonedDateTime;\nexport function startOfYear(date: CalendarDateTime): CalendarDateTime;\nexport function startOfYear(date: CalendarDate): CalendarDate;\nexport function startOfYear(date: DateValue): DateValue;\nexport function startOfYear(date: DateValue): DateValue {\n return startOfMonth(date.subtract({months: date.month - 1}));\n}\n\n/** Returns the last day of the year for the given date. */\nexport function endOfYear(date: ZonedDateTime): ZonedDateTime;\nexport function endOfYear(date: CalendarDateTime): CalendarDateTime;\nexport function endOfYear(date: CalendarDate): CalendarDate;\nexport function endOfYear(date: DateValue): DateValue;\nexport function endOfYear(date: DateValue): DateValue {\n return endOfMonth(date.add({months: date.calendar.getMonthsInYear(date) - date.month}));\n}\n\nexport function getMinimumMonthInYear(date: AnyCalendarDate) {\n if (date.calendar.getMinimumMonthInYear) {\n return date.calendar.getMinimumMonthInYear(date);\n }\n\n return 1;\n}\n\nexport function getMinimumDayInMonth(date: AnyCalendarDate) {\n if (date.calendar.getMinimumDayInMonth) {\n return date.calendar.getMinimumDayInMonth(date);\n }\n\n return 1;\n}\n\n/** Returns the first date of the week for the given date and locale. */\nexport function startOfWeek(date: ZonedDateTime, locale: string, firstDayOfWeek?: DayOfWeek): ZonedDateTime;\nexport function startOfWeek(date: CalendarDateTime, locale: string, firstDayOfWeek?: DayOfWeek): CalendarDateTime;\nexport function startOfWeek(date: CalendarDate, locale: string, firstDayOfWeek?: DayOfWeek): CalendarDate;\nexport function startOfWeek(date: DateValue, locale: string, firstDayOfWeek?: DayOfWeek): DateValue;\nexport function startOfWeek(date: DateValue, locale: string, firstDayOfWeek?: DayOfWeek): DateValue {\n let dayOfWeek = getDayOfWeek(date, locale, firstDayOfWeek);\n return date.subtract({days: dayOfWeek});\n}\n\n/** Returns the last date of the week for the given date and locale. */\nexport function endOfWeek(date: ZonedDateTime, locale: string, firstDayOfWeek?: DayOfWeek): ZonedDateTime;\nexport function endOfWeek(date: CalendarDateTime, locale: string, firstDayOfWeek?: DayOfWeek): CalendarDateTime;\nexport function endOfWeek(date: CalendarDate, locale: string, firstDayOfWeek?: DayOfWeek): CalendarDate;\nexport function endOfWeek(date: DateValue, locale: string, firstDayOfWeek?: DayOfWeek): DateValue;\nexport function endOfWeek(date: DateValue, locale: string, firstDayOfWeek?: DayOfWeek): DateValue {\n return startOfWeek(date, locale, firstDayOfWeek).add({days: 6});\n}\n\nconst cachedRegions = new Map<string, string>();\n\nfunction getRegion(locale: string): string | undefined {\n // If the Intl.Locale API is available, use it to get the region for the locale.\n // @ts-ignore\n if (Intl.Locale) {\n // Constructing an Intl.Locale is expensive, so cache the result.\n let region = cachedRegions.get(locale);\n if (!region) {\n // @ts-ignore\n region = new Intl.Locale(locale).maximize().region;\n if (region) {\n cachedRegions.set(locale, region);\n }\n }\n return region;\n }\n\n // If not, just try splitting the string.\n // If the second part of the locale string is 'u',\n // then this is a unicode extension, so ignore it.\n // Otherwise, it should be the region.\n let part = locale.split('-')[1];\n return part === 'u' ? undefined : part;\n}\n\nfunction getWeekStart(locale: string): number {\n // TODO: use Intl.Locale for this once browsers support the weekInfo property\n // https://github.com/tc39/proposal-intl-locale-info\n let region = getRegion(locale);\n return region ? weekStartData[region] || 0 : 0;\n}\n\n/** Returns the number of weeks in the given month and locale. */\nexport function getWeeksInMonth(date: DateValue, locale: string, firstDayOfWeek?: DayOfWeek): number {\n let days = date.calendar.getDaysInMonth(date);\n return Math.ceil((getDayOfWeek(startOfMonth(date), locale, firstDayOfWeek) + days) / 7);\n}\n\n/** Returns the lesser of the two provider dates. */\nexport function minDate<A extends DateValue, B extends DateValue>(a?: A | null, b?: B | null): A | B | null | undefined {\n if (a && b) {\n return a.compare(b) <= 0 ? a : b;\n }\n\n return a || b;\n}\n\n/** Returns the greater of the two provider dates. */\nexport function maxDate<A extends DateValue, B extends DateValue>(a?: A | null, b?: B | null): A | B | null | undefined {\n if (a && b) {\n return a.compare(b) >= 0 ? a : b;\n }\n\n return a || b;\n}\n\nconst WEEKEND_DATA = {\n AF: [4, 5],\n AE: [5, 6],\n BH: [5, 6],\n DZ: [5, 6],\n EG: [5, 6],\n IL: [5, 6],\n IQ: [5, 6],\n IR: [5, 5],\n JO: [5, 6],\n KW: [5, 6],\n LY: [5, 6],\n OM: [5, 6],\n QA: [5, 6],\n SA: [5, 6],\n SD: [5, 6],\n SY: [5, 6],\n YE: [5, 6]\n};\n\n/** Returns whether the given date is on a weekend in the given locale. */\nexport function isWeekend(date: DateValue, locale: string): boolean {\n let julian = date.calendar.toJulianDay(date);\n\n // If julian is negative, then julian % 7 will be negative, so we adjust\n // accordingly. Julian day 0 is Monday.\n let dayOfWeek = Math.ceil(julian + 1) % 7;\n if (dayOfWeek < 0) {\n dayOfWeek += 7;\n }\n\n let region = getRegion(locale);\n // Use Intl.Locale for this once weekInfo is supported.\n // https://github.com/tc39/proposal-intl-locale-info\n let [start, end] = WEEKEND_DATA[region!] || [6, 0];\n return dayOfWeek === start || dayOfWeek === end;\n}\n\n/** Returns whether the given date is on a weekday in the given locale. */\nexport function isWeekday(date: DateValue, locale: string): boolean {\n return !isWeekend(date, locale);\n}\n"],"names":[],"version":3,"file":"queries.main.js.map"}
|
package/dist/queries.mjs
CHANGED
|
@@ -46,11 +46,21 @@ function $14e0f24ef4ac5c92$export$ea840f5a6dda8147(a, b) {
|
|
|
46
46
|
function $14e0f24ef4ac5c92$export$629b0a497aa65267(date, timeZone) {
|
|
47
47
|
return $14e0f24ef4ac5c92$export$ea39ec197993aef0(date, $14e0f24ef4ac5c92$export$d0bdf45af03a6ea3(timeZone));
|
|
48
48
|
}
|
|
49
|
-
|
|
49
|
+
const $14e0f24ef4ac5c92$var$DAY_MAP = {
|
|
50
|
+
sun: 0,
|
|
51
|
+
mon: 1,
|
|
52
|
+
tue: 2,
|
|
53
|
+
wed: 3,
|
|
54
|
+
thu: 4,
|
|
55
|
+
fri: 5,
|
|
56
|
+
sat: 6
|
|
57
|
+
};
|
|
58
|
+
function $14e0f24ef4ac5c92$export$2061056d06d7cdf7(date, locale, firstDayOfWeek) {
|
|
50
59
|
let julian = date.calendar.toJulianDay(date);
|
|
51
60
|
// If julian is negative, then julian % 7 will be negative, so we adjust
|
|
52
61
|
// accordingly. Julian day 0 is Monday.
|
|
53
|
-
let
|
|
62
|
+
let weekStart = firstDayOfWeek ? $14e0f24ef4ac5c92$var$DAY_MAP[firstDayOfWeek] : $14e0f24ef4ac5c92$var$getWeekStart(locale);
|
|
63
|
+
let dayOfWeek = Math.ceil(julian + 1 - weekStart) % 7;
|
|
54
64
|
if (dayOfWeek < 0) dayOfWeek += 7;
|
|
55
65
|
return dayOfWeek;
|
|
56
66
|
}
|
|
@@ -112,14 +122,14 @@ function $14e0f24ef4ac5c92$export$b2f4953d301981d5(date) {
|
|
|
112
122
|
if (date.calendar.getMinimumDayInMonth) return date.calendar.getMinimumDayInMonth(date);
|
|
113
123
|
return 1;
|
|
114
124
|
}
|
|
115
|
-
function $14e0f24ef4ac5c92$export$42c81a444fbfb5d4(date, locale) {
|
|
116
|
-
let dayOfWeek = $14e0f24ef4ac5c92$export$2061056d06d7cdf7(date, locale);
|
|
125
|
+
function $14e0f24ef4ac5c92$export$42c81a444fbfb5d4(date, locale, firstDayOfWeek) {
|
|
126
|
+
let dayOfWeek = $14e0f24ef4ac5c92$export$2061056d06d7cdf7(date, locale, firstDayOfWeek);
|
|
117
127
|
return date.subtract({
|
|
118
128
|
days: dayOfWeek
|
|
119
129
|
});
|
|
120
130
|
}
|
|
121
|
-
function $14e0f24ef4ac5c92$export$ef8b6d9133084f4e(date, locale) {
|
|
122
|
-
return $14e0f24ef4ac5c92$export$42c81a444fbfb5d4(date, locale).add({
|
|
131
|
+
function $14e0f24ef4ac5c92$export$ef8b6d9133084f4e(date, locale, firstDayOfWeek) {
|
|
132
|
+
return $14e0f24ef4ac5c92$export$42c81a444fbfb5d4(date, locale, firstDayOfWeek).add({
|
|
123
133
|
days: 6
|
|
124
134
|
});
|
|
125
135
|
}
|
|
@@ -150,9 +160,9 @@ function $14e0f24ef4ac5c92$var$getWeekStart(locale) {
|
|
|
150
160
|
let region = $14e0f24ef4ac5c92$var$getRegion(locale);
|
|
151
161
|
return region ? (0, $2fe286d2fb449abb$export$7a5acbd77d414bd9)[region] || 0 : 0;
|
|
152
162
|
}
|
|
153
|
-
function $14e0f24ef4ac5c92$export$ccc1b2479e7dd654(date, locale) {
|
|
163
|
+
function $14e0f24ef4ac5c92$export$ccc1b2479e7dd654(date, locale, firstDayOfWeek) {
|
|
154
164
|
let days = date.calendar.getDaysInMonth(date);
|
|
155
|
-
return Math.ceil(($14e0f24ef4ac5c92$export$2061056d06d7cdf7($14e0f24ef4ac5c92$export$a5a3b454ada2268e(date), locale) + days) / 7);
|
|
165
|
+
return Math.ceil(($14e0f24ef4ac5c92$export$2061056d06d7cdf7($14e0f24ef4ac5c92$export$a5a3b454ada2268e(date), locale, firstDayOfWeek) + days) / 7);
|
|
156
166
|
}
|
|
157
167
|
function $14e0f24ef4ac5c92$export$5c333a116e949cdd(a, b) {
|
|
158
168
|
if (a && b) return a.compare(b) <= 0 ? a : b;
|
package/dist/queries.module.js
CHANGED
|
@@ -46,11 +46,21 @@ function $14e0f24ef4ac5c92$export$ea840f5a6dda8147(a, b) {
|
|
|
46
46
|
function $14e0f24ef4ac5c92$export$629b0a497aa65267(date, timeZone) {
|
|
47
47
|
return $14e0f24ef4ac5c92$export$ea39ec197993aef0(date, $14e0f24ef4ac5c92$export$d0bdf45af03a6ea3(timeZone));
|
|
48
48
|
}
|
|
49
|
-
|
|
49
|
+
const $14e0f24ef4ac5c92$var$DAY_MAP = {
|
|
50
|
+
sun: 0,
|
|
51
|
+
mon: 1,
|
|
52
|
+
tue: 2,
|
|
53
|
+
wed: 3,
|
|
54
|
+
thu: 4,
|
|
55
|
+
fri: 5,
|
|
56
|
+
sat: 6
|
|
57
|
+
};
|
|
58
|
+
function $14e0f24ef4ac5c92$export$2061056d06d7cdf7(date, locale, firstDayOfWeek) {
|
|
50
59
|
let julian = date.calendar.toJulianDay(date);
|
|
51
60
|
// If julian is negative, then julian % 7 will be negative, so we adjust
|
|
52
61
|
// accordingly. Julian day 0 is Monday.
|
|
53
|
-
let
|
|
62
|
+
let weekStart = firstDayOfWeek ? $14e0f24ef4ac5c92$var$DAY_MAP[firstDayOfWeek] : $14e0f24ef4ac5c92$var$getWeekStart(locale);
|
|
63
|
+
let dayOfWeek = Math.ceil(julian + 1 - weekStart) % 7;
|
|
54
64
|
if (dayOfWeek < 0) dayOfWeek += 7;
|
|
55
65
|
return dayOfWeek;
|
|
56
66
|
}
|
|
@@ -112,14 +122,14 @@ function $14e0f24ef4ac5c92$export$b2f4953d301981d5(date) {
|
|
|
112
122
|
if (date.calendar.getMinimumDayInMonth) return date.calendar.getMinimumDayInMonth(date);
|
|
113
123
|
return 1;
|
|
114
124
|
}
|
|
115
|
-
function $14e0f24ef4ac5c92$export$42c81a444fbfb5d4(date, locale) {
|
|
116
|
-
let dayOfWeek = $14e0f24ef4ac5c92$export$2061056d06d7cdf7(date, locale);
|
|
125
|
+
function $14e0f24ef4ac5c92$export$42c81a444fbfb5d4(date, locale, firstDayOfWeek) {
|
|
126
|
+
let dayOfWeek = $14e0f24ef4ac5c92$export$2061056d06d7cdf7(date, locale, firstDayOfWeek);
|
|
117
127
|
return date.subtract({
|
|
118
128
|
days: dayOfWeek
|
|
119
129
|
});
|
|
120
130
|
}
|
|
121
|
-
function $14e0f24ef4ac5c92$export$ef8b6d9133084f4e(date, locale) {
|
|
122
|
-
return $14e0f24ef4ac5c92$export$42c81a444fbfb5d4(date, locale).add({
|
|
131
|
+
function $14e0f24ef4ac5c92$export$ef8b6d9133084f4e(date, locale, firstDayOfWeek) {
|
|
132
|
+
return $14e0f24ef4ac5c92$export$42c81a444fbfb5d4(date, locale, firstDayOfWeek).add({
|
|
123
133
|
days: 6
|
|
124
134
|
});
|
|
125
135
|
}
|
|
@@ -150,9 +160,9 @@ function $14e0f24ef4ac5c92$var$getWeekStart(locale) {
|
|
|
150
160
|
let region = $14e0f24ef4ac5c92$var$getRegion(locale);
|
|
151
161
|
return region ? (0, $2fe286d2fb449abb$export$7a5acbd77d414bd9)[region] || 0 : 0;
|
|
152
162
|
}
|
|
153
|
-
function $14e0f24ef4ac5c92$export$ccc1b2479e7dd654(date, locale) {
|
|
163
|
+
function $14e0f24ef4ac5c92$export$ccc1b2479e7dd654(date, locale, firstDayOfWeek) {
|
|
154
164
|
let days = date.calendar.getDaysInMonth(date);
|
|
155
|
-
return Math.ceil(($14e0f24ef4ac5c92$export$2061056d06d7cdf7($14e0f24ef4ac5c92$export$a5a3b454ada2268e(date), locale) + days) / 7);
|
|
165
|
+
return Math.ceil(($14e0f24ef4ac5c92$export$2061056d06d7cdf7($14e0f24ef4ac5c92$export$a5a3b454ada2268e(date), locale, firstDayOfWeek) + days) / 7);
|
|
156
166
|
}
|
|
157
167
|
function $14e0f24ef4ac5c92$export$5c333a116e949cdd(a, b) {
|
|
158
168
|
if (a && b) return a.compare(b) <= 0 ? a : b;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"mappings":";;;AAAA;;;;;;;;;;CAUC;;AAUM,SAAS,0CAAU,CAAY,EAAE,CAAY;IAClD,IAAI,CAAA,GAAA,yCAAS,EAAE,GAAG,EAAE,QAAQ;IAC5B,OAAO,EAAE,GAAG,KAAK,EAAE,GAAG,IAAI,EAAE,IAAI,KAAK,EAAE,IAAI,IAAI,EAAE,KAAK,KAAK,EAAE,KAAK,IAAI,EAAE,GAAG,KAAK,EAAE,GAAG;AACvF;AAGO,SAAS,0CAAY,CAAY,EAAE,CAAY;IACpD,IAAI,CAAA,GAAA,yCAAS,EAAE,GAAG,EAAE,QAAQ;IAC5B,yGAAyG;IACzG,IAAI,0CAAa;IACjB,IAAI,0CAAa;IACjB,OAAO,EAAE,GAAG,KAAK,EAAE,GAAG,IAAI,EAAE,IAAI,KAAK,EAAE,IAAI,IAAI,EAAE,KAAK,KAAK,EAAE,KAAK;AACpE;AAGO,SAAS,0CAAW,CAAY,EAAE,CAAY;IACnD,IAAI,CAAA,GAAA,yCAAS,EAAE,GAAG,EAAE,QAAQ;IAC5B,IAAI,0C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KAAE;IAClD,OAAO,cAAc,SAAS,cAAc;AAC9C;AAGO,SAAS,0CAAU,IAAe,EAAE,MAAc;IACvD,OAAO,CAAC,yCAAU,MAAM;AAC1B","sources":["packages/@internationalized/date/src/queries.ts"],"sourcesContent":["/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport {AnyCalendarDate, AnyTime} from './types';\nimport {CalendarDate, CalendarDateTime, ZonedDateTime} from './CalendarDate';\nimport {fromAbsolute, toAbsolute, toCalendar, toCalendarDate} from './conversion';\nimport {weekStartData} from './weekStartData';\n\ntype DateValue = CalendarDate | CalendarDateTime | ZonedDateTime;\n\n/** Returns whether the given dates occur on the same day, regardless of the time or calendar system. */\nexport function isSameDay(a: DateValue, b: DateValue): boolean {\n b = toCalendar(b, a.calendar);\n return a.era === b.era && a.year === b.year && a.month === b.month && a.day === b.day;\n}\n\n/** Returns whether the given dates occur in the same month, using the calendar system of the first date. */\nexport function isSameMonth(a: DateValue, b: DateValue): boolean {\n b = toCalendar(b, a.calendar);\n // In the Japanese calendar, months can span multiple eras/years, so only compare the first of the month.\n a = startOfMonth(a);\n b = startOfMonth(b);\n return a.era === b.era && a.year === b.year && a.month === b.month;\n}\n\n/** Returns whether the given dates occur in the same year, using the calendar system of the first date. */\nexport function isSameYear(a: DateValue, b: DateValue): boolean {\n b = toCalendar(b, a.calendar);\n a = startOfYear(a);\n b = startOfYear(b);\n return a.era === b.era && a.year === b.year;\n}\n\n/** Returns whether the given dates occur on the same day, and are of the same calendar system. */\nexport function isEqualDay(a: DateValue, b: DateValue): boolean {\n return a.calendar.identifier === b.calendar.identifier && a.era === b.era && a.year === b.year && a.month === b.month && a.day === b.day;\n}\n\n/** Returns whether the given dates occur in the same month, and are of the same calendar system. */\nexport function isEqualMonth(a: DateValue, b: DateValue): boolean {\n a = startOfMonth(a);\n b = startOfMonth(b);\n return a.calendar.identifier === b.calendar.identifier && a.era === b.era && a.year === b.year && a.month === b.month;\n}\n\n/** Returns whether the given dates occur in the same year, and are of the same calendar system. */\nexport function isEqualYear(a: DateValue, b: DateValue): boolean {\n a = startOfYear(a);\n b = startOfYear(b);\n return a.calendar.identifier === b.calendar.identifier && a.era === b.era && a.year === b.year;\n}\n\n/** Returns whether the date is today in the given time zone. */\nexport function isToday(date: DateValue, timeZone: string): boolean {\n return isSameDay(date, today(timeZone));\n}\n\n/**\n * Returns the day of week for the given date and locale. Days are numbered from zero to six,\n * where zero is the first day of the week in the given locale. For example, in the United States,\n * the first day of the week is Sunday, but in France it is Monday.\n */\nexport function getDayOfWeek(date: DateValue, locale: string): number {\n let julian = date.calendar.toJulianDay(date);\n\n // If julian is negative, then julian % 7 will be negative, so we adjust\n // accordingly. Julian day 0 is Monday.\n let dayOfWeek = Math.ceil(julian + 1 - getWeekStart(locale)) % 7;\n if (dayOfWeek < 0) {\n dayOfWeek += 7;\n }\n\n return dayOfWeek;\n}\n\n/** Returns the current time in the given time zone. */\nexport function now(timeZone: string): ZonedDateTime {\n return fromAbsolute(Date.now(), timeZone);\n}\n\n/** Returns today's date in the given time zone. */\nexport function today(timeZone: string): CalendarDate {\n return toCalendarDate(now(timeZone));\n}\n\nexport function compareDate(a: AnyCalendarDate, b: AnyCalendarDate): number {\n return a.calendar.toJulianDay(a) - b.calendar.toJulianDay(b);\n}\n\nexport function compareTime(a: AnyTime, b: AnyTime): number {\n return timeToMs(a) - timeToMs(b);\n}\n\nfunction timeToMs(a: AnyTime): number {\n return a.hour * 60 * 60 * 1000 + a.minute * 60 * 1000 + a.second * 1000 + a.millisecond;\n}\n\n/**\n * Returns the number of hours in the given date and time zone.\n * Usually this is 24, but it could be 23 or 25 if the date is on a daylight saving transition.\n */\nexport function getHoursInDay(a: CalendarDate, timeZone: string): number {\n let ms = toAbsolute(a, timeZone);\n let tomorrow = a.add({days: 1});\n let tomorrowMs = toAbsolute(tomorrow, timeZone);\n return (tomorrowMs - ms) / 3600000;\n}\n\nlet localTimeZone: string | null = null;\n\n/** Returns the time zone identifier for the current user. */\nexport function getLocalTimeZone(): string {\n // TODO: invalidate this somehow?\n if (localTimeZone == null) {\n localTimeZone = new Intl.DateTimeFormat().resolvedOptions().timeZone;\n }\n\n return localTimeZone!;\n}\n\n/** Returns the first date of the month for the given date. */\nexport function startOfMonth(date: ZonedDateTime): ZonedDateTime;\nexport function startOfMonth(date: CalendarDateTime): CalendarDateTime;\nexport function startOfMonth(date: CalendarDate): CalendarDate;\nexport function startOfMonth(date: DateValue): DateValue;\nexport function startOfMonth(date: DateValue): DateValue {\n // Use `subtract` instead of `set` so we don't get constrained in an era.\n return date.subtract({days: date.day - 1});\n}\n\n/** Returns the last date of the month for the given date. */\nexport function endOfMonth(date: ZonedDateTime): ZonedDateTime;\nexport function endOfMonth(date: CalendarDateTime): CalendarDateTime;\nexport function endOfMonth(date: CalendarDate): CalendarDate;\nexport function endOfMonth(date: DateValue): DateValue;\nexport function endOfMonth(date: DateValue): DateValue {\n return date.add({days: date.calendar.getDaysInMonth(date) - date.day});\n}\n\n/** Returns the first day of the year for the given date. */\nexport function startOfYear(date: ZonedDateTime): ZonedDateTime;\nexport function startOfYear(date: CalendarDateTime): CalendarDateTime;\nexport function startOfYear(date: CalendarDate): CalendarDate;\nexport function startOfYear(date: DateValue): DateValue;\nexport function startOfYear(date: DateValue): DateValue {\n return startOfMonth(date.subtract({months: date.month - 1}));\n}\n\n/** Returns the last day of the year for the given date. */\nexport function endOfYear(date: ZonedDateTime): ZonedDateTime;\nexport function endOfYear(date: CalendarDateTime): CalendarDateTime;\nexport function endOfYear(date: CalendarDate): CalendarDate;\nexport function endOfYear(date: DateValue): DateValue;\nexport function endOfYear(date: DateValue): DateValue {\n return endOfMonth(date.add({months: date.calendar.getMonthsInYear(date) - date.month}));\n}\n\nexport function getMinimumMonthInYear(date: AnyCalendarDate) {\n if (date.calendar.getMinimumMonthInYear) {\n return date.calendar.getMinimumMonthInYear(date);\n }\n\n return 1;\n}\n\nexport function getMinimumDayInMonth(date: AnyCalendarDate) {\n if (date.calendar.getMinimumDayInMonth) {\n return date.calendar.getMinimumDayInMonth(date);\n }\n\n return 1;\n}\n\n/** Returns the first date of the week for the given date and locale. */\nexport function startOfWeek(date: ZonedDateTime, locale: string): ZonedDateTime;\nexport function startOfWeek(date: CalendarDateTime, locale: string): CalendarDateTime;\nexport function startOfWeek(date: CalendarDate, locale: string): CalendarDate;\nexport function startOfWeek(date: DateValue, locale: string): DateValue;\nexport function startOfWeek(date: DateValue, locale: string): DateValue {\n let dayOfWeek = getDayOfWeek(date, locale);\n return date.subtract({days: dayOfWeek});\n}\n\n/** Returns the last date of the week for the given date and locale. */\nexport function endOfWeek(date: ZonedDateTime, locale: string): ZonedDateTime;\nexport function endOfWeek(date: CalendarDateTime, locale: string): CalendarDateTime;\nexport function endOfWeek(date: CalendarDate, locale: string): CalendarDate;\nexport function endOfWeek(date: DateValue, locale: string): DateValue;\nexport function endOfWeek(date: DateValue, locale: string): DateValue {\n return startOfWeek(date, locale).add({days: 6});\n}\n\nconst cachedRegions = new Map<string, string>();\n\nfunction getRegion(locale: string): string | undefined {\n // If the Intl.Locale API is available, use it to get the region for the locale.\n // @ts-ignore\n if (Intl.Locale) {\n // Constructing an Intl.Locale is expensive, so cache the result.\n let region = cachedRegions.get(locale);\n if (!region) {\n // @ts-ignore\n region = new Intl.Locale(locale).maximize().region;\n if (region) {\n cachedRegions.set(locale, region);\n }\n }\n return region;\n }\n\n // If not, just try splitting the string.\n // If the second part of the locale string is 'u',\n // then this is a unicode extension, so ignore it.\n // Otherwise, it should be the region.\n let part = locale.split('-')[1];\n return part === 'u' ? undefined : part;\n}\n\nfunction getWeekStart(locale: string): number {\n // TODO: use Intl.Locale for this once browsers support the weekInfo property\n // https://github.com/tc39/proposal-intl-locale-info\n let region = getRegion(locale);\n return region ? weekStartData[region] || 0 : 0;\n}\n\n/** Returns the number of weeks in the given month and locale. */\nexport function getWeeksInMonth(date: DateValue, locale: string): number {\n let days = date.calendar.getDaysInMonth(date);\n return Math.ceil((getDayOfWeek(startOfMonth(date), locale) + days) / 7);\n}\n\n/** Returns the lesser of the two provider dates. */\nexport function minDate<A extends DateValue, B extends DateValue>(a?: A | null, b?: B | null): A | B | null | undefined {\n if (a && b) {\n return a.compare(b) <= 0 ? a : b;\n }\n\n return a || b;\n}\n\n/** Returns the greater of the two provider dates. */\nexport function maxDate<A extends DateValue, B extends DateValue>(a?: A | null, b?: B | null): A | B | null | undefined {\n if (a && b) {\n return a.compare(b) >= 0 ? a : b;\n }\n\n return a || b;\n}\n\nconst WEEKEND_DATA = {\n AF: [4, 5],\n AE: [5, 6],\n BH: [5, 6],\n DZ: [5, 6],\n EG: [5, 6],\n IL: [5, 6],\n IQ: [5, 6],\n IR: [5, 5],\n JO: [5, 6],\n KW: [5, 6],\n LY: [5, 6],\n OM: [5, 6],\n QA: [5, 6],\n SA: [5, 6],\n SD: [5, 6],\n SY: [5, 6],\n YE: [5, 6]\n};\n\n/** Returns whether the given date is on a weekend in the given locale. */\nexport function isWeekend(date: DateValue, locale: string): boolean {\n let julian = date.calendar.toJulianDay(date);\n\n // If julian is negative, then julian % 7 will be negative, so we adjust\n // accordingly. Julian day 0 is Monday.\n let dayOfWeek = Math.ceil(julian + 1) % 7;\n if (dayOfWeek < 0) {\n dayOfWeek += 7;\n }\n\n let region = getRegion(locale);\n // Use Intl.Locale for this once weekInfo is supported.\n // https://github.com/tc39/proposal-intl-locale-info\n let [start, end] = WEEKEND_DATA[region!] || [6, 0];\n return dayOfWeek === start || dayOfWeek === end;\n}\n\n/** Returns whether the given date is on a weekday in the given locale. */\nexport function isWeekday(date: DateValue, locale: string): boolean {\n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0CAAkD,CAAY,EAAE,CAAY;IAC1F,IAAI,KAAK,GACP,OAAO,EAAE,OAAO,CAAC,MAAM,IAAI,IAAI;IAGjC,OAAO,KAAK;AACd;AAEA,MAAM,qCAAe;IACnB,IAAI;QAAC;QAAG;KAAE;IACV,IAAI;QAAC;QAAG;KAAE;IACV,IAAI;QAAC;QAAG;KAAE;IACV,IAAI;QAAC;QAAG;KAAE;IACV,IAAI;QAAC;QAAG;KAAE;IACV,IAAI;QAAC;QAAG;KAAE;IACV,IAAI;QAAC;QAAG;KAAE;IACV,IAAI;QAAC;QAAG;KAAE;IACV,IAAI;QAAC;QAAG;KAAE;IACV,IAAI;QAAC;QAAG;KAAE;IACV,IAAI;QAAC;QAAG;KAAE;IACV,IAAI;QAAC;QAAG;KAAE;IACV,IAAI;QAAC;QAAG;KAAE;IACV,IAAI;QAAC;QAAG;KAAE;IACV,IAAI;QAAC;QAAG;KAAE;IACV,IAAI;QAAC;QAAG;KAAE;IACV,IAAI;QAAC;QAAG;KAAE;AACZ;AAGO,SAAS,yCAAU,IAAe,EAAE,MAAc;IACvD,IAAI,SAAS,KAAK,QAAQ,CAAC,WAAW,CAAC;IAEvC,wEAAwE;IACxE,wCAAwC;IACxC,IAAI,YAAY,KAAK,IAAI,CAAC,SAAS,KAAK;IACxC,IAAI,YAAY,GACd,aAAa;IAGf,IAAI,SAAS,gCAAU;IACvB,uDAAuD;IACvD,oDAAoD;IACpD,IAAI,CAAC,OAAO,IAAI,GAAG,kCAAY,CAAC,OAAQ,IAAI;QAAC;QAAG;KAAE;IAClD,OAAO,cAAc,SAAS,cAAc;AAC9C;AAGO,SAAS,0CAAU,IAAe,EAAE,MAAc;IACvD,OAAO,CAAC,yCAAU,MAAM;AAC1B","sources":["packages/@internationalized/date/src/queries.ts"],"sourcesContent":["/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport {AnyCalendarDate, AnyTime} from './types';\nimport {CalendarDate, CalendarDateTime, ZonedDateTime} from './CalendarDate';\nimport {fromAbsolute, toAbsolute, toCalendar, toCalendarDate} from './conversion';\nimport {weekStartData} from './weekStartData';\n\ntype DateValue = CalendarDate | CalendarDateTime | ZonedDateTime;\n\n/** Returns whether the given dates occur on the same day, regardless of the time or calendar system. */\nexport function isSameDay(a: DateValue, b: DateValue): boolean {\n b = toCalendar(b, a.calendar);\n return a.era === b.era && a.year === b.year && a.month === b.month && a.day === b.day;\n}\n\n/** Returns whether the given dates occur in the same month, using the calendar system of the first date. */\nexport function isSameMonth(a: DateValue, b: DateValue): boolean {\n b = toCalendar(b, a.calendar);\n // In the Japanese calendar, months can span multiple eras/years, so only compare the first of the month.\n a = startOfMonth(a);\n b = startOfMonth(b);\n return a.era === b.era && a.year === b.year && a.month === b.month;\n}\n\n/** Returns whether the given dates occur in the same year, using the calendar system of the first date. */\nexport function isSameYear(a: DateValue, b: DateValue): boolean {\n b = toCalendar(b, a.calendar);\n a = startOfYear(a);\n b = startOfYear(b);\n return a.era === b.era && a.year === b.year;\n}\n\n/** Returns whether the given dates occur on the same day, and are of the same calendar system. */\nexport function isEqualDay(a: DateValue, b: DateValue): boolean {\n return a.calendar.identifier === b.calendar.identifier && a.era === b.era && a.year === b.year && a.month === b.month && a.day === b.day;\n}\n\n/** Returns whether the given dates occur in the same month, and are of the same calendar system. */\nexport function isEqualMonth(a: DateValue, b: DateValue): boolean {\n a = startOfMonth(a);\n b = startOfMonth(b);\n return a.calendar.identifier === b.calendar.identifier && a.era === b.era && a.year === b.year && a.month === b.month;\n}\n\n/** Returns whether the given dates occur in the same year, and are of the same calendar system. */\nexport function isEqualYear(a: DateValue, b: DateValue): boolean {\n a = startOfYear(a);\n b = startOfYear(b);\n return a.calendar.identifier === b.calendar.identifier && a.era === b.era && a.year === b.year;\n}\n\n/** Returns whether the date is today in the given time zone. */\nexport function isToday(date: DateValue, timeZone: string): boolean {\n return isSameDay(date, today(timeZone));\n}\n\nconst DAY_MAP = {\n sun: 0,\n mon: 1,\n tue: 2,\n wed: 3,\n thu: 4,\n fri: 5,\n sat: 6\n};\n\ntype DayOfWeek = 'sun' | 'mon' | 'tue' | 'wed' | 'thu' | 'fri' | 'sat';\n\n/**\n * Returns the day of week for the given date and locale. Days are numbered from zero to six,\n * where zero is the first day of the week in the given locale. For example, in the United States,\n * the first day of the week is Sunday, but in France it is Monday.\n */\nexport function getDayOfWeek(date: DateValue, locale: string, firstDayOfWeek?: DayOfWeek): number {\n let julian = date.calendar.toJulianDay(date);\n\n // If julian is negative, then julian % 7 will be negative, so we adjust\n // accordingly. Julian day 0 is Monday.\n let weekStart = firstDayOfWeek ? DAY_MAP[firstDayOfWeek] : getWeekStart(locale);\n let dayOfWeek = Math.ceil(julian + 1 - weekStart) % 7;\n if (dayOfWeek < 0) {\n dayOfWeek += 7;\n }\n\n return dayOfWeek;\n}\n\n/** Returns the current time in the given time zone. */\nexport function now(timeZone: string): ZonedDateTime {\n return fromAbsolute(Date.now(), timeZone);\n}\n\n/** Returns today's date in the given time zone. */\nexport function today(timeZone: string): CalendarDate {\n return toCalendarDate(now(timeZone));\n}\n\nexport function compareDate(a: AnyCalendarDate, b: AnyCalendarDate): number {\n return a.calendar.toJulianDay(a) - b.calendar.toJulianDay(b);\n}\n\nexport function compareTime(a: AnyTime, b: AnyTime): number {\n return timeToMs(a) - timeToMs(b);\n}\n\nfunction timeToMs(a: AnyTime): number {\n return a.hour * 60 * 60 * 1000 + a.minute * 60 * 1000 + a.second * 1000 + a.millisecond;\n}\n\n/**\n * Returns the number of hours in the given date and time zone.\n * Usually this is 24, but it could be 23 or 25 if the date is on a daylight saving transition.\n */\nexport function getHoursInDay(a: CalendarDate, timeZone: string): number {\n let ms = toAbsolute(a, timeZone);\n let tomorrow = a.add({days: 1});\n let tomorrowMs = toAbsolute(tomorrow, timeZone);\n return (tomorrowMs - ms) / 3600000;\n}\n\nlet localTimeZone: string | null = null;\n\n/** Returns the time zone identifier for the current user. */\nexport function getLocalTimeZone(): string {\n // TODO: invalidate this somehow?\n if (localTimeZone == null) {\n localTimeZone = new Intl.DateTimeFormat().resolvedOptions().timeZone;\n }\n\n return localTimeZone!;\n}\n\n/** Returns the first date of the month for the given date. */\nexport function startOfMonth(date: ZonedDateTime): ZonedDateTime;\nexport function startOfMonth(date: CalendarDateTime): CalendarDateTime;\nexport function startOfMonth(date: CalendarDate): CalendarDate;\nexport function startOfMonth(date: DateValue): DateValue;\nexport function startOfMonth(date: DateValue): DateValue {\n // Use `subtract` instead of `set` so we don't get constrained in an era.\n return date.subtract({days: date.day - 1});\n}\n\n/** Returns the last date of the month for the given date. */\nexport function endOfMonth(date: ZonedDateTime): ZonedDateTime;\nexport function endOfMonth(date: CalendarDateTime): CalendarDateTime;\nexport function endOfMonth(date: CalendarDate): CalendarDate;\nexport function endOfMonth(date: DateValue): DateValue;\nexport function endOfMonth(date: DateValue): DateValue {\n return date.add({days: date.calendar.getDaysInMonth(date) - date.day});\n}\n\n/** Returns the first day of the year for the given date. */\nexport function startOfYear(date: ZonedDateTime): ZonedDateTime;\nexport function startOfYear(date: CalendarDateTime): CalendarDateTime;\nexport function startOfYear(date: CalendarDate): CalendarDate;\nexport function startOfYear(date: DateValue): DateValue;\nexport function startOfYear(date: DateValue): DateValue {\n return startOfMonth(date.subtract({months: date.month - 1}));\n}\n\n/** Returns the last day of the year for the given date. */\nexport function endOfYear(date: ZonedDateTime): ZonedDateTime;\nexport function endOfYear(date: CalendarDateTime): CalendarDateTime;\nexport function endOfYear(date: CalendarDate): CalendarDate;\nexport function endOfYear(date: DateValue): DateValue;\nexport function endOfYear(date: DateValue): DateValue {\n return endOfMonth(date.add({months: date.calendar.getMonthsInYear(date) - date.month}));\n}\n\nexport function getMinimumMonthInYear(date: AnyCalendarDate) {\n if (date.calendar.getMinimumMonthInYear) {\n return date.calendar.getMinimumMonthInYear(date);\n }\n\n return 1;\n}\n\nexport function getMinimumDayInMonth(date: AnyCalendarDate) {\n if (date.calendar.getMinimumDayInMonth) {\n return date.calendar.getMinimumDayInMonth(date);\n }\n\n return 1;\n}\n\n/** Returns the first date of the week for the given date and locale. */\nexport function startOfWeek(date: ZonedDateTime, locale: string, firstDayOfWeek?: DayOfWeek): ZonedDateTime;\nexport function startOfWeek(date: CalendarDateTime, locale: string, firstDayOfWeek?: DayOfWeek): CalendarDateTime;\nexport function startOfWeek(date: CalendarDate, locale: string, firstDayOfWeek?: DayOfWeek): CalendarDate;\nexport function startOfWeek(date: DateValue, locale: string, firstDayOfWeek?: DayOfWeek): DateValue;\nexport function startOfWeek(date: DateValue, locale: string, firstDayOfWeek?: DayOfWeek): DateValue {\n let dayOfWeek = getDayOfWeek(date, locale, firstDayOfWeek);\n return date.subtract({days: dayOfWeek});\n}\n\n/** Returns the last date of the week for the given date and locale. */\nexport function endOfWeek(date: ZonedDateTime, locale: string, firstDayOfWeek?: DayOfWeek): ZonedDateTime;\nexport function endOfWeek(date: CalendarDateTime, locale: string, firstDayOfWeek?: DayOfWeek): CalendarDateTime;\nexport function endOfWeek(date: CalendarDate, locale: string, firstDayOfWeek?: DayOfWeek): CalendarDate;\nexport function endOfWeek(date: DateValue, locale: string, firstDayOfWeek?: DayOfWeek): DateValue;\nexport function endOfWeek(date: DateValue, locale: string, firstDayOfWeek?: DayOfWeek): DateValue {\n return startOfWeek(date, locale, firstDayOfWeek).add({days: 6});\n}\n\nconst cachedRegions = new Map<string, string>();\n\nfunction getRegion(locale: string): string | undefined {\n // If the Intl.Locale API is available, use it to get the region for the locale.\n // @ts-ignore\n if (Intl.Locale) {\n // Constructing an Intl.Locale is expensive, so cache the result.\n let region = cachedRegions.get(locale);\n if (!region) {\n // @ts-ignore\n region = new Intl.Locale(locale).maximize().region;\n if (region) {\n cachedRegions.set(locale, region);\n }\n }\n return region;\n }\n\n // If not, just try splitting the string.\n // If the second part of the locale string is 'u',\n // then this is a unicode extension, so ignore it.\n // Otherwise, it should be the region.\n let part = locale.split('-')[1];\n return part === 'u' ? undefined : part;\n}\n\nfunction getWeekStart(locale: string): number {\n // TODO: use Intl.Locale for this once browsers support the weekInfo property\n // https://github.com/tc39/proposal-intl-locale-info\n let region = getRegion(locale);\n return region ? weekStartData[region] || 0 : 0;\n}\n\n/** Returns the number of weeks in the given month and locale. */\nexport function getWeeksInMonth(date: DateValue, locale: string, firstDayOfWeek?: DayOfWeek): number {\n let days = date.calendar.getDaysInMonth(date);\n return Math.ceil((getDayOfWeek(startOfMonth(date), locale, firstDayOfWeek) + days) / 7);\n}\n\n/** Returns the lesser of the two provider dates. */\nexport function minDate<A extends DateValue, B extends DateValue>(a?: A | null, b?: B | null): A | B | null | undefined {\n if (a && b) {\n return a.compare(b) <= 0 ? a : b;\n }\n\n return a || b;\n}\n\n/** Returns the greater of the two provider dates. */\nexport function maxDate<A extends DateValue, B extends DateValue>(a?: A | null, b?: B | null): A | B | null | undefined {\n if (a && b) {\n return a.compare(b) >= 0 ? a : b;\n }\n\n return a || b;\n}\n\nconst WEEKEND_DATA = {\n AF: [4, 5],\n AE: [5, 6],\n BH: [5, 6],\n DZ: [5, 6],\n EG: [5, 6],\n IL: [5, 6],\n IQ: [5, 6],\n IR: [5, 5],\n JO: [5, 6],\n KW: [5, 6],\n LY: [5, 6],\n OM: [5, 6],\n QA: [5, 6],\n SA: [5, 6],\n SD: [5, 6],\n SY: [5, 6],\n YE: [5, 6]\n};\n\n/** Returns whether the given date is on a weekend in the given locale. */\nexport function isWeekend(date: DateValue, locale: string): boolean {\n let julian = date.calendar.toJulianDay(date);\n\n // If julian is negative, then julian % 7 will be negative, so we adjust\n // accordingly. Julian day 0 is Monday.\n let dayOfWeek = Math.ceil(julian + 1) % 7;\n if (dayOfWeek < 0) {\n dayOfWeek += 7;\n }\n\n let region = getRegion(locale);\n // Use Intl.Locale for this once weekInfo is supported.\n // https://github.com/tc39/proposal-intl-locale-info\n let [start, end] = WEEKEND_DATA[region!] || [6, 0];\n return dayOfWeek === start || dayOfWeek === end;\n}\n\n/** Returns whether the given date is on a weekday in the given locale. */\nexport function isWeekday(date: DateValue, locale: string): boolean {\n return !isWeekend(date, locale);\n}\n"],"names":[],"version":3,"file":"queries.module.js.map"}
|
package/dist/string.main.js
CHANGED
|
@@ -34,10 +34,10 @@ $parcel$export(module.exports, "parseDuration", () => $4c32e2d98e5a5134$export$e
|
|
|
34
34
|
|
|
35
35
|
|
|
36
36
|
const $4c32e2d98e5a5134$var$TIME_RE = /^(\d{2})(?::(\d{2}))?(?::(\d{2}))?(\.\d+)?$/;
|
|
37
|
-
const $4c32e2d98e5a5134$var$DATE_RE = /^(\d{4})-(\d{2})-(\d{2})$/;
|
|
38
|
-
const $4c32e2d98e5a5134$var$DATE_TIME_RE = /^(\d{4})-(\d{2})-(\d{2})(?:T(\d{2}))?(?::(\d{2}))?(?::(\d{2}))?(\.\d+)?$/;
|
|
39
|
-
const $4c32e2d98e5a5134$var$ZONED_DATE_TIME_RE = /^(\d{4})-(\d{2})-(\d{2})(?:T(\d{2}))?(?::(\d{2}))?(?::(\d{2}))?(\.\d+)?(?:([+-]\d{2})(?::?(\d{2}))?)?\[(.*?)\]$/;
|
|
40
|
-
const $4c32e2d98e5a5134$var$ABSOLUTE_RE = /^(\d{4})-(\d{2})-(\d{2})(?:T(\d{2}))?(?::(\d{2}))?(?::(\d{2}))?(\.\d+)?(?:(?:([+-]\d{2})(?::?(\d{2}))?)|Z)$/;
|
|
37
|
+
const $4c32e2d98e5a5134$var$DATE_RE = /^([+-]\d{6}|\d{4})-(\d{2})-(\d{2})$/;
|
|
38
|
+
const $4c32e2d98e5a5134$var$DATE_TIME_RE = /^([+-]\d{6}|\d{4})-(\d{2})-(\d{2})(?:T(\d{2}))?(?::(\d{2}))?(?::(\d{2}))?(\.\d+)?$/;
|
|
39
|
+
const $4c32e2d98e5a5134$var$ZONED_DATE_TIME_RE = /^([+-]\d{6}|\d{4})-(\d{2})-(\d{2})(?:T(\d{2}))?(?::(\d{2}))?(?::(\d{2}))?(\.\d+)?(?:([+-]\d{2})(?::?(\d{2}))?)?\[(.*?)\]$/;
|
|
40
|
+
const $4c32e2d98e5a5134$var$ABSOLUTE_RE = /^([+-]\d{6}|\d{4})-(\d{2})-(\d{2})(?:T(\d{2}))?(?::(\d{2}))?(?::(\d{2}))?(\.\d+)?(?:(?:([+-]\d{2})(?::?(\d{2}))?)|Z)$/;
|
|
41
41
|
const $4c32e2d98e5a5134$var$DATE_TIME_DURATION_RE = /^((?<negative>-)|\+)?P((?<years>\d*)Y)?((?<months>\d*)M)?((?<weeks>\d*)W)?((?<days>\d*)D)?((?<time>T)((?<hours>\d*[.,]?\d{1,9})H)?((?<minutes>\d*[.,]?\d{1,9})M)?((?<seconds>\d*[.,]?\d{1,9})S)?)?$/;
|
|
42
42
|
const $4c32e2d98e5a5134$var$requiredDurationTimeGroups = [
|
|
43
43
|
'hours',
|
|
@@ -66,14 +66,18 @@ function $4c32e2d98e5a5134$export$6b862160d295c8e(value) {
|
|
|
66
66
|
function $4c32e2d98e5a5134$export$588937bcd60ade55(value) {
|
|
67
67
|
let m = value.match($4c32e2d98e5a5134$var$DATE_TIME_RE);
|
|
68
68
|
if (!m) throw new Error('Invalid ISO 8601 date time string: ' + value);
|
|
69
|
-
let
|
|
69
|
+
let year = $4c32e2d98e5a5134$var$parseNumber(m[1], -9999, 9999);
|
|
70
|
+
let era = year < 1 ? 'BC' : 'AD';
|
|
71
|
+
let date = new (0, $625ad1e1f4c43bc1$exports.CalendarDateTime)(era, year < 1 ? -year + 1 : year, $4c32e2d98e5a5134$var$parseNumber(m[2], 1, 12), 1, m[4] ? $4c32e2d98e5a5134$var$parseNumber(m[4], 0, 23) : 0, m[5] ? $4c32e2d98e5a5134$var$parseNumber(m[5], 0, 59) : 0, m[6] ? $4c32e2d98e5a5134$var$parseNumber(m[6], 0, 59) : 0, m[7] ? $4c32e2d98e5a5134$var$parseNumber(m[7], 0, Infinity) * 1000 : 0);
|
|
70
72
|
date.day = $4c32e2d98e5a5134$var$parseNumber(m[3], 0, date.calendar.getDaysInMonth(date));
|
|
71
73
|
return date;
|
|
72
74
|
}
|
|
73
75
|
function $4c32e2d98e5a5134$export$fd7893f06e92a6a4(value, disambiguation) {
|
|
74
76
|
let m = value.match($4c32e2d98e5a5134$var$ZONED_DATE_TIME_RE);
|
|
75
77
|
if (!m) throw new Error('Invalid ISO 8601 date time string: ' + value);
|
|
76
|
-
let
|
|
78
|
+
let year = $4c32e2d98e5a5134$var$parseNumber(m[1], -9999, 9999);
|
|
79
|
+
let era = year < 1 ? 'BC' : 'AD';
|
|
80
|
+
let date = new (0, $625ad1e1f4c43bc1$exports.ZonedDateTime)(era, year < 1 ? -year + 1 : year, $4c32e2d98e5a5134$var$parseNumber(m[2], 1, 12), 1, m[10], 0, m[4] ? $4c32e2d98e5a5134$var$parseNumber(m[4], 0, 23) : 0, m[5] ? $4c32e2d98e5a5134$var$parseNumber(m[5], 0, 59) : 0, m[6] ? $4c32e2d98e5a5134$var$parseNumber(m[6], 0, 59) : 0, m[7] ? $4c32e2d98e5a5134$var$parseNumber(m[7], 0, Infinity) * 1000 : 0);
|
|
77
81
|
date.day = $4c32e2d98e5a5134$var$parseNumber(m[3], 0, date.calendar.getDaysInMonth(date));
|
|
78
82
|
let plainDateTime = (0, $4ae0260a69729f1d$exports.toCalendarDateTime)(date);
|
|
79
83
|
let ms;
|
|
@@ -91,7 +95,9 @@ function $4c32e2d98e5a5134$export$fd7893f06e92a6a4(value, disambiguation) {
|
|
|
91
95
|
function $4c32e2d98e5a5134$export$5adfdab05168c219(value, timeZone) {
|
|
92
96
|
let m = value.match($4c32e2d98e5a5134$var$ABSOLUTE_RE);
|
|
93
97
|
if (!m) throw new Error('Invalid ISO 8601 date time string: ' + value);
|
|
94
|
-
let
|
|
98
|
+
let year = $4c32e2d98e5a5134$var$parseNumber(m[1], -9999, 9999);
|
|
99
|
+
let era = year < 1 ? 'BC' : 'AD';
|
|
100
|
+
let date = new (0, $625ad1e1f4c43bc1$exports.ZonedDateTime)(era, year < 1 ? -year + 1 : year, $4c32e2d98e5a5134$var$parseNumber(m[2], 1, 12), 1, timeZone, 0, m[4] ? $4c32e2d98e5a5134$var$parseNumber(m[4], 0, 23) : 0, m[5] ? $4c32e2d98e5a5134$var$parseNumber(m[5], 0, 59) : 0, m[6] ? $4c32e2d98e5a5134$var$parseNumber(m[6], 0, 59) : 0, m[7] ? $4c32e2d98e5a5134$var$parseNumber(m[7], 0, Infinity) * 1000 : 0);
|
|
95
101
|
date.day = $4c32e2d98e5a5134$var$parseNumber(m[3], 0, date.calendar.getDaysInMonth(date));
|
|
96
102
|
var _m_;
|
|
97
103
|
if (m[8]) date.offset = $4c32e2d98e5a5134$var$parseNumber(m[8], -23, 23) * 3600000 + $4c32e2d98e5a5134$var$parseNumber((_m_ = m[9]) !== null && _m_ !== void 0 ? _m_ : '0', 0, 59) * 60000;
|
|
@@ -110,7 +116,10 @@ function $4c32e2d98e5a5134$export$f59dee82248f5ad4(time) {
|
|
|
110
116
|
}
|
|
111
117
|
function $4c32e2d98e5a5134$export$60dfd74aa96791bd(date) {
|
|
112
118
|
let gregorianDate = (0, $4ae0260a69729f1d$exports.toCalendar)(date, new (0, $af14c9812fdceb33$exports.GregorianCalendar)());
|
|
113
|
-
|
|
119
|
+
let year;
|
|
120
|
+
if (gregorianDate.era === 'BC') year = gregorianDate.year === 1 ? '0000' : '-' + String(Math.abs(1 - gregorianDate.year)).padStart(6, '00');
|
|
121
|
+
else year = String(gregorianDate.year).padStart(4, '0');
|
|
122
|
+
return `${year}-${String(gregorianDate.month).padStart(2, '0')}-${String(gregorianDate.day).padStart(2, '0')}`;
|
|
114
123
|
}
|
|
115
124
|
function $4c32e2d98e5a5134$export$4223de14708adc63(date) {
|
|
116
125
|
// @ts-ignore
|
|
@@ -130,11 +139,11 @@ function $4c32e2d98e5a5134$export$ecae829bb3747ea6(value) {
|
|
|
130
139
|
var _match_groups, _match_groups1, _match_groups2, _match_groups3, _match_groups4, _match_groups5, _match_groups6, _match_groups7, _match_groups8;
|
|
131
140
|
const match = value.match($4c32e2d98e5a5134$var$DATE_TIME_DURATION_RE);
|
|
132
141
|
if (!match) throw new Error(`Invalid ISO 8601 Duration string: ${value}`);
|
|
133
|
-
const parseDurationGroup = (group, isNegative
|
|
142
|
+
const parseDurationGroup = (group, isNegative)=>{
|
|
134
143
|
if (!group) return 0;
|
|
135
144
|
try {
|
|
136
145
|
const sign = isNegative ? -1 : 1;
|
|
137
|
-
return sign *
|
|
146
|
+
return sign * Number(group.replace(',', '.'));
|
|
138
147
|
} catch {
|
|
139
148
|
throw new Error(`Invalid ISO 8601 Duration string: ${value}`);
|
|
140
149
|
}
|
|
@@ -154,13 +163,13 @@ function $4c32e2d98e5a5134$export$ecae829bb3747ea6(value) {
|
|
|
154
163
|
if (!hasRequiredDurationTimeGroups) throw new Error(`Invalid ISO 8601 Duration string: ${value}`);
|
|
155
164
|
}
|
|
156
165
|
const duration = {
|
|
157
|
-
years: parseDurationGroup((_match_groups2 = match.groups) === null || _match_groups2 === void 0 ? void 0 : _match_groups2.years, isNegative
|
|
158
|
-
months: parseDurationGroup((_match_groups3 = match.groups) === null || _match_groups3 === void 0 ? void 0 : _match_groups3.months, isNegative
|
|
159
|
-
weeks: parseDurationGroup((_match_groups4 = match.groups) === null || _match_groups4 === void 0 ? void 0 : _match_groups4.weeks, isNegative
|
|
160
|
-
days: parseDurationGroup((_match_groups5 = match.groups) === null || _match_groups5 === void 0 ? void 0 : _match_groups5.days, isNegative
|
|
161
|
-
hours: parseDurationGroup((_match_groups6 = match.groups) === null || _match_groups6 === void 0 ? void 0 : _match_groups6.hours, isNegative
|
|
162
|
-
minutes: parseDurationGroup((_match_groups7 = match.groups) === null || _match_groups7 === void 0 ? void 0 : _match_groups7.minutes, isNegative
|
|
163
|
-
seconds: parseDurationGroup((_match_groups8 = match.groups) === null || _match_groups8 === void 0 ? void 0 : _match_groups8.seconds, isNegative
|
|
166
|
+
years: parseDurationGroup((_match_groups2 = match.groups) === null || _match_groups2 === void 0 ? void 0 : _match_groups2.years, isNegative),
|
|
167
|
+
months: parseDurationGroup((_match_groups3 = match.groups) === null || _match_groups3 === void 0 ? void 0 : _match_groups3.months, isNegative),
|
|
168
|
+
weeks: parseDurationGroup((_match_groups4 = match.groups) === null || _match_groups4 === void 0 ? void 0 : _match_groups4.weeks, isNegative),
|
|
169
|
+
days: parseDurationGroup((_match_groups5 = match.groups) === null || _match_groups5 === void 0 ? void 0 : _match_groups5.days, isNegative),
|
|
170
|
+
hours: parseDurationGroup((_match_groups6 = match.groups) === null || _match_groups6 === void 0 ? void 0 : _match_groups6.hours, isNegative),
|
|
171
|
+
minutes: parseDurationGroup((_match_groups7 = match.groups) === null || _match_groups7 === void 0 ? void 0 : _match_groups7.minutes, isNegative),
|
|
172
|
+
seconds: parseDurationGroup((_match_groups8 = match.groups) === null || _match_groups8 === void 0 ? void 0 : _match_groups8.seconds, isNegative)
|
|
164
173
|
};
|
|
165
174
|
if (duration.hours !== undefined && duration.hours % 1 !== 0 && (duration.minutes || duration.seconds)) throw new Error(`Invalid ISO 8601 Duration string: ${value} - only the smallest unit can be fractional`);
|
|
166
175
|
if (duration.minutes !== undefined && duration.minutes % 1 !== 0 && duration.seconds) throw new Error(`Invalid ISO 8601 Duration string: ${value} - only the smallest unit can be fractional`);
|
package/dist/string.main.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"mappings":";;;;;;;;;;;;;;;;;;;;;AAAA;;;;;;;;;;CAUC;;;;AASD,MAAM,gCAAU;AAChB,MAAM,gCAAU;AAChB,MAAM,qCAAe;AACrB,MAAM,2CAAqB;AAC3B,MAAM,oCAAc;AACpB,MAAM,8CACF;AACJ,MAAM,mDAA6B;IAAC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yright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport {AnyDateTime, DateTimeDuration, Disambiguation} from './types';\nimport {CalendarDate, CalendarDateTime, Time, ZonedDateTime} from './CalendarDate';\nimport {epochFromDate, fromAbsolute, possibleAbsolutes, toAbsolute, toCalendar, toCalendarDateTime, toTimeZone} from './conversion';\nimport {getLocalTimeZone} from './queries';\nimport {GregorianCalendar} from './calendars/GregorianCalendar';\nimport {Mutable} from './utils';\n\nconst TIME_RE = /^(\\d{2})(?::(\\d{2}))?(?::(\\d{2}))?(\\.\\d+)?$/;\nconst DATE_RE = /^(\\d{4})-(\\d{2})-(\\d{2})$/;\nconst DATE_TIME_RE = /^(\\d{4})-(\\d{2})-(\\d{2})(?:T(\\d{2}))?(?::(\\d{2}))?(?::(\\d{2}))?(\\.\\d+)?$/;\nconst ZONED_DATE_TIME_RE = /^(\\d{4})-(\\d{2})-(\\d{2})(?:T(\\d{2}))?(?::(\\d{2}))?(?::(\\d{2}))?(\\.\\d+)?(?:([+-]\\d{2})(?::?(\\d{2}))?)?\\[(.*?)\\]$/;\nconst ABSOLUTE_RE = /^(\\d{4})-(\\d{2})-(\\d{2})(?:T(\\d{2}))?(?::(\\d{2}))?(?::(\\d{2}))?(\\.\\d+)?(?:(?:([+-]\\d{2})(?::?(\\d{2}))?)|Z)$/;\nconst DATE_TIME_DURATION_RE =\n /^((?<negative>-)|\\+)?P((?<years>\\d*)Y)?((?<months>\\d*)M)?((?<weeks>\\d*)W)?((?<days>\\d*)D)?((?<time>T)((?<hours>\\d*[.,]?\\d{1,9})H)?((?<minutes>\\d*[.,]?\\d{1,9})M)?((?<seconds>\\d*[.,]?\\d{1,9})S)?)?$/;\nconst requiredDurationTimeGroups = ['hours', 'minutes', 'seconds'];\nconst requiredDurationGroups = ['years', 'months', 'weeks', 'days', ...requiredDurationTimeGroups];\n\n/** Parses an ISO 8601 time string. */\nexport function parseTime(value: string): Time {\n let m = value.match(TIME_RE);\n if (!m) {\n throw new Error('Invalid ISO 8601 time string: ' + value);\n }\n\n return new Time(\n parseNumber(m[1], 0, 23),\n m[2] ? parseNumber(m[2], 0, 59) : 0,\n m[3] ? parseNumber(m[3], 0, 59) : 0,\n m[4] ? parseNumber(m[4], 0, Infinity) * 1000 : 0\n );\n}\n\n/** Parses an ISO 8601 date string, with no time components. */\nexport function parseDate(value: string): CalendarDate {\n let m = value.match(DATE_RE);\n if (!m) {\n throw new Error('Invalid ISO 8601 date string: ' + value);\n }\n\n let date: Mutable<CalendarDate> = new CalendarDate(\n parseNumber(m[1], 0, 9999),\n parseNumber(m[2], 1, 12),\n 1\n );\n\n date.day = parseNumber(m[3], 0, date.calendar.getDaysInMonth(date));\n return date as CalendarDate;\n}\n\n/** Parses an ISO 8601 date and time string, with no time zone. */\nexport function parseDateTime(value: string): CalendarDateTime {\n let m = value.match(DATE_TIME_RE);\n if (!m) {\n throw new Error('Invalid ISO 8601 date time string: ' + value);\n }\n\n let date: Mutable<CalendarDateTime> = new CalendarDateTime(\n parseNumber(m[1], 1, 9999),\n parseNumber(m[2], 1, 12),\n 1,\n m[4] ? parseNumber(m[4], 0, 23) : 0,\n m[5] ? parseNumber(m[5], 0, 59) : 0,\n m[6] ? parseNumber(m[6], 0, 59) : 0,\n m[7] ? parseNumber(m[7], 0, Infinity) * 1000 : 0\n );\n\n date.day = parseNumber(m[3], 0, date.calendar.getDaysInMonth(date));\n return date as CalendarDateTime;\n}\n\n/**\n * Parses an ISO 8601 date and time string with a time zone extension and optional UTC offset\n * (e.g. \"2021-11-07T00:45[America/Los_Angeles]\" or \"2021-11-07T00:45-07:00[America/Los_Angeles]\").\n * Ambiguous times due to daylight saving time transitions are resolved according to the `disambiguation`\n * parameter.\n */\nexport function parseZonedDateTime(value: string, disambiguation?: Disambiguation): ZonedDateTime {\n let m = value.match(ZONED_DATE_TIME_RE);\n if (!m) {\n throw new Error('Invalid ISO 8601 date time string: ' + value);\n }\n\n let date: Mutable<ZonedDateTime> = new ZonedDateTime(\n parseNumber(m[1], 1, 9999),\n parseNumber(m[2], 1, 12),\n 1,\n m[10],\n 0,\n m[4] ? parseNumber(m[4], 0, 23) : 0,\n m[5] ? parseNumber(m[5], 0, 59) : 0,\n m[6] ? parseNumber(m[6], 0, 59) : 0,\n m[7] ? parseNumber(m[7], 0, Infinity) * 1000 : 0\n );\n\n date.day = parseNumber(m[3], 0, date.calendar.getDaysInMonth(date));\n\n let plainDateTime = toCalendarDateTime(date as ZonedDateTime);\n\n let ms: number;\n if (m[8]) {\n date.offset = parseNumber(m[8], -23, 23) * 60 * 60 * 1000 + parseNumber(m[9] ?? '0', 0, 59) * 60 * 1000;\n ms = epochFromDate(date as ZonedDateTime) - date.offset;\n\n // Validate offset against parsed date.\n let absolutes = possibleAbsolutes(plainDateTime, date.timeZone);\n if (!absolutes.includes(ms)) {\n throw new Error(`Offset ${offsetToString(date.offset)} is invalid for ${dateTimeToString(date)} in ${date.timeZone}`);\n }\n } else {\n // Convert to absolute and back to fix invalid times due to DST.\n ms = toAbsolute(toCalendarDateTime(plainDateTime), date.timeZone, disambiguation);\n }\n\n return fromAbsolute(ms, date.timeZone);\n}\n\n/**\n * Parses an ISO 8601 date and time string with a UTC offset (e.g. \"2021-11-07T07:45:00Z\"\n * or \"2021-11-07T07:45:00-07:00\"). The result is converted to the provided time zone.\n */\nexport function parseAbsolute(value: string, timeZone: string): ZonedDateTime {\n let m = value.match(ABSOLUTE_RE);\n if (!m) {\n throw new Error('Invalid ISO 8601 date time string: ' + value);\n }\n\n let date: Mutable<ZonedDateTime> = new ZonedDateTime(\n parseNumber(m[1], 1, 9999),\n parseNumber(m[2], 1, 12),\n 1,\n timeZone,\n 0,\n m[4] ? parseNumber(m[4], 0, 23) : 0,\n m[5] ? parseNumber(m[5], 0, 59) : 0,\n m[6] ? parseNumber(m[6], 0, 59) : 0,\n m[7] ? parseNumber(m[7], 0, Infinity) * 1000 : 0\n );\n\n date.day = parseNumber(m[3], 0, date.calendar.getDaysInMonth(date));\n\n if (m[8]) {\n date.offset = parseNumber(m[8], -23, 23) * 60 * 60 * 1000 + parseNumber(m[9] ?? '0', 0, 59) * 60 * 1000;\n }\n\n return toTimeZone(date as ZonedDateTime, timeZone);\n}\n\n/**\n * Parses an ISO 8601 date and time string with a UTC offset (e.g. \"2021-11-07T07:45:00Z\"\n * or \"2021-11-07T07:45:00-07:00\"). The result is converted to the user's local time zone.\n */\nexport function parseAbsoluteToLocal(value: string): ZonedDateTime {\n return parseAbsolute(value, getLocalTimeZone());\n}\n\nfunction parseNumber(value: string, min: number, max: number) {\n let val = Number(value);\n if (val < min || val > max) {\n throw new RangeError(`Value out of range: ${min} <= ${val} <= ${max}`);\n }\n\n return val;\n}\n\nexport function timeToString(time: Time): string {\n return `${String(time.hour).padStart(2, '0')}:${String(time.minute).padStart(2, '0')}:${String(time.second).padStart(2, '0')}${time.millisecond ? String(time.millisecond / 1000).slice(1) : ''}`;\n}\n\nexport function dateToString(date: CalendarDate): string {\n let gregorianDate = toCalendar(date, new GregorianCalendar());\n return `${String(gregorianDate.year).padStart(4, '0')}-${String(gregorianDate.month).padStart(2, '0')}-${String(gregorianDate.day).padStart(2, '0')}`;\n}\n\nexport function dateTimeToString(date: AnyDateTime): string {\n // @ts-ignore\n return `${dateToString(date)}T${timeToString(date)}`;\n}\n\nfunction offsetToString(offset: number) {\n let sign = Math.sign(offset) < 0 ? '-' : '+';\n offset = Math.abs(offset);\n let offsetHours = Math.floor(offset / (60 * 60 * 1000));\n let offsetMinutes = (offset % (60 * 60 * 1000)) / (60 * 1000);\n return `${sign}${String(offsetHours).padStart(2, '0')}:${String(offsetMinutes).padStart(2, '0')}`;\n}\n\nexport function zonedDateTimeToString(date: ZonedDateTime): string {\n return `${dateTimeToString(date)}${offsetToString(date.offset)}[${date.timeZone}]`;\n}\n\n/**\n * Parses an ISO 8601 duration string (e.g. \"P3Y6M6W4DT12H30M5S\").\n * @param value An ISO 8601 duration string.\n * @returns A DateTimeDuration object.\n */\nexport function parseDuration(value: string): Required<DateTimeDuration> {\n const match = value.match(DATE_TIME_DURATION_RE);\n\n if (!match) {\n throw new Error(`Invalid ISO 8601 Duration string: ${value}`);\n }\n\n const parseDurationGroup = (\n group: string | undefined,\n isNegative: boolean,\n min: number,\n max: number\n ): number => {\n if (!group) {\n return 0;\n }\n try {\n const sign = isNegative ? -1 : 1;\n return sign * parseNumber(group.replace(',', '.'), min, max);\n } catch {\n throw new Error(`Invalid ISO 8601 Duration string: ${value}`);\n }\n };\n\n const isNegative = !!match.groups?.negative;\n\n const hasRequiredGroups = requiredDurationGroups.some(group => match.groups?.[group]);\n\n if (!hasRequiredGroups) {\n throw new Error(`Invalid ISO 8601 Duration string: ${value}`);\n }\n\n const durationStringIncludesTime = match.groups?.time;\n\n if (durationStringIncludesTime) {\n const hasRequiredDurationTimeGroups = requiredDurationTimeGroups.some(group => match.groups?.[group]);\n if (!hasRequiredDurationTimeGroups) {\n throw new Error(`Invalid ISO 8601 Duration string: ${value}`);\n }\n }\n\n const duration: Mutable<DateTimeDuration> = {\n years: parseDurationGroup(match.groups?.years, isNegative, 0, 9999),\n months: parseDurationGroup(match.groups?.months, isNegative, 0, 12),\n weeks: parseDurationGroup(match.groups?.weeks, isNegative, 0, Infinity),\n days: parseDurationGroup(match.groups?.days, isNegative, 0, 31),\n hours: parseDurationGroup(match.groups?.hours, isNegative, 0, 23),\n minutes: parseDurationGroup(match.groups?.minutes, isNegative, 0, 59),\n seconds: parseDurationGroup(match.groups?.seconds, isNegative, 0, 59)\n };\n\n if (duration.hours !== undefined && ((duration.hours % 1) !== 0) && (duration.minutes || duration.seconds)) {\n throw new Error(`Invalid ISO 8601 Duration string: ${value} - only the smallest unit can be fractional`);\n }\n\n if (duration.minutes !== undefined && ((duration.minutes % 1) !== 0) && duration.seconds) {\n throw new Error(`Invalid ISO 8601 Duration string: ${value} - only the smallest unit can be fractional`);\n }\n\n return duration as Required<DateTimeDuration>;\n}\n"],"names":[],"version":3,"file":"string.main.js.map"}
|
|
1
|
+
{"mappings":";;;;;;;;;;;;;;;;;;;;;AAAA;;;;;;;;;;CAUC;;;;AASD,MAAM,gCAAU;AAChB,MAAM,gCAAU;AAChB,MAAM,qCAAe;AACrB,MAAM,2CAAqB;AAC3B,MAAM,oCAAc;AACpB,MAAM,8CACF;AACJ,MAAM,mDAA6B;IAAC;IAAS;IAAW;CAAU;AAClE,MAAM,+CAAyB;IAAC;IAAS;IAAU;IAAS;OAAW;CAA2B;AAG3F,SAAS,0CAAU,KAAa;IACrC,IAAI,IAAI,MAAM,KAAK,CAAC;IACpB,IAAI,CAAC,GACH,MAAM,IAAI,MAAM,mCAAmC;IAGrD,OAAO,IAAI,CAAA,GAAA,8BAAG,EACZ,kCAAY,CAAC,CAAC,EAAE,EAAE,GAAG,KACrB,CAAC,CAAC,EAAE,GAAG,kCAAY,CAAC,CAAC,EAAE,EAAE,GAAG,MAAM,GAClC,CAAC,CAAC,EAAE,GAAG,kCAAY,CAAC,CAAC,EAAE,EAAE,GAAG,MAAM,GAClC,CAAC,CAAC,EAAE,GAAG,kCAAY,CAAC,CAAC,EAAE,EAAE,GAAG,YAAY,OAAO;AAEnD;AAGO,SAAS,yCAAU,KAAa;IACrC,IAAI,IAAI,MAAM,KAAK,CAAC;IACpB,IAAI,CAAC,GACH,MAAM,IAAI,MAAM,mCAAmC;IAGrD,IAAI,OAA8B,IAAI,CAAA,GAAA,sCAAW,EAC/C,kCAAY,CAAC,CAAC,EAAE,EAAE,GAAG,OACrB,kCAAY,CAAC,CAAC,EAAE,EAAE,GAAG,KACrB;IAGF,KAAK,GAAG,GAAG,kCAAY,CAAC,CAAC,EA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,MAAM,cAAZ,qCAAA,eAAc,IAAI,EAAE;QAC7C,OAAO,oBAAmB,iBAAA,MAAM,MAAM,cAAZ,qCAAA,eAAc,KAAK,EAAE;QAC/C,SAAS,oBAAmB,iBAAA,MAAM,MAAM,cAAZ,qCAAA,eAAc,OAAO,EAAE;QACnD,SAAS,oBAAmB,iBAAA,MAAM,MAAM,cAAZ,qCAAA,eAAc,OAAO,EAAE;IACrD;IAEA,IAAI,SAAS,KAAK,KAAK,aAAc,AAAC,SAAS,KAAK,GAAG,MAAO,KAAO,CAAA,SAAS,OAAO,IAAI,SAAS,OAAO,AAAD,GACtG,MAAM,IAAI,MAAM,CAAC,kCAAkC,EAAE,MAAM,2CAA2C,CAAC;IAGzG,IAAI,SAAS,OAAO,KAAK,aAAc,AAAC,SAAS,OAAO,GAAG,MAAO,KAAM,SAAS,OAAO,EACtF,MAAM,IAAI,MAAM,CAAC,kCAAkC,EAAE,MAAM,2CAA2C,CAAC;IAGzG,OAAO;AACT","sources":["packages/@internationalized/date/src/string.ts"],"sourcesContent":["/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport {AnyDateTime, DateTimeDuration, Disambiguation} from './types';\nimport {CalendarDate, CalendarDateTime, Time, ZonedDateTime} from './CalendarDate';\nimport {epochFromDate, fromAbsolute, possibleAbsolutes, toAbsolute, toCalendar, toCalendarDateTime, toTimeZone} from './conversion';\nimport {getLocalTimeZone} from './queries';\nimport {GregorianCalendar} from './calendars/GregorianCalendar';\nimport {Mutable} from './utils';\n\nconst TIME_RE = /^(\\d{2})(?::(\\d{2}))?(?::(\\d{2}))?(\\.\\d+)?$/;\nconst DATE_RE = /^([+-]\\d{6}|\\d{4})-(\\d{2})-(\\d{2})$/;\nconst DATE_TIME_RE = /^([+-]\\d{6}|\\d{4})-(\\d{2})-(\\d{2})(?:T(\\d{2}))?(?::(\\d{2}))?(?::(\\d{2}))?(\\.\\d+)?$/;\nconst ZONED_DATE_TIME_RE = /^([+-]\\d{6}|\\d{4})-(\\d{2})-(\\d{2})(?:T(\\d{2}))?(?::(\\d{2}))?(?::(\\d{2}))?(\\.\\d+)?(?:([+-]\\d{2})(?::?(\\d{2}))?)?\\[(.*?)\\]$/;\nconst ABSOLUTE_RE = /^([+-]\\d{6}|\\d{4})-(\\d{2})-(\\d{2})(?:T(\\d{2}))?(?::(\\d{2}))?(?::(\\d{2}))?(\\.\\d+)?(?:(?:([+-]\\d{2})(?::?(\\d{2}))?)|Z)$/;\nconst DATE_TIME_DURATION_RE =\n /^((?<negative>-)|\\+)?P((?<years>\\d*)Y)?((?<months>\\d*)M)?((?<weeks>\\d*)W)?((?<days>\\d*)D)?((?<time>T)((?<hours>\\d*[.,]?\\d{1,9})H)?((?<minutes>\\d*[.,]?\\d{1,9})M)?((?<seconds>\\d*[.,]?\\d{1,9})S)?)?$/;\nconst requiredDurationTimeGroups = ['hours', 'minutes', 'seconds'];\nconst requiredDurationGroups = ['years', 'months', 'weeks', 'days', ...requiredDurationTimeGroups];\n\n/** Parses an ISO 8601 time string. */\nexport function parseTime(value: string): Time {\n let m = value.match(TIME_RE);\n if (!m) {\n throw new Error('Invalid ISO 8601 time string: ' + value);\n }\n\n return new Time(\n parseNumber(m[1], 0, 23),\n m[2] ? parseNumber(m[2], 0, 59) : 0,\n m[3] ? parseNumber(m[3], 0, 59) : 0,\n m[4] ? parseNumber(m[4], 0, Infinity) * 1000 : 0\n );\n}\n\n/** Parses an ISO 8601 date string, with no time components. */\nexport function parseDate(value: string): CalendarDate {\n let m = value.match(DATE_RE);\n if (!m) {\n throw new Error('Invalid ISO 8601 date string: ' + value);\n }\n\n let date: Mutable<CalendarDate> = new CalendarDate(\n parseNumber(m[1], 0, 9999),\n parseNumber(m[2], 1, 12),\n 1\n );\n\n date.day = parseNumber(m[3], 0, date.calendar.getDaysInMonth(date));\n return date as CalendarDate;\n}\n\n/** Parses an ISO 8601 date and time string, with no time zone. */\nexport function parseDateTime(value: string): CalendarDateTime {\n let m = value.match(DATE_TIME_RE);\n if (!m) {\n throw new Error('Invalid ISO 8601 date time string: ' + value);\n }\n\n let year = parseNumber(m[1], -9999, 9999);\n let era = year < 1 ? 'BC' : 'AD';\n\n let date: Mutable<CalendarDateTime> = new CalendarDateTime(\n era,\n year < 1 ? -year + 1 : year,\n parseNumber(m[2], 1, 12),\n 1,\n m[4] ? parseNumber(m[4], 0, 23) : 0,\n m[5] ? parseNumber(m[5], 0, 59) : 0,\n m[6] ? parseNumber(m[6], 0, 59) : 0,\n m[7] ? parseNumber(m[7], 0, Infinity) * 1000 : 0\n );\n\n date.day = parseNumber(m[3], 0, date.calendar.getDaysInMonth(date));\n return date as CalendarDateTime;\n}\n\n/**\n * Parses an ISO 8601 date and time string with a time zone extension and optional UTC offset\n * (e.g. \"2021-11-07T00:45[America/Los_Angeles]\" or \"2021-11-07T00:45-07:00[America/Los_Angeles]\").\n * Ambiguous times due to daylight saving time transitions are resolved according to the `disambiguation`\n * parameter.\n */\nexport function parseZonedDateTime(value: string, disambiguation?: Disambiguation): ZonedDateTime {\n let m = value.match(ZONED_DATE_TIME_RE);\n if (!m) {\n throw new Error('Invalid ISO 8601 date time string: ' + value);\n }\n\n let year = parseNumber(m[1], -9999, 9999);\n let era = year < 1 ? 'BC' : 'AD';\n\n let date: Mutable<ZonedDateTime> = new ZonedDateTime(\n era,\n year < 1 ? -year + 1 : year,\n parseNumber(m[2], 1, 12),\n 1,\n m[10],\n 0,\n m[4] ? parseNumber(m[4], 0, 23) : 0,\n m[5] ? parseNumber(m[5], 0, 59) : 0,\n m[6] ? parseNumber(m[6], 0, 59) : 0,\n m[7] ? parseNumber(m[7], 0, Infinity) * 1000 : 0\n );\n\n date.day = parseNumber(m[3], 0, date.calendar.getDaysInMonth(date));\n\n let plainDateTime = toCalendarDateTime(date as ZonedDateTime);\n\n let ms: number;\n if (m[8]) {\n date.offset = parseNumber(m[8], -23, 23) * 60 * 60 * 1000 + parseNumber(m[9] ?? '0', 0, 59) * 60 * 1000;\n ms = epochFromDate(date as ZonedDateTime) - date.offset;\n\n // Validate offset against parsed date.\n let absolutes = possibleAbsolutes(plainDateTime, date.timeZone);\n if (!absolutes.includes(ms)) {\n throw new Error(`Offset ${offsetToString(date.offset)} is invalid for ${dateTimeToString(date)} in ${date.timeZone}`);\n }\n } else {\n // Convert to absolute and back to fix invalid times due to DST.\n ms = toAbsolute(toCalendarDateTime(plainDateTime), date.timeZone, disambiguation);\n }\n\n return fromAbsolute(ms, date.timeZone);\n}\n\n/**\n * Parses an ISO 8601 date and time string with a UTC offset (e.g. \"2021-11-07T07:45:00Z\"\n * or \"2021-11-07T07:45:00-07:00\"). The result is converted to the provided time zone.\n */\nexport function parseAbsolute(value: string, timeZone: string): ZonedDateTime {\n let m = value.match(ABSOLUTE_RE);\n if (!m) {\n throw new Error('Invalid ISO 8601 date time string: ' + value);\n }\n\n let year = parseNumber(m[1], -9999, 9999);\n let era = year < 1 ? 'BC' : 'AD';\n\n let date: Mutable<ZonedDateTime> = new ZonedDateTime(\n era,\n year < 1 ? -year + 1 : year,\n parseNumber(m[2], 1, 12),\n 1,\n timeZone,\n 0,\n m[4] ? parseNumber(m[4], 0, 23) : 0,\n m[5] ? parseNumber(m[5], 0, 59) : 0,\n m[6] ? parseNumber(m[6], 0, 59) : 0,\n m[7] ? parseNumber(m[7], 0, Infinity) * 1000 : 0\n );\n\n date.day = parseNumber(m[3], 0, date.calendar.getDaysInMonth(date));\n\n if (m[8]) {\n date.offset = parseNumber(m[8], -23, 23) * 60 * 60 * 1000 + parseNumber(m[9] ?? '0', 0, 59) * 60 * 1000;\n }\n\n return toTimeZone(date as ZonedDateTime, timeZone);\n}\n\n/**\n * Parses an ISO 8601 date and time string with a UTC offset (e.g. \"2021-11-07T07:45:00Z\"\n * or \"2021-11-07T07:45:00-07:00\"). The result is converted to the user's local time zone.\n */\nexport function parseAbsoluteToLocal(value: string): ZonedDateTime {\n return parseAbsolute(value, getLocalTimeZone());\n}\n\nfunction parseNumber(value: string, min: number, max: number) {\n let val = Number(value);\n if (val < min || val > max) {\n throw new RangeError(`Value out of range: ${min} <= ${val} <= ${max}`);\n }\n\n return val;\n}\n\nexport function timeToString(time: Time): string {\n return `${String(time.hour).padStart(2, '0')}:${String(time.minute).padStart(2, '0')}:${String(time.second).padStart(2, '0')}${time.millisecond ? String(time.millisecond / 1000).slice(1) : ''}`;\n}\n\nexport function dateToString(date: CalendarDate): string {\n let gregorianDate = toCalendar(date, new GregorianCalendar());\n let year: string;\n if (gregorianDate.era === 'BC') {\n year = gregorianDate.year === 1 \n ? '0000'\n : '-' + String(Math.abs(1 - gregorianDate.year)).padStart(6, '00');\n } else {\n year = String(gregorianDate.year).padStart(4, '0');\n }\n return `${year}-${String(gregorianDate.month).padStart(2, '0')}-${String(gregorianDate.day).padStart(2, '0')}`;\n}\n\nexport function dateTimeToString(date: AnyDateTime): string {\n // @ts-ignore\n return `${dateToString(date)}T${timeToString(date)}`;\n}\n\nfunction offsetToString(offset: number) {\n let sign = Math.sign(offset) < 0 ? '-' : '+';\n offset = Math.abs(offset);\n let offsetHours = Math.floor(offset / (60 * 60 * 1000));\n let offsetMinutes = (offset % (60 * 60 * 1000)) / (60 * 1000);\n return `${sign}${String(offsetHours).padStart(2, '0')}:${String(offsetMinutes).padStart(2, '0')}`;\n}\n\nexport function zonedDateTimeToString(date: ZonedDateTime): string {\n return `${dateTimeToString(date)}${offsetToString(date.offset)}[${date.timeZone}]`;\n}\n\n/**\n * Parses an ISO 8601 duration string (e.g. \"P3Y6M6W4DT12H30M5S\").\n * @param value An ISO 8601 duration string.\n * @returns A DateTimeDuration object.\n */\nexport function parseDuration(value: string): Required<DateTimeDuration> {\n const match = value.match(DATE_TIME_DURATION_RE);\n\n if (!match) {\n throw new Error(`Invalid ISO 8601 Duration string: ${value}`);\n }\n\n const parseDurationGroup = (\n group: string | undefined,\n isNegative: boolean\n ): number => {\n if (!group) {\n return 0;\n }\n try {\n const sign = isNegative ? -1 : 1;\n return sign * Number(group.replace(',', '.'));\n } catch {\n throw new Error(`Invalid ISO 8601 Duration string: ${value}`);\n }\n };\n\n const isNegative = !!match.groups?.negative;\n\n const hasRequiredGroups = requiredDurationGroups.some(group => match.groups?.[group]);\n\n if (!hasRequiredGroups) {\n throw new Error(`Invalid ISO 8601 Duration string: ${value}`);\n }\n\n const durationStringIncludesTime = match.groups?.time;\n\n if (durationStringIncludesTime) {\n const hasRequiredDurationTimeGroups = requiredDurationTimeGroups.some(group => match.groups?.[group]);\n if (!hasRequiredDurationTimeGroups) {\n throw new Error(`Invalid ISO 8601 Duration string: ${value}`);\n }\n }\n\n const duration: Mutable<DateTimeDuration> = {\n years: parseDurationGroup(match.groups?.years, isNegative),\n months: parseDurationGroup(match.groups?.months, isNegative),\n weeks: parseDurationGroup(match.groups?.weeks, isNegative),\n days: parseDurationGroup(match.groups?.days, isNegative),\n hours: parseDurationGroup(match.groups?.hours, isNegative),\n minutes: parseDurationGroup(match.groups?.minutes, isNegative),\n seconds: parseDurationGroup(match.groups?.seconds, isNegative)\n };\n\n if (duration.hours !== undefined && ((duration.hours % 1) !== 0) && (duration.minutes || duration.seconds)) {\n throw new Error(`Invalid ISO 8601 Duration string: ${value} - only the smallest unit can be fractional`);\n }\n\n if (duration.minutes !== undefined && ((duration.minutes % 1) !== 0) && duration.seconds) {\n throw new Error(`Invalid ISO 8601 Duration string: ${value} - only the smallest unit can be fractional`);\n }\n\n return duration as Required<DateTimeDuration>;\n}\n"],"names":[],"version":3,"file":"string.main.js.map"}
|