{"version":3,"file":"dateUtils.mjs","names":["DateTime","formatDateLong","value","date","Date","day","toLocaleString","month","year","dayOfWeek","weekday","error","formatDate","formatStr","toLowerCase","getDate","getMonth","getFullYear","toISOString","split","getDaysDiff","dateOne","dateTwo","d1","d2","diff","getTime","getDateFromString","dateString","length","fromISO","toJSDate","getLocalizedDateString","timeZone","convertedDate","fromJSDate","zone","DATE_SHORT","getLocalizedDateTime","convertedDateTime","getLocalizedDateTimeString","delimiter","includeOffset","TIME_WITH_SECONDS","offsetNameShort","DATETIME_SHORT_WITH_SECONDS","getLocalizedTimeString"],"sources":["../../../../src/UI/widgets/utils/dateUtils.js"],"sourcesContent":["import { DateTime } from 'luxon'\n\nexport function formatDateLong(value) {\n  try {\n    let date = new Date(value);\n    const day = date.toLocaleString('default', { day: '2-digit' });\n    const month = date.toLocaleString('default', { month: 'short' });\n    const year = date.toLocaleString('default', { year: 'numeric' });\n    const dayOfWeek = date.toLocaleString('default', { weekday: 'long' });\n    return `${day} ${month}, ${year} (${dayOfWeek})`;\n  } catch (error) {\n    return '';\n  }\n}\n\nexport function formatDate(value, formatStr = '') {\n  try {\n    let date = new Date(value);\n    const day = date.toLocaleString('default', { day: '2-digit' });\n    const month = date.toLocaleString('default', { month: 'short' });\n    const year = date.toLocaleString('default', { year: 'numeric' });\n\n    switch (formatStr.toLowerCase()) {\n      case 'mon dd, yyyy':\n        return `${day} ${month}, ${year}`;\n      case 'dd/mm/yyyy':\n        return `${date.getDate()}/${date.getMonth() + 1}/${date.getFullYear()}`;\n      case 'yyyy-mm-dd':\n        return date.toISOString().split('T')[0];\n      default:\n        return '';\n    }\n  } catch (error) {\n    return '';\n  }\n}\n\nexport function getDaysDiff(dateOne, dateTwo) {\n  const d1 = new Date(dateOne);\n  const d2 = new Date(dateTwo);\n  const diff = d2.getTime() - d1.getTime();\n\n  return diff / (1000 * 60 * 60 * 24);\n}\n\n/**\n * Creates a Date object based on an ISO 8601 date string.\n * @param dateString A ISO 8601 date string. EX: yyyy-MM-ddThh:mm:ss[Z|offset]\n * @returns A date object, or null if the format was invalid.\n */\nexport const getDateFromString = (dateString) => {\n  if (!dateString || dateString.length === 0) {\n    return null;\n  }\n\n  const date = DateTime.fromISO(dateString);\n\n  return date ? date.toJSDate() : null;\n};\n\n/**\n * Formats a date string by converting it to a date in the specified time zone,\n * stripping out the time element and returning a localized date string.\n * @param date A Date or ISO 8601 date string. EX: yyyy-MM-ddThh:mm:ss[Z|offset]\n * @param timeZone An IANA time zone id. If supplied, convert the date into the specified time zone,\n * otherwise convert to local browser time.\n * @returns A date string without time based on the supplied time zone and the\n * user's browser locale settings.\n */\nexport const getLocalizedDateString = (date, timeZone = 'local') => {\n  const convertedDate = date instanceof Date ? date : getDateFromString(date);\n\n  return convertedDate\n    ? DateTime.fromJSDate(convertedDate, { zone: timeZone }).toLocaleString(DateTime.DATE_SHORT)\n    : '';\n};\n\n/**\n * Converts a date string to a date in the specified timezone,\n * and returning a converted date with the localized date and time.\n * @param date A Date or ISO 8601 date string. EX: yyyy-MM-ddThh:mm:ss[Z|offset]\n * @param timeZone If supplied, convert the date into the specified IANA time zone,\n * otherwise convert to local browser time.\n * @returns A converted date and time based on the user's browser locale settings.\n */\nexport const getLocalizedDateTime = (date, timeZone = 'local') => {\n  const convertedDate = date instanceof Date ? date : getDateFromString(date);\n  if (convertedDate === null) {\n    return '';\n  }\n  const convertedDateTime = DateTime.fromJSDate(convertedDate, { zone: timeZone });\n\n  return convertedDateTime;\n};\n\n/**\n * Formats a date string by converting it to a date in the specified timezone,\n * and returning a string with the localized date and time.\n * @param date A Date or ISO 8601 date string. EX: yyyy-MM-ddThh:mm:ss[Z|offset]\n * @param delimiter If supplied, split the date and time by this string when returned.\n * @param timeZone If supplied, convert the date into the specified IANA time zone,\n * otherwise convert to local browser time.\n * @returns A date and time string based on the user's browser locale settings.\n */\nexport const getLocalizedDateTimeString = (\n  date,\n  delimiter = null,\n  timeZone = 'local',\n  includeOffset = false,\n) => {\n  const convertedDate = date instanceof Date ? date : getDateFromString(date);\n  if (convertedDate === null) {\n    return '';\n  }\n  const convertedDateTime = DateTime.fromJSDate(convertedDate, { zone: timeZone });\n\n  if (delimiter !== null) {\n    return (\n      convertedDateTime.toLocaleString(DateTime.DATE_SHORT) +\n      delimiter +\n      convertedDateTime.toLocaleString(DateTime.TIME_WITH_SECONDS) +\n      (includeOffset ? ' ' + convertedDateTime.offsetNameShort : '')\n    );\n  } else {\n    return (\n      convertedDateTime.toLocaleString(DateTime.DATETIME_SHORT_WITH_SECONDS) +\n      (includeOffset ? ' ' + convertedDateTime.offsetNameShort : '')\n    );\n  }\n};\n\n/**\n * Formats a date string by converting it to a date in the specified time zone,\n * and returning a string as the localized time.\n * @param date A Date or ISO 8601 date string. EX: yyyy-MM-ddThh:mm:ss[Z|offset]\n * @param timeZone An IANA time zone id. If supplied, convert the date into the specified time zone,\n * otherwise convert to local browser time.\n * @returns A time string without the date based on the supplied time zone and user's\n * browser locale settings.\n */\nexport const getLocalizedTimeString = (date, timeZone = 'local') => {\n  const convertedDate = date instanceof Date ? date : getDateFromString(date);\n\n  return convertedDate\n    ? DateTime.fromJSDate(convertedDate, { zone: timeZone }).toLocaleString(\n        DateTime.TIME_WITH_SECONDS,\n      )\n    : '';\n};\n"],"mappings":";;AAeA,SAAgBY,WAAWV,OAAOW,YAAY,IAAI;AAChD,KAAI;EACF,IAAIV,OAAO,IAAIC,KAAKF,MAAM;EAC1B,MAAMG,MAAMF,KAAKG,eAAe,WAAW,EAAED,KAAK,WAAW,CAAC;EAC9D,MAAME,QAAQJ,KAAKG,eAAe,WAAW,EAAEC,OAAO,SAAS,CAAC;EAChE,MAAMC,OAAOL,KAAKG,eAAe,WAAW,EAAEE,MAAM,WAAW,CAAC;AAEhE,UAAQK,UAAUC,aAAa,EAA/B;GACE,KAAK,eACH,QAAO,GAAGT,IAAG,GAAIE,MAAK,IAAKC;GAC7B,KAAK,aACH,QAAO,GAAGL,KAAKY,SAAS,CAAA,GAAIZ,KAAKa,U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