UNPKG

@js-temporal/polyfill

Version:

Polyfill for Tc39 Stage 3 proposal Temporal (https://github.com/tc39/proposal-temporal)

1 lines 683 kB
{"version":3,"file":"index.cjs","sources":["../tsc-out/intrinsicclass.js","../tsc-out/slots.js","../tsc-out/regex.js","../tsc-out/ecmascript.js","../tsc-out/intl.js","../tsc-out/instant.js","../tsc-out/calendar.js","../tsc-out/plaindate.js","../tsc-out/plaindatetime.js","../tsc-out/duration.js","../tsc-out/plainmonthday.js","../tsc-out/now.js","../tsc-out/plaintime.js","../tsc-out/timezone.js","../tsc-out/plainyearmonth.js","../tsc-out/zoneddatetime.js","../tsc-out/index.js","../tsc-out/legacydate.js"],"sourcesContent":["import { DEBUG } from './debug';\nconst INTRINSICS = {};\nconst customUtilInspectFormatters = {\n ['Temporal.Duration'](depth, options) {\n const descr = options.stylize(`${this[Symbol.toStringTag]} <${this}>`, 'special');\n if (depth < 1)\n return descr;\n const entries = [];\n for (const prop of [\n 'years',\n 'months',\n 'weeks',\n 'days',\n 'hours',\n 'minutes',\n 'seconds',\n 'milliseconds',\n 'microseconds',\n 'nanoseconds'\n ]) {\n if (this[prop] !== 0)\n entries.push(` ${prop}: ${options.stylize(this[prop], 'number')}`);\n }\n return descr + ' {\\n' + entries.join(',\\n') + '\\n}';\n }\n};\nfunction defaultUtilInspectFormatter(depth, options) {\n return options.stylize(`${this[Symbol.toStringTag]} <${this}>`, 'special');\n}\nexport function MakeIntrinsicClass(Class, name) {\n Object.defineProperty(Class.prototype, Symbol.toStringTag, {\n value: name,\n writable: false,\n enumerable: false,\n configurable: true\n });\n if (DEBUG) {\n Object.defineProperty(Class.prototype, Symbol.for('nodejs.util.inspect.custom'), {\n value: customUtilInspectFormatters[name] || defaultUtilInspectFormatter,\n writable: false,\n enumerable: false,\n configurable: true\n });\n }\n for (const prop of Object.getOwnPropertyNames(Class)) {\n // we know that `prop` is present, so the descriptor is never undefined\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n const desc = Object.getOwnPropertyDescriptor(Class, prop);\n if (!desc.configurable || !desc.enumerable)\n continue;\n desc.enumerable = false;\n Object.defineProperty(Class, prop, desc);\n }\n for (const prop of Object.getOwnPropertyNames(Class.prototype)) {\n // we know that `prop` is present, so the descriptor is never undefined\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n const desc = Object.getOwnPropertyDescriptor(Class.prototype, prop);\n if (!desc.configurable || !desc.enumerable)\n continue;\n desc.enumerable = false;\n Object.defineProperty(Class.prototype, prop, desc);\n }\n DefineIntrinsic(name, Class);\n DefineIntrinsic(`${name}.prototype`, Class.prototype);\n}\nexport function DefineIntrinsic(name, value) {\n const key = `%${name}%`;\n if (INTRINSICS[key] !== undefined)\n throw new Error(`intrinsic ${name} already exists`);\n INTRINSICS[key] = value;\n}\nexport function GetIntrinsic(intrinsic) {\n return INTRINSICS[intrinsic];\n}\n//# sourceMappingURL=intrinsicclass.js.map","// Instant\nexport const EPOCHNANOSECONDS = 'slot-epochNanoSeconds';\n// TimeZone\nexport const TIMEZONE_ID = 'slot-timezone-identifier';\n// DateTime, Date, Time, YearMonth, MonthDay\nexport const ISO_YEAR = 'slot-year';\nexport const ISO_MONTH = 'slot-month';\nexport const ISO_DAY = 'slot-day';\nexport const ISO_HOUR = 'slot-hour';\nexport const ISO_MINUTE = 'slot-minute';\nexport const ISO_SECOND = 'slot-second';\nexport const ISO_MILLISECOND = 'slot-millisecond';\nexport const ISO_MICROSECOND = 'slot-microsecond';\nexport const ISO_NANOSECOND = 'slot-nanosecond';\nexport const CALENDAR = 'slot-calendar';\n// Date, YearMonth, and MonthDay all have the same slots, disambiguation needed:\nexport const DATE_BRAND = 'slot-date-brand';\nexport const YEAR_MONTH_BRAND = 'slot-year-month-brand';\nexport const MONTH_DAY_BRAND = 'slot-month-day-brand';\n// ZonedDateTime\nexport const INSTANT = 'slot-cached-instant';\nexport const TIME_ZONE = 'slot-time-zone';\n// Duration\nexport const YEARS = 'slot-years';\nexport const MONTHS = 'slot-months';\nexport const WEEKS = 'slot-weeks';\nexport const DAYS = 'slot-days';\nexport const HOURS = 'slot-hours';\nexport const MINUTES = 'slot-minutes';\nexport const SECONDS = 'slot-seconds';\nexport const MILLISECONDS = 'slot-milliseconds';\nexport const MICROSECONDS = 'slot-microseconds';\nexport const NANOSECONDS = 'slot-nanoseconds';\n// Calendar\nexport const CALENDAR_ID = 'slot-calendar-identifier';\nconst slots = new WeakMap();\nexport function CreateSlots(container) {\n slots.set(container, Object.create(null));\n}\nfunction GetSlots(container) {\n return slots.get(container);\n}\nexport function HasSlot(container, ...ids) {\n if (!container || 'object' !== typeof container)\n return false;\n const myslots = GetSlots(container);\n return !!myslots && ids.reduce((all, id) => all && id in myslots, true);\n}\nexport function GetSlot(container, id) {\n const value = GetSlots(container)[id];\n if (value === undefined)\n throw new TypeError(`Missing internal slot ${id}`);\n return value;\n}\nexport function SetSlot(container, id, value) {\n GetSlots(container)[id] = value;\n}\n//# sourceMappingURL=slots.js.map","const tzComponent = /\\.[-A-Za-z_]|\\.\\.[-A-Za-z._]{1,12}|\\.[-A-Za-z_][-A-Za-z._]{0,12}|[A-Za-z_][-A-Za-z._]{0,13}/;\nconst offsetNoCapture = /(?:[+\\u2212-][0-2][0-9](?::?[0-5][0-9](?::?[0-5][0-9](?:[.,]\\d{1,9})?)?)?)/;\nconst timeZoneID = new RegExp(`(?:(?:${tzComponent.source})(?:\\\\/(?:${tzComponent.source}))*|Etc/GMT[-+]\\\\d{1,2}|${offsetNoCapture.source})`);\nconst calComponent = /[A-Za-z0-9]{3,8}/;\nconst calendarID = new RegExp(`(?:${calComponent.source}(?:-${calComponent.source})*)`);\nconst yearpart = /(?:[+\\u2212-]\\d{6}|\\d{4})/;\nconst monthpart = /(?:0[1-9]|1[0-2])/;\nconst daypart = /(?:0[1-9]|[12]\\d|3[01])/;\nconst datesplit = new RegExp(`(${yearpart.source})(?:-(${monthpart.source})-(${daypart.source})|(${monthpart.source})(${daypart.source}))`);\nconst timesplit = /(\\d{2})(?::(\\d{2})(?::(\\d{2})(?:[.,](\\d{1,9}))?)?|(\\d{2})(?:(\\d{2})(?:[.,](\\d{1,9}))?)?)?/;\nexport const offset = /([+\\u2212-])([01][0-9]|2[0-3])(?::?([0-5][0-9])(?::?([0-5][0-9])(?:[.,](\\d{1,9}))?)?)?/;\nconst zonesplit = new RegExp(`(?:([zZ])|(?:${offset.source})?)(?:\\\\[(${timeZoneID.source})\\\\])?`);\nconst calendar = new RegExp(`\\\\[u-ca=(${calendarID.source})\\\\]`);\nexport const zoneddatetime = new RegExp(`^${datesplit.source}(?:(?:T|\\\\s+)${timesplit.source})?${zonesplit.source}(?:${calendar.source})?$`, 'i');\nexport const time = new RegExp(`^T?${timesplit.source}(?:${zonesplit.source})?(?:${calendar.source})?$`, 'i');\n// The short forms of YearMonth and MonthDay are only for the ISO calendar.\n// Non-ISO calendar YearMonth and MonthDay have to parse as a Temporal.PlainDate,\n// with the reference fields.\n// YYYYMM forbidden by ISO 8601 because ambiguous with YYMMDD, but allowed by\n// RFC 3339 and we don't allow 2-digit years, so we allow it.\n// Not ambiguous with HHMMSS because that requires a 'T' prefix\nexport const yearmonth = new RegExp(`^(${yearpart.source})-?(${monthpart.source})$`);\nexport const monthday = new RegExp(`^(?:--)?(${monthpart.source})-?(${daypart.source})$`);\nconst fraction = /(\\d+)(?:[.,](\\d{1,9}))?/;\nconst durationDate = /(?:(\\d+)Y)?(?:(\\d+)M)?(?:(\\d+)W)?(?:(\\d+)D)?/;\nconst durationTime = new RegExp(`(?:${fraction.source}H)?(?:${fraction.source}M)?(?:${fraction.source}S)?`);\nexport const duration = new RegExp(`^([+\\u2212-])?P${durationDate.source}(?:T(?!$)${durationTime.source})?$`, 'i');\n//# sourceMappingURL=regex.js.map","const ArrayIncludes = Array.prototype.includes;\nconst ArrayPrototypePush = Array.prototype.push;\nconst IntlDateTimeFormat = globalThis.Intl.DateTimeFormat;\nconst MathMin = Math.min;\nconst MathMax = Math.max;\nconst MathAbs = Math.abs;\nconst MathFloor = Math.floor;\nconst MathSign = Math.sign;\nconst MathTrunc = Math.trunc;\nconst NumberIsNaN = Number.isNaN;\nconst NumberIsFinite = Number.isFinite;\nconst NumberCtor = Number;\nconst StringCtor = String;\nconst NumberMaxSafeInteger = Number.MAX_SAFE_INTEGER;\nconst ObjectAssign = Object.assign;\nconst ObjectCreate = Object.create;\nconst ObjectDefineProperty = Object.defineProperty;\nconst ObjectGetOwnPropertyDescriptor = Object.getOwnPropertyDescriptor;\nconst ObjectIs = Object.is;\nconst ReflectApply = Reflect.apply;\nimport { DEBUG } from './debug';\nimport JSBI from 'jsbi';\nimport { GetIntrinsic } from './intrinsicclass';\nimport { CreateSlots, GetSlot, HasSlot, SetSlot, EPOCHNANOSECONDS, TIMEZONE_ID, CALENDAR_ID, INSTANT, ISO_YEAR, ISO_MONTH, ISO_DAY, ISO_HOUR, ISO_MINUTE, ISO_SECOND, ISO_MILLISECOND, ISO_MICROSECOND, ISO_NANOSECOND, DATE_BRAND, YEAR_MONTH_BRAND, MONTH_DAY_BRAND, TIME_ZONE, CALENDAR, YEARS, MONTHS, WEEKS, DAYS, HOURS, MINUTES, SECONDS, MILLISECONDS, MICROSECONDS, NANOSECONDS } from './slots';\nexport const ZERO = JSBI.BigInt(0);\nconst ONE = JSBI.BigInt(1);\nconst SIXTY = JSBI.BigInt(60);\nexport const THOUSAND = JSBI.BigInt(1e3);\nexport const MILLION = JSBI.BigInt(1e6);\nexport const BILLION = JSBI.BigInt(1e9);\nconst NEGATIVE_ONE = JSBI.BigInt(-1);\nconst DAY_SECONDS = 86400;\nconst DAY_NANOS = JSBI.multiply(JSBI.BigInt(DAY_SECONDS), BILLION);\nconst NS_MIN = JSBI.multiply(JSBI.BigInt(-86400), JSBI.BigInt(1e17));\nconst NS_MAX = JSBI.multiply(JSBI.BigInt(86400), JSBI.BigInt(1e17));\nconst YEAR_MIN = -271821;\nconst YEAR_MAX = 275760;\nconst BEFORE_FIRST_OFFSET_TRANSITION = JSBI.multiply(JSBI.BigInt(-388152), JSBI.BigInt(1e13)); // 1847-01-01T00:00:00Z\nconst ABOUT_TEN_YEARS_NANOS = JSBI.multiply(DAY_NANOS, JSBI.BigInt(366 * 10));\nconst ABOUT_ONE_YEAR_NANOS = JSBI.multiply(DAY_NANOS, JSBI.BigInt(366 * 1));\nconst TWO_WEEKS_NANOS = JSBI.multiply(DAY_NANOS, JSBI.BigInt(2 * 7));\nconst BUILTIN_CALENDAR_IDS = [\n 'iso8601',\n 'hebrew',\n 'islamic',\n 'islamic-umalqura',\n 'islamic-tbla',\n 'islamic-civil',\n 'islamic-rgsa',\n 'islamicc',\n 'persian',\n 'ethiopic',\n 'ethioaa',\n 'coptic',\n 'chinese',\n 'dangi',\n 'roc',\n 'indian',\n 'buddhist',\n 'japanese',\n 'gregory'\n];\nfunction IsInteger(value) {\n if (typeof value !== 'number' || !NumberIsFinite(value))\n return false;\n const abs = MathAbs(value);\n return MathFloor(abs) === abs;\n}\nexport function IsObject(value) {\n return (typeof value === 'object' && value !== null) || typeof value === 'function';\n}\nexport function ToNumber(value) {\n if (typeof value === 'bigint')\n throw new TypeError('Cannot convert BigInt to number');\n return NumberCtor(value);\n}\nfunction ToInteger(value) {\n const num = ToNumber(value);\n if (NumberIsNaN(num))\n return 0;\n const integer = MathTrunc(num);\n if (num === 0)\n return 0;\n return integer;\n}\nexport function ToString(value) {\n if (typeof value === 'symbol') {\n throw new TypeError('Cannot convert a Symbol value to a String');\n }\n return StringCtor(value);\n}\nexport function ToIntegerThrowOnInfinity(value) {\n const integer = ToInteger(value);\n if (!NumberIsFinite(integer)) {\n throw new RangeError('infinity is out of range');\n }\n return integer;\n}\nfunction ToPositiveInteger(valueParam, property) {\n const value = ToInteger(valueParam);\n if (!NumberIsFinite(value)) {\n throw new RangeError('infinity is out of range');\n }\n if (value < 1) {\n if (property !== undefined) {\n throw new RangeError(`property '${property}' cannot be a a number less than one`);\n }\n throw new RangeError('Cannot convert a number less than one to a positive integer');\n }\n return value;\n}\nexport function ToIntegerWithoutRounding(valueParam) {\n const value = ToNumber(valueParam);\n if (NumberIsNaN(value))\n return 0;\n if (!NumberIsFinite(value)) {\n throw new RangeError('infinity is out of range');\n }\n if (!IsInteger(value)) {\n throw new RangeError(`unsupported fractional value ${value}`);\n }\n return ToInteger(value); // ℝ(value) in spec text; converts -0 to 0\n}\nfunction divmod(x, y) {\n const quotient = JSBI.divide(x, y);\n const remainder = JSBI.remainder(x, y);\n return { quotient, remainder };\n}\nfunction abs(x) {\n if (JSBI.lessThan(x, ZERO))\n return JSBI.multiply(x, NEGATIVE_ONE);\n return x;\n}\nexport function ArrayPush(arr, ...newItem) {\n ArrayPrototypePush.apply(arr, newItem);\n return arr;\n}\nconst BUILTIN_CASTS = new Map([\n ['year', ToIntegerThrowOnInfinity],\n ['month', ToPositiveInteger],\n ['monthCode', ToString],\n ['day', ToPositiveInteger],\n ['hour', ToIntegerThrowOnInfinity],\n ['minute', ToIntegerThrowOnInfinity],\n ['second', ToIntegerThrowOnInfinity],\n ['millisecond', ToIntegerThrowOnInfinity],\n ['microsecond', ToIntegerThrowOnInfinity],\n ['nanosecond', ToIntegerThrowOnInfinity],\n ['years', ToIntegerWithoutRounding],\n ['months', ToIntegerWithoutRounding],\n ['weeks', ToIntegerWithoutRounding],\n ['days', ToIntegerWithoutRounding],\n ['hours', ToIntegerWithoutRounding],\n ['minutes', ToIntegerWithoutRounding],\n ['seconds', ToIntegerWithoutRounding],\n ['milliseconds', ToIntegerWithoutRounding],\n ['microseconds', ToIntegerWithoutRounding],\n ['nanoseconds', ToIntegerWithoutRounding],\n ['era', ToString],\n ['eraYear', ToInteger],\n ['offset', ToString]\n]);\nconst BUILTIN_DEFAULTS = new Map([\n ['hour', 0],\n ['minute', 0],\n ['second', 0],\n ['millisecond', 0],\n ['microsecond', 0],\n ['nanosecond', 0]\n]);\n// each item is [plural, singular, category]\nconst SINGULAR_PLURAL_UNITS = [\n ['years', 'year', 'date'],\n ['months', 'month', 'date'],\n ['weeks', 'week', 'date'],\n ['days', 'day', 'date'],\n ['hours', 'hour', 'time'],\n ['minutes', 'minute', 'time'],\n ['seconds', 'second', 'time'],\n ['milliseconds', 'millisecond', 'time'],\n ['microseconds', 'microsecond', 'time'],\n ['nanoseconds', 'nanosecond', 'time']\n];\nconst SINGULAR_FOR = new Map(SINGULAR_PLURAL_UNITS.map((e) => [e[0], e[1]]));\nconst PLURAL_FOR = new Map(SINGULAR_PLURAL_UNITS.map(([p, s]) => [s, p]));\nconst UNITS_DESCENDING = SINGULAR_PLURAL_UNITS.map(([, s]) => s);\nconst DURATION_FIELDS = Array.from(SINGULAR_FOR.keys()).sort();\nimport * as PARSE from './regex';\nconst IntlDateTimeFormatEnUsCache = new Map();\nfunction getIntlDateTimeFormatEnUsForTimeZone(timeZoneIdentifier) {\n let instance = IntlDateTimeFormatEnUsCache.get(timeZoneIdentifier);\n if (instance === undefined) {\n instance = new IntlDateTimeFormat('en-us', {\n timeZone: StringCtor(timeZoneIdentifier),\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 IntlDateTimeFormatEnUsCache.set(timeZoneIdentifier, instance);\n }\n return instance;\n}\nexport function IsTemporalInstant(item) {\n return HasSlot(item, EPOCHNANOSECONDS) && !HasSlot(item, TIME_ZONE, CALENDAR);\n}\nexport function IsTemporalTimeZone(item) {\n return HasSlot(item, TIMEZONE_ID);\n}\nexport function IsTemporalCalendar(item) {\n return HasSlot(item, CALENDAR_ID);\n}\nexport function IsTemporalDuration(item) {\n return HasSlot(item, YEARS, MONTHS, DAYS, HOURS, MINUTES, SECONDS, MILLISECONDS, MICROSECONDS, NANOSECONDS);\n}\nexport function IsTemporalDate(item) {\n return HasSlot(item, DATE_BRAND);\n}\nexport function IsTemporalTime(item) {\n return (HasSlot(item, ISO_HOUR, ISO_MINUTE, ISO_SECOND, ISO_MILLISECOND, ISO_MICROSECOND, ISO_NANOSECOND) &&\n !HasSlot(item, ISO_YEAR, ISO_MONTH, ISO_DAY));\n}\nexport function IsTemporalDateTime(item) {\n return HasSlot(item, ISO_YEAR, ISO_MONTH, ISO_DAY, ISO_HOUR, ISO_MINUTE, ISO_SECOND, ISO_MILLISECOND, ISO_MICROSECOND, ISO_NANOSECOND);\n}\nexport function IsTemporalYearMonth(item) {\n return HasSlot(item, YEAR_MONTH_BRAND);\n}\nexport function IsTemporalMonthDay(item) {\n return HasSlot(item, MONTH_DAY_BRAND);\n}\nexport function IsTemporalZonedDateTime(item) {\n return HasSlot(item, EPOCHNANOSECONDS, TIME_ZONE, CALENDAR);\n}\nexport function RejectObjectWithCalendarOrTimeZone(item) {\n if (HasSlot(item, CALENDAR) || HasSlot(item, TIME_ZONE)) {\n throw new TypeError('with() does not support a calendar or timeZone property');\n }\n if (item.calendar !== undefined) {\n throw new TypeError('with() does not support a calendar property');\n }\n if (item.timeZone !== undefined) {\n throw new TypeError('with() does not support a timeZone property');\n }\n}\nfunction ParseTemporalTimeZone(stringIdent) {\n let { ianaName, offset, z } = ParseTemporalTimeZoneString(stringIdent);\n if (ianaName)\n return ianaName;\n if (z)\n return 'UTC';\n return offset; // if !ianaName && !z then offset must be present\n}\nfunction FormatCalendarAnnotation(id, showCalendar) {\n if (showCalendar === 'never')\n return '';\n if (showCalendar === 'auto' && id === 'iso8601')\n return '';\n return `[u-ca=${id}]`;\n}\nfunction ParseISODateTime(isoString) {\n // ZDT is the superset of fields for every other Temporal type\n const match = PARSE.zoneddatetime.exec(isoString);\n if (!match)\n throw new RangeError(`invalid ISO 8601 string: ${isoString}`);\n let yearString = match[1];\n if (yearString[0] === '\\u2212')\n yearString = `-${yearString.slice(1)}`;\n if (yearString === '-000000')\n throw new RangeError(`invalid ISO 8601 string: ${isoString}`);\n const year = ToInteger(yearString);\n const month = ToInteger(match[2] || match[4]);\n const day = ToInteger(match[3] || match[5]);\n const hour = ToInteger(match[6]);\n const hasTime = match[6] !== undefined;\n const minute = ToInteger(match[7] || match[10]);\n let second = ToInteger(match[8] || match[11]);\n if (second === 60)\n second = 59;\n const fraction = (match[9] || match[12]) + '000000000';\n const millisecond = ToInteger(fraction.slice(0, 3));\n const microsecond = ToInteger(fraction.slice(3, 6));\n const nanosecond = ToInteger(fraction.slice(6, 9));\n let offset;\n let z = false;\n if (match[13]) {\n offset = undefined;\n z = true;\n }\n else if (match[14] && match[15]) {\n const offsetSign = match[14] === '-' || match[14] === '\\u2212' ? '-' : '+';\n const offsetHours = match[15] || '00';\n const offsetMinutes = match[16] || '00';\n const offsetSeconds = match[17] || '00';\n let offsetFraction = match[18] || '0';\n offset = `${offsetSign}${offsetHours}:${offsetMinutes}`;\n if (+offsetFraction) {\n while (offsetFraction.endsWith('0'))\n offsetFraction = offsetFraction.slice(0, -1);\n offset += `:${offsetSeconds}.${offsetFraction}`;\n }\n else if (+offsetSeconds) {\n offset += `:${offsetSeconds}`;\n }\n if (offset === '-00:00')\n offset = '+00:00';\n }\n let ianaName = match[19];\n if (ianaName) {\n try {\n // Canonicalize name if it is an IANA link name or is capitalized wrong\n ianaName = GetCanonicalTimeZoneIdentifier(ianaName).toString();\n }\n catch {\n // Not an IANA name, may be a custom ID, pass through unchanged\n }\n }\n const calendar = match[20];\n RejectDateTime(year, month, day, hour, minute, second, millisecond, microsecond, nanosecond);\n return {\n year,\n month,\n day,\n hasTime,\n hour,\n minute,\n second,\n millisecond,\n microsecond,\n nanosecond,\n ianaName,\n offset,\n z,\n calendar\n };\n}\n// ts-prune-ignore-next TODO: remove if test/validStrings is converted to TS.\nexport function ParseTemporalInstantString(isoString) {\n const result = ParseISODateTime(isoString);\n if (!result.z && !result.offset)\n throw new RangeError('Temporal.Instant requires a time zone offset');\n return result;\n}\n// ts-prune-ignore-next TODO: remove if test/validStrings is converted to TS.\nexport function ParseTemporalZonedDateTimeString(isoString) {\n const result = ParseISODateTime(isoString);\n if (!result.ianaName)\n throw new RangeError('Temporal.ZonedDateTime requires a time zone ID in brackets');\n return result;\n}\n// ts-prune-ignore-next TODO: remove if test/validStrings is converted to TS.\nexport function ParseTemporalDateTimeString(isoString) {\n return ParseISODateTime(isoString);\n}\n// ts-prune-ignore-next TODO: remove if test/validStrings is converted to TS.\nexport function ParseTemporalDateString(isoString) {\n return ParseISODateTime(isoString);\n}\n// ts-prune-ignore-next TODO: remove if test/validStrings is converted to TS.\nexport function ParseTemporalTimeString(isoString) {\n const match = PARSE.time.exec(isoString);\n let hour, minute, second, millisecond, microsecond, nanosecond, calendar;\n if (match) {\n hour = ToInteger(match[1]);\n minute = ToInteger(match[2] || match[5]);\n second = ToInteger(match[3] || match[6]);\n if (second === 60)\n second = 59;\n const fraction = (match[4] || match[7]) + '000000000';\n millisecond = ToInteger(fraction.slice(0, 3));\n microsecond = ToInteger(fraction.slice(3, 6));\n nanosecond = ToInteger(fraction.slice(6, 9));\n calendar = match[15];\n }\n else {\n let z, hasTime;\n ({ hasTime, hour, minute, second, millisecond, microsecond, nanosecond, calendar, z } =\n ParseISODateTime(isoString));\n if (!hasTime)\n throw new RangeError(`time is missing in string: ${isoString}`);\n if (z)\n throw new RangeError('Z designator not supported for PlainTime');\n }\n // if it's a date-time string, OK\n if (/[tT ][0-9][0-9]/.test(isoString)) {\n return { hour, minute, second, millisecond, microsecond, nanosecond, calendar };\n }\n // slow but non-grammar-dependent way to ensure that time-only strings that\n // are also valid PlainMonthDay and PlainYearMonth throw. corresponds to\n // assertion in spec text\n try {\n const { month, day } = ParseTemporalMonthDayString(isoString);\n RejectISODate(1972, month, day);\n }\n catch {\n try {\n const { year, month } = ParseTemporalYearMonthString(isoString);\n RejectISODate(year, month, 1);\n }\n catch {\n return { hour, minute, second, millisecond, microsecond, nanosecond, calendar };\n }\n }\n throw new RangeError(`invalid ISO 8601 time-only string ${isoString}; may need a T prefix`);\n}\n// ts-prune-ignore-next TODO: remove if test/validStrings is converted to TS.\nexport function ParseTemporalYearMonthString(isoString) {\n const match = PARSE.yearmonth.exec(isoString);\n let year, month, calendar, referenceISODay;\n if (match) {\n let yearString = match[1];\n if (yearString[0] === '\\u2212')\n yearString = `-${yearString.slice(1)}`;\n if (yearString === '-000000')\n throw new RangeError(`invalid ISO 8601 string: ${isoString}`);\n year = ToInteger(yearString);\n month = ToInteger(match[2]);\n calendar = match[3];\n }\n else {\n let z;\n ({ year, month, calendar, day: referenceISODay, z } = ParseISODateTime(isoString));\n if (z)\n throw new RangeError('Z designator not supported for PlainYearMonth');\n }\n return { year, month, calendar, referenceISODay };\n}\n// ts-prune-ignore-next TODO: remove if test/validStrings is converted to TS.\nexport function ParseTemporalMonthDayString(isoString) {\n const match = PARSE.monthday.exec(isoString);\n let month, day, calendar, referenceISOYear;\n if (match) {\n month = ToInteger(match[1]);\n day = ToInteger(match[2]);\n }\n else {\n let z;\n ({ month, day, calendar, year: referenceISOYear, z } = ParseISODateTime(isoString));\n if (z)\n throw new RangeError('Z designator not supported for PlainMonthDay');\n }\n return { month, day, calendar, referenceISOYear };\n}\n// ts-prune-ignore-next TODO: remove if test/validStrings is converted to TS.\nexport function ParseTemporalTimeZoneString(stringIdent) {\n try {\n let canonicalIdent = GetCanonicalTimeZoneIdentifier(stringIdent);\n if (canonicalIdent)\n return { ianaName: canonicalIdent.toString() };\n }\n catch {\n // fall through\n }\n try {\n // Try parsing ISO string instead\n const result = ParseISODateTime(stringIdent);\n if (result.z || result.offset || result.ianaName) {\n return result;\n }\n }\n catch {\n // fall through\n }\n throw new RangeError(`Invalid time zone: ${stringIdent}`);\n}\n// ts-prune-ignore-next TODO: remove if test/validStrings is converted to TS.\nexport function ParseTemporalDurationString(isoString) {\n const match = PARSE.duration.exec(isoString);\n if (!match)\n throw new RangeError(`invalid duration: ${isoString}`);\n if (match.slice(2).every((element) => element === undefined)) {\n throw new RangeError(`invalid duration: ${isoString}`);\n }\n const sign = match[1] === '-' || match[1] === '\\u2212' ? -1 : 1;\n const years = ToInteger(match[2]) * sign;\n const months = ToInteger(match[3]) * sign;\n const weeks = ToInteger(match[4]) * sign;\n const days = ToInteger(match[5]) * sign;\n const hours = ToInteger(match[6]) * sign;\n let fHours = match[7];\n let minutes = ToInteger(match[8]) * sign;\n let fMinutes = match[9];\n let seconds = ToInteger(match[10]) * sign;\n const fSeconds = match[11] + '000000000';\n let milliseconds = ToInteger(fSeconds.slice(0, 3)) * sign;\n let microseconds = ToInteger(fSeconds.slice(3, 6)) * sign;\n let nanoseconds = ToInteger(fSeconds.slice(6, 9)) * sign;\n fHours = fHours ? (sign * ToInteger(fHours)) / 10 ** fHours.length : 0;\n fMinutes = fMinutes ? (sign * ToInteger(fMinutes)) / 10 ** fMinutes.length : 0;\n ({ minutes, seconds, milliseconds, microseconds, nanoseconds } = DurationHandleFractions(fHours, minutes, fMinutes, seconds, milliseconds, microseconds, nanoseconds));\n RejectDuration(years, months, weeks, days, hours, minutes, seconds, milliseconds, microseconds, nanoseconds);\n return { years, months, weeks, days, hours, minutes, seconds, milliseconds, microseconds, nanoseconds };\n}\n// ts-prune-ignore-next TODO: remove if test/validStrings is converted to TS.\nexport function ParseTemporalInstant(isoString) {\n let { year, month, day, hour, minute, second, millisecond, microsecond, nanosecond, offset, z } = ParseTemporalInstantString(isoString);\n if (!z && !offset)\n throw new RangeError('Temporal.Instant requires a time zone offset');\n // At least one of z or offset is defined, but TS doesn't seem to understand\n // that we only use offset if z is not defined (and thus offset must be defined).\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n const offsetNs = z ? 0 : ParseTimeZoneOffsetString(offset);\n ({ year, month, day, hour, minute, second, millisecond, microsecond, nanosecond } = BalanceISODateTime(year, month, day, hour, minute, second, millisecond, microsecond, nanosecond - offsetNs));\n const epochNs = GetEpochFromISOParts(year, month, day, hour, minute, second, millisecond, microsecond, nanosecond);\n if (epochNs === null)\n throw new RangeError('DateTime outside of supported range');\n return epochNs;\n}\nexport function RegulateISODate(yearParam, monthParam, dayParam, overflow) {\n let year = yearParam;\n let month = monthParam;\n let day = dayParam;\n switch (overflow) {\n case 'reject':\n RejectISODate(year, month, day);\n break;\n case 'constrain':\n ({ year, month, day } = ConstrainISODate(year, month, day));\n break;\n }\n return { year, month, day };\n}\nexport function RegulateTime(hourParam, minuteParam, secondParam, millisecondParam, microsecondParam, nanosecondParam, overflow) {\n let hour = hourParam;\n let minute = minuteParam;\n let second = secondParam;\n let millisecond = millisecondParam;\n let microsecond = microsecondParam;\n let nanosecond = nanosecondParam;\n switch (overflow) {\n case 'reject':\n RejectTime(hour, minute, second, millisecond, microsecond, nanosecond);\n break;\n case 'constrain':\n ({ hour, minute, second, millisecond, microsecond, nanosecond } = ConstrainTime(hour, minute, second, millisecond, microsecond, nanosecond));\n break;\n }\n return { hour, minute, second, millisecond, microsecond, nanosecond };\n}\nexport function RegulateISOYearMonth(yearParam, monthParam, overflow) {\n let year = yearParam;\n let month = monthParam;\n const referenceISODay = 1;\n switch (overflow) {\n case 'reject':\n RejectISODate(year, month, referenceISODay);\n break;\n case 'constrain':\n ({ year, month } = ConstrainISODate(year, month));\n break;\n }\n return { year, month };\n}\nfunction DurationHandleFractions(fHoursParam, minutesParam, fMinutesParam, secondsParam, millisecondsParam, microsecondsParam, nanosecondsParam) {\n let fHours = fHoursParam;\n let minutes = minutesParam;\n let fMinutes = fMinutesParam;\n let seconds = secondsParam;\n let milliseconds = millisecondsParam;\n let microseconds = microsecondsParam;\n let nanoseconds = nanosecondsParam;\n if (fHours !== 0) {\n [minutes, fMinutes, seconds, milliseconds, microseconds, nanoseconds].forEach((val) => {\n if (val !== 0)\n throw new RangeError('only the smallest unit can be fractional');\n });\n const mins = fHours * 60;\n minutes = MathTrunc(mins);\n fMinutes = mins % 1;\n }\n if (fMinutes !== 0) {\n [seconds, milliseconds, microseconds, nanoseconds].forEach((val) => {\n if (val !== 0)\n throw new RangeError('only the smallest unit can be fractional');\n });\n const secs = fMinutes * 60;\n seconds = MathTrunc(secs);\n const fSeconds = secs % 1;\n if (fSeconds !== 0) {\n const mils = fSeconds * 1000;\n milliseconds = MathTrunc(mils);\n const fMilliseconds = mils % 1;\n if (fMilliseconds !== 0) {\n const mics = fMilliseconds * 1000;\n microseconds = MathTrunc(mics);\n const fMicroseconds = mics % 1;\n if (fMicroseconds !== 0) {\n const nans = fMicroseconds * 1000;\n nanoseconds = MathTrunc(nans);\n }\n }\n }\n }\n return { minutes, seconds, milliseconds, microseconds, nanoseconds };\n}\nfunction ToTemporalDurationRecord(item) {\n if (!IsObject(item)) {\n return ParseTemporalDurationString(ToString(item));\n }\n if (IsTemporalDuration(item)) {\n return {\n years: GetSlot(item, YEARS),\n months: GetSlot(item, MONTHS),\n weeks: GetSlot(item, WEEKS),\n days: GetSlot(item, DAYS),\n hours: GetSlot(item, HOURS),\n minutes: GetSlot(item, MINUTES),\n seconds: GetSlot(item, SECONDS),\n milliseconds: GetSlot(item, MILLISECONDS),\n microseconds: GetSlot(item, MICROSECONDS),\n nanoseconds: GetSlot(item, NANOSECONDS)\n };\n }\n const result = {\n years: 0,\n months: 0,\n weeks: 0,\n days: 0,\n hours: 0,\n minutes: 0,\n seconds: 0,\n milliseconds: 0,\n microseconds: 0,\n nanoseconds: 0\n };\n let partial = ToTemporalPartialDurationRecord(item);\n for (const property of DURATION_FIELDS) {\n const value = partial[property];\n if (value !== undefined) {\n result[property] = value;\n }\n }\n let { years, months, weeks, days, hours, minutes, seconds, milliseconds, microseconds, nanoseconds } = result;\n RejectDuration(years, months, weeks, days, hours, minutes, seconds, milliseconds, microseconds, nanoseconds);\n return { years, months, weeks, days, hours, minutes, seconds, milliseconds, microseconds, nanoseconds };\n}\nfunction ToTemporalPartialDurationRecord(temporalDurationLike) {\n if (!IsObject(temporalDurationLike)) {\n throw new TypeError('invalid duration-like');\n }\n const result = {\n years: undefined,\n months: undefined,\n weeks: undefined,\n days: undefined,\n hours: undefined,\n minutes: undefined,\n seconds: undefined,\n milliseconds: undefined,\n microseconds: undefined,\n nanoseconds: undefined\n };\n let any = false;\n for (const property of DURATION_FIELDS) {\n const value = temporalDurationLike[property];\n if (value !== undefined) {\n any = true;\n result[property] = ToIntegerWithoutRounding(value);\n }\n }\n if (!any) {\n throw new TypeError('invalid duration-like');\n }\n return result;\n}\nfunction ToLimitedTemporalDuration(item, disallowedProperties) {\n let record = ToTemporalDurationRecord(item);\n for (const property of disallowedProperties) {\n if (record[property] !== 0) {\n throw new RangeError(`Duration field ${property} not supported by Temporal.Instant. Try Temporal.ZonedDateTime instead.`);\n }\n }\n return record;\n}\nexport function ToTemporalOverflow(options) {\n if (options === undefined)\n return 'constrain';\n return GetOption(options, 'overflow', ['constrain', 'reject'], 'constrain');\n}\nexport function ToTemporalDisambiguation(options) {\n if (options === undefined)\n return 'compatible';\n return GetOption(options, 'disambiguation', ['compatible', 'earlier', 'later', 'reject'], 'compatible');\n}\nexport function ToTemporalRoundingMode(options, fallback) {\n return GetOption(options, 'roundingMode', ['ceil', 'floor', 'trunc', 'halfExpand'], fallback);\n}\nfunction NegateTemporalRoundingMode(roundingMode) {\n switch (roundingMode) {\n case 'ceil':\n return 'floor';\n case 'floor':\n return 'ceil';\n default:\n return roundingMode;\n }\n}\nexport function ToTemporalOffset(options, fallback) {\n if (options === undefined)\n return fallback;\n return GetOption(options, 'offset', ['prefer', 'use', 'ignore', 'reject'], fallback);\n}\nexport function ToShowCalendarOption(options) {\n return GetOption(options, 'calendarName', ['auto', 'always', 'never'], 'auto');\n}\nexport function ToShowTimeZoneNameOption(options) {\n return GetOption(options, 'timeZoneName', ['auto', 'never'], 'auto');\n}\nexport function ToShowOffsetOption(options) {\n return GetOption(options, 'offset', ['auto', 'never'], 'auto');\n}\nexport function ToTemporalRoundingIncrement(options, dividend, inclusive) {\n let maximum = Infinity;\n if (dividend !== undefined)\n maximum = dividend;\n if (!inclusive && dividend !== undefined)\n maximum = dividend > 1 ? dividend - 1 : 1;\n const increment = GetNumberOption(options, 'roundingIncrement', 1, maximum, 1);\n if (dividend !== undefined && dividend % increment !== 0) {\n throw new RangeError(`Rounding increment must divide evenly into ${dividend}`);\n }\n return increment;\n}\nexport function ToTemporalDateTimeRoundingIncrement(options, smallestUnit) {\n const maximumIncrements = {\n year: undefined,\n month: undefined,\n week: undefined,\n day: undefined,\n hour: 24,\n minute: 60,\n second: 60,\n millisecond: 1000,\n microsecond: 1000,\n nanosecond: 1000\n };\n return ToTemporalRoundingIncrement(options, maximumIncrements[smallestUnit], false);\n}\nexport function ToSecondsStringPrecision(options) {\n const smallestUnit = GetTemporalUnit(options, 'smallestUnit', 'time', undefined);\n if (smallestUnit === 'hour') {\n const ALLOWED_UNITS = SINGULAR_PLURAL_UNITS.reduce((allowed, [p, s, c]) => {\n // Weirdly, local type inference seems to understand the types of s and p, but tsc still complains.\n // Maybe this is fixed in later TS versions?\n if (c === 'time' && s !== 'hour') {\n allowed.push(s, p);\n }\n return allowed;\n }, []);\n throw new RangeError(`smallestUnit must be one of ${ALLOWED_UNITS.join(', ')}, not ${smallestUnit}`);\n }\n switch (smallestUnit) {\n case 'minute':\n return { precision: 'minute', unit: 'minute', increment: 1 };\n case 'second':\n return { precision: 0, unit: 'second', increment: 1 };\n case 'millisecond':\n return { precision: 3, unit: 'millisecond', increment: 1 };\n case 'microsecond':\n return { precision: 6, unit: 'microsecond', increment: 1 };\n case 'nanosecond':\n return { precision: 9, unit: 'nanosecond', increment: 1 };\n default: // fall through if option not given\n }\n let digits = options.fractionalSecondDigits;\n if (digits === undefined)\n digits = 'auto';\n if (typeof digits !== 'number') {\n const stringDigits = ToString(digits);\n if (stringDigits === 'auto')\n return { precision: 'auto', unit: 'nanosecond', increment: 1 };\n throw new RangeError(`fractionalSecondDigits must be 'auto' or 0 through 9, not ${stringDigits}`);\n }\n if (NumberIsNaN(digits) || digits < 0 || digits > 9) {\n throw new RangeError(`fractionalSecondDigits must be 'auto' or 0 through 9, not ${digits}`);\n }\n const precision = MathFloor(digits);\n switch (precision) {\n case 0:\n return { precision, unit: 'second', increment: 1 };\n case 1:\n case 2:\n case 3:\n return { precision, unit: 'millisecond', increment: 10 ** (3 - precision) };\n case 4:\n case 5:\n case 6:\n return { precision, unit: 'microsecond', increment: 10 ** (6 - precision) };\n case 7:\n case 8:\n case 9:\n return { precision, unit: 'nanosecond', increment: 10 ** (9 - precision) };\n default:\n throw new RangeError(`fractionalSecondDigits must be 'auto' or 0 through 9, not ${digits}`);\n }\n}\nexport const REQUIRED = Symbol('~required~');\n// This signature of the function is NOT used in type-checking, so restricting\n// the default value via generic binding like the other overloads isn't\n// necessary.\nexport function GetTemporalUnit(options, key, unitGroup, requiredOrDefault, extraValues = []) {\n const allowedSingular = [];\n for (const [, singular, category] of SINGULAR_PLURAL_UNITS) {\n if (unitGroup === 'datetime' || unitGroup === category) {\n allowedSingular.push(singular);\n }\n }\n allowedSingular.push(...extraValues);\n let defaultVal = requiredOrDefault;\n if (defaultVal === REQUIRED) {\n defaultVal = undefined;\n }\n else if (defaultVal !== undefined) {\n allowedSingular.push(defaultVal);\n }\n const allowedValues = [\n ...allowedSingular\n ];\n for (const singular of allowedSingular) {\n const plural = PLURAL_FOR.get(singular);\n if (plural !== undefined)\n allowedValues.push(plural);\n }\n let retval = GetOption(options, key, allowedValues, defaultVal);\n if (retval === undefined && requiredOrDefault === REQUIRED) {\n throw new RangeError(`${key} is required`);\n }\n // Coerce any plural units into their singular form\n if (SINGULAR_FOR.has(retval)) {\n // We just has-checked this, but tsc doesn't understand that.\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n return SINGULAR_FOR.get(retval);\n }\n return retval;\n}\nexport function ToRelativeTemporalObject(options) {\n const relativeTo = options.relativeTo;\n if (relativeTo === undefined)\n return relativeTo;\n let offsetBehaviour = 'option';\n let matchMinutes = false;\n let year, month, day, hour, minute, second, millisecond, microsecond, nanosecond, calendar, timeZone, offset;\n if (IsObject(relativeTo)) {\n if (IsTemporalZonedDateTime(relativeTo) || IsTemporalDate(relativeTo))\n return relativeTo;\n if (IsTemporalDateTime(relativeTo))\n return TemporalDateTimeToDate(relativeTo);\n calendar = GetTemporalCalendarWithISODefault(relativeTo);\n const fieldNames = CalendarFields(calendar, [\n 'day',\n 'hour',\n 'microsecond',\n 'millisecond',\n 'minute',\n 'month',\n 'monthCode',\n 'nanosecond',\n 'second',\n 'year'\n ]);\n const fields = PrepareTemporalFields(relativeTo, fieldNames, []);\n const dateOptions = ObjectCreate(null);\n dateOptions.overflow = 'constrain';\n ({ year, month, day, hour, minute, second, millisecond, microsecond, nanosecond } = InterpretTemporalDateTimeFields(calendar, fields, dateOptions));\n // The `offset` and `timeZone` properties only exist on ZonedDateTime (or\n // ZonedDateTimeLike-property bags). The assertions below are used to avoid\n // TS errors while not diverging runtime code from proposal-temporal.\n offset = relativeTo.offset;\n if (offset === undefined)\n offsetBehaviour = 'wall';\n timeZone = relativeTo.timeZone;\n }\n else {\n let ianaName, z;\n ({ year, month, day, hour, minute, second, millisecond, microsecond, nanosecond, calendar, ianaName, offset, z } =\n ParseISODateTime(ToString(relativeTo)));\n if (ianaName)\n timeZone = ianaName;\n if (z) {\n offsetBehaviour = 'exact';\n }\n else if (!offset) {\n offsetBehaviour = 'wall';\n }\n if (!calendar)\n calendar = GetISO8601Calendar();\n calendar = ToTemporalCalendar(calendar);\n matchMinutes = true;\n }\n if (timeZone !== undefined) {\n timeZone = ToTemporalTimeZone(timeZone);\n let offsetNs = 0;\n if (offsetBehaviour === 'option')\n offsetNs = ParseTimeZoneOffsetString(ToString(offset));\n const epochNanoseconds = InterpretISODateTimeOffset(year, month, day, hour, minute, second, millisecond, microsecond, nanosecond, offsetBehaviour, offsetNs, timeZone, 'compatible', 'reject', matchMinutes);\n return CreateTemporalZonedDateTime(epochNanoseconds, timeZone, calendar);\n }\n return CreateTemporalDate(year, month, day, calendar);\n}\nexport function DefaultTemporalLargestUnit(years, months, weeks, days, hours, minutes, seconds, milliseconds, microseconds, nanoseconds) {\n for (const [prop, v] of [\n ['years', years],\n ['months', months],\n ['weeks', weeks],\n ['days', days],\n ['hours', hours],\n ['minutes', minutes],\n ['seconds', seconds],\n ['milliseconds', milliseconds],\n ['microseconds', microseconds],\n ['nanoseconds', nanoseconds]\n ]) {\n if (v !== 0) {\n // All the above keys are definitely in SINGULAR_FOR\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n return SINGULAR_FOR.get(prop);\n }\n }\n return 'nanosecond';\n}\nexport function LargerOfTwoTemporalUnits(unit1, unit2) {\n if (UNITS_DESCENDING.indexOf(unit1) > UNITS_DESCENDING.indexOf(unit2))\n return unit2;\n return unit1;\n}\nfunction MergeLargestUnitOption(optionsParam, largestUnit) {\n let options = optionsParam;\n if (options === undefined)\n options = ObjectCreate(null);\n return ObjectAssign(ObjectCreate(null), options, { largestUnit });\n}\nexport function PrepareTemporalFields(bag, fields, requiredFields, { emptySourceErrorMessage } = { emptySourceErrorMessage: 'no supported properties found' }) {\n const result = ObjectCreate(null);\n let any = false;\n for (const property of fields) {\n let value = bag[property];\n if (value !== undefined) {\n any = true;\n if (BUILTIN_CASTS.has(property)) {\n // We just has-checked this map access, so there will definitely be a\n // value.\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n value = BUILTIN_CASTS.get(property)(value);\n }\n result[property] = value;\n }\n else if (requiredFields !== 'partial') {\n // TODO: using .call in this way is not correctly type-checked by tsc.\n // We might need a type-safe Call wrapper?\n if (ArrayIncludes.call(requiredFields, property)) {\n throw new TypeError(`required property '${property}' missing or undefined`);\n }\n value = BUILTIN_DEFAULTS.get(property);\n result[property] = value;\n }\n }\n if (requiredFields === 'partial' && !any) {\n throw new TypeError(emptySourceErrorMessage);\n }\n if ((result.era === undefined) !== (result.eraYear === undefined)) {\n throw new RangeError(\"properties 'era' and 'eraYear' must be provided together\");\n }\n return result;\n}\nexport function ToTemporalTimeRecord(bag, completeness = 'complete') {\n // NOTE: Field order here is important.\n const fields = ['hour', 'microsecond', 'millisecond', 'minute', 'nanosecond', 'second'];\n const partial = PrepareTemporalFields(bag, fields, 'partial', { emptySourceErrorMessage: 'invalid time-like' });\n const result = {};\n for (const field of fields) {\n const valueDesc = ObjectGetOwnPropertyDescriptor(partial, field);\n if (valueDesc !== undefined) {\n result[field] = valueDesc.value;\n }\n else if (completeness === 'complete') {\n result[field] = 0;\n }\n }\n return result;\n}\nexport function ToTemporalDate(itemParam, options) {\n let item = itemParam;\n if (IsObject(item)) {\n if (IsTemporalDate(item))\n return item;\n if (IsTemporalZonedDateTime(item)) {\n ToTemporalOverflow(options); // validate and ignore\n item = BuiltinTimeZoneGetPlainDateTimeFor(GetSlot(item, TIME_ZONE), GetSlot(item, INSTANT), GetSlot(item, CALENDAR));\n }\n if (IsTemporalDateTime(item)) {\n ToTemporalOverflow(options); // validate and ignore\n return CreateTemporalDate(GetSlot(item, ISO_YEAR), GetSlot(item, ISO_MONTH), GetSlot(item, ISO_DAY), GetSlot(item, CALENDAR));\n }\n const calendar = GetTemporalCalendarWithISODefault(item);\n const fieldNames = CalendarFields(calendar, ['day', 'month', 'monthCode', 'year']);\n const fields = PrepareTemporalFields(item, fieldNames, []);\n return CalendarDateFromFields(calendar, fields, options);\n }\n ToTemporalOverflow(options); // validate and ignore\n const { year, month, day, calendar, z } = ParseTemporalDateString(ToString(item));\n if (z)\n throw new RangeError('Z designator not supported for PlainDate');\n const TemporalPlainDate = GetIntrinsic('%Temporal.PlainDate%');\n return new TemporalPlainDate(year, month, day, calendar); // include validation\n}\nexport function InterpretTemporalDateTimeFields(calendar, fields, options) {\n let { hour, minute, second, millisecond, microsecond, nanosecond } = ToTemporalTimeRecord(fields);\n const overflow = ToTemporalOverflow(options);\n const date = CalendarDateFromFields(calendar, fields, options);\n const year = GetSlot(date, ISO_YEAR);\n const month = GetSlot(date, ISO_MONTH);\n const day = GetSlot(date, ISO_DAY);\n ({ hour, minute, second, millisecond, microsecond, nanosecond } = RegulateTime(hour, minute, second, millisecond, microsecond, nanosecond, overflow));\n return { year, month, day, hour, minute, second, millisecond, microsecond, nanosecond };\n}\nexport function ToTemporalDateTime(item, options) {\n let year, month, day, hour, minute, second, millisecond, microsecond, nanosecond, calendar;\n if (IsObject(item)) {\n if (IsTemporalDateTime(item))\n return item;\n if (IsTemporalZonedDateTime(item)) {\n ToTemporalOverflow(options); // validate and ignore\n return BuiltinTimeZoneGetPlainDateTimeFor(GetSlot(item,