{"ast":null,"code":"import { isValid } from \"./isValid.mjs\";\nimport { toDate } from \"./toDate.mjs\";\nimport { addLeadingZeros } from \"./_lib/addLeadingZeros.mjs\";\n\n/**\n * The {@link formatISO9075} function options.\n */\n\n/**\n * @name formatISO9075\n * @category Common Helpers\n * @summary Format the date according to the ISO 9075 standard (https://dev.mysql.com/doc/refman/5.7/en/date-and-time-functions.html#function_get-format).\n *\n * @description\n * Return the formatted date string in ISO 9075 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\n *\n * @throws `date` must not be Invalid Date\n *\n * @example\n * // Represent 18 September 2019 in ISO 9075 format:\n * const result = formatISO9075(new Date(2019, 8, 18, 19, 0, 52))\n * //=> '2019-09-18 19:00:52'\n *\n * @example\n * // Represent 18 September 2019 in ISO 9075, short format:\n * const result = formatISO9075(new Date(2019, 8, 18, 19, 0, 52), { format: 'basic' })\n * //=> '20190918 190052'\n *\n * @example\n * // Represent 18 September 2019 in ISO 9075 format, date only:\n * const result = formatISO9075(new Date(2019, 8, 18, 19, 0, 52), { representation: 'date' })\n * //=> '2019-09-18'\n *\n * @example\n * // Represent 18 September 2019 in ISO 9075 format, time only:\n * const result = formatISO9075(new Date(2019, 8, 18, 19, 0, 52), { representation: 'time' })\n * //=> '19:00:52'\n */\nexport function formatISO9075(date, options) {\n  const _date = toDate(date);\n  if (!isValid(_date)) {\n    throw new RangeError(\"Invalid time value\");\n  }\n  const format = options?.format ?? \"extended\";\n  const representation = options?.representation ?? \"complete\";\n  let result = \"\";\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    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 a space\n    const separator = result === \"\" ? \"\" : \" \";\n\n    // HHmmss or HH:mm:ss.\n    result = `${result}${separator}${hour}${timeDelimiter}${minute}${timeDelimiter}${second}`;\n  }\n  return result;\n}\n\n// Fallback for modularized imports:\nexport default formatISO9075;","map":null,"metadata":{},"sourceType":"module","externalDependencies":[]}