{"version":3,"file":"dateLocalizationHooks.mjs","names":["IANAZone","useCallback","getLocalizedDateString","getLocalizedDateTimeString","useAuthedUser","useGetLocalizedDateString","timeZone","$","_c","user","t0","additionalProperties","activeUtilityTimeZone","date","validTimeZone","isValidZone","getDateString","useGetLocalizedDateTimeString","includeTimeZoneOffset","undefined","t1","t2","delimiter","getDateTimeString","useGetLocalizedUserDateTimeString"],"sources":["../../../src/udp/utilities/dateLocalizationHooks.jsx"],"sourcesContent":["import { IANAZone } from 'luxon';\nimport { useCallback } from 'react';\nimport {\n  getLocalizedDateString,\n  getLocalizedDateTimeString,\n} from '../../UI/widgets/utils/dateUtils';\nimport { useAuthedUser } from '../../utilities/auth/useAuthedUser'\n\n/**\n * Gets a function that can be used to convert a date or\n * ISO 8601 date string (EX: yyyy-MM-ddThh:mm:ss[Z|offset])\n * to a localized date string without time in the specified IANA time zone.\n * @param timeZone An IANA time zone to convert the date to before returning as a string.\n * @returns A function to convert a date to a localized string.\n */\n\nexport const useGetLocalizedDateString = (timeZone) => {\n  const user = useAuthedUser();\n\n  const getDateString = useCallback(\n    (date) => {\n      const validTimeZone =\n        timeZone !== 'local' &&\n        (timeZone === user?.additionalProperties?.activeUtilityTimeZone ||\n          IANAZone.isValidZone(timeZone))\n          ? timeZone\n          : 'local'; // IANAZone.isValidZone is very slow, skip it if known valid timeZone passed\n      return getLocalizedDateString(date, validTimeZone);\n    },\n    [user, timeZone],\n  );\n\n  return getDateString;\n};\n\n/**\n * Gets a function that can be used to convert a date or\n * ISO 8601 date string (EX: yyyy-MM-ddThh:mm:ss[Z|offset])\n * to a localized date time string in the specified IANA time zone.\n * @param timeZone The IANA time zone to convert the date before converting to\n * a localized string.\n * @param includeTimeZoneOffset If true, include the time zone offset in the localized string.\n * @returns A function to convert a date to a localized string.\n */\n\nexport const useGetLocalizedDateTimeString = (timeZone, includeTimeZoneOffset = false) => {\n  const user = useAuthedUser();\n\n  const getDateTimeString = useCallback(\n    (date, delimiter = null) => {\n      const validTimeZone =\n        timeZone !== 'local' &&\n        (timeZone === user?.additionalProperties?.activeUtilityTimeZone ||\n          IANAZone.isValidZone(timeZone))\n          ? timeZone\n          : 'local'; // IANAZone.isValidZone is very slow, skip it if known valid timeZone passed\n      return getLocalizedDateTimeString(date, delimiter, validTimeZone, includeTimeZoneOffset);\n    },\n    [user, timeZone, includeTimeZoneOffset],\n  );\n\n  return getDateTimeString;\n};\n\n/**\n * Gets a function that can be used to convert a date or\n * ISO 8601 date string (EX: yyyy-MM-ddThh:mm:ss[Z|offset])\n * to a localized date time string in the current user's time zone.\n * @param includeTimeZoneOffset If true, include the time zone offset in the localized string.\n * @returns A function to convert a date to a localized string.\n */\n\nexport const useGetLocalizedUserDateTimeString = (includeTimeZoneOffset = false) => {\n  const user = useAuthedUser();\n\n  const getDateTimeString = useCallback(\n    (date, delimiter = null) => {\n      return getLocalizedDateTimeString(\n        date,\n        delimiter,\n        user?.additionalProperties?.timeZone,\n        includeTimeZoneOffset,\n      );\n    },\n    [user, includeTimeZoneOffset],\n  );\n\n  return getDateTimeString;\n};\n"],"mappings":";;;;;;;;;;;;;AAgBA,MAAaK,6BAA4BC,aAAA;CAAA,MAAAC,IAAAC,EAAA,EAAA;CACvC,MAAAC,OAAaL,eAAe;CAAC,IAAAM;AAAA,KAAAH,EAAA,OAAAD,YAAAC,EAAA,OAAAE,MAAAE,sBAAAC,uBAAA;AAG3BF,QAAAG,SAAA;AAMgB,UACPX,uBAAuBW,MAL5BP,aAAa,YACZA,aAAaG,MAAIE,sBAA6CC,yBAC7DZ,SAAQe,YAAaT,SAAU,IAFjCA,WAAA,QAKgD;;AACnDC,IAAA,KAAAD;AAAAC,IAAA,KAAAE,MAAAE,sBAAAC;AAAAL,IAAA,KAAAG;OAAAA,MAAAH,EAAA;AAED,QAXoBG;;;;;;;;;;;AA0BxB,MAAaO,iCAAgCX,UAAAI,OAAA;CAAA,MAAAH,IAAAC,EAAA,EAAA;CAAW,MAAAU,wBAAAR,OAAAS,KAAAA,I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