{"ast":null,"code":"import { toDate } from \"./toDate.mjs\";\nimport { addLeadingZeros } from \"./_lib/addLeadingZeros.mjs\";\n\n/**\n * The {@link formatISO} function options.\n */\n\n/**\n * @name formatISO\n * @category Common Helpers\n * @summary Format the date according to the ISO 8601 standard (https://support.sas.com/documentation/cdl/en/lrdict/64316/HTML/default/viewer.htm#a003169814.htm).\n *\n * @description\n * Return the formatted date string in ISO 8601 format. Options may be passed to control the parts and notations of the date.\n *\n * @typeParam DateType - The `Date` type, the function operates on. Gets inferred from passed arguments. Allows to use extensions like [`UTCDate`](https://github.com/date-fns/utc).\n *\n * @param date - The original date\n * @param options - An object with options.\n *\n * @returns The formatted date string (in loca.l time zone)\n *\n * @throws `date` must not be Invalid Date\n *\n * @example\n * // Represent 18 September 2019 in ISO 8601 format (local time zone is UTC):\n * const result = formatISO(new Date(2019, 8, 18, 19, 0, 52))\n * //=> '2019-09-18T19:00:52Z'\n *\n * @example\n * // Represent 18 September 2019 in ISO 8601, short format (local time zone is UTC):\n * const result = formatISO(new Date(2019, 8, 18, 19, 0, 52), { format: 'basic' })\n * //=> '20190918T190052'\n *\n * @example\n * // Represent 18 September 2019 in ISO 8601 format, date only:\n * const result = formatISO(new Date(2019, 8, 18, 19, 0, 52), { representation: 'date' })\n * //=> '2019-09-18'\n *\n * @example\n * // Represent 18 September 2019 in ISO 8601 format, time only (local time zone is UTC):\n * const result = formatISO(new Date(2019, 8, 18, 19, 0, 52), { representation: 'time' })\n * //=> '19:00:52Z'\n */\nexport function formatISO(date, options) {\n  const _date = toDate(date);\n  if (isNaN(_date.getTime())) {\n    throw new RangeError(\"Invalid time value\");\n  }\n  const format = options?.format ?? \"extended\";\n  const representation = options?.representation ?? \"complete\";\n  let result = \"\";\n  let tzOffset = \"\";\n  const dateDelimiter = format === \"extended\" ? \"-\" : \"\";\n  const timeDelimiter = format === \"extended\" ? \":\" : \"\";\n\n  // Representation is either 'date' or 'complete'\n  if (representation !== \"time\") {\n    const day = addLeadingZeros(_date.getDate(), 2);\n    const month = addLeadingZeros(_date.getMonth() + 1, 2);\n    const year = addLeadingZeros(_date.getFullYear(), 4);\n\n    // yyyyMMdd or yyyy-MM-dd.\n    result = `${year}${dateDelimiter}${month}${dateDelimiter}${day}`;\n  }\n\n  // Representation is either 'time' or 'complete'\n  if (representation !== \"date\") {\n    // Add the timezone.\n    const offset = _date.getTimezoneOffset();\n    if (offset !== 0) {\n      const absoluteOffset = Math.abs(offset);\n      const hourOffset = addLeadingZeros(Math.trunc(absoluteOffset / 60), 2);\n      const minuteOffset = addLeadingZeros(absoluteOffset % 60, 2);\n      // If less than 0, the sign is +, because it is ahead of time.\n      const sign = offset < 0 ? \"+\" : \"-\";\n      tzOffset = `${sign}${hourOffset}:${minuteOffset}`;\n    } else {\n      tzOffset = \"Z\";\n    }\n    const hour = addLeadingZeros(_date.getHours(), 2);\n    const minute = addLeadingZeros(_date.getMinutes(), 2);\n    const second = addLeadingZeros(_date.getSeconds(), 2);\n\n    // If there's also date, separate it with time with 'T'\n    const separator = result === \"\" ? \"\" : \"T\";\n\n    // Creates a time string consisting of hour, minute, and second, separated by delimiters, if defined.\n    const time = [hour, minute, second].join(timeDelimiter);\n\n    // HHmmss or HH:mm:ss.\n    result = `${result}${separator}${time}${tzOffset}`;\n  }\n  return result;\n}\n\n// Fallback for modularized imports:\nexport default formatISO;","map":null,"metadata":{},"sourceType":"module","externalDependencies":[]}