{"version":3,"file":"time.mjs","sources":["../../../admin/src/utils/time.ts"],"sourcesContent":["export const getTimezoneOffset = (timezone: string, date: Date) => {\n try {\n const offsetPart = new Intl.DateTimeFormat('en', {\n timeZone: timezone,\n timeZoneName: 'longOffset',\n })\n .formatToParts(date)\n .find((part) => part.type === 'timeZoneName');\n\n const offset = offsetPart ? offsetPart.value : '';\n\n // We want to show time based on UTC, not GMT so we swap that.\n let utcOffset = offset.replace('GMT', 'UTC');\n\n // For perfect UTC (UTC+0:00) we only get the string UTC, So we need to append the 0's.\n if (!utcOffset.includes('+') && !utcOffset.includes('-')) {\n utcOffset = `${utcOffset}+00:00`;\n }\n\n return utcOffset;\n } catch (error) {\n // When timezone is invalid we catch the error and return empty to don't break the app\n return '';\n }\n};\n\ninterface ITimezoneOption {\n offset: string;\n value: string;\n}\n\nexport const getTimezones = (selectedDate: Date) => {\n const timezoneList: ITimezoneOption[] = Intl.supportedValuesOf('timeZone').map((timezone) => {\n // Timezone will be in the format GMT${OFFSET} where offset could be nothing,\n // a four digit string e.g. +05:00 or -08:00\n const utcOffset = getTimezoneOffset(timezone, selectedDate);\n\n // Offset and timezone are concatenated with '&', so to split and save the required timezone in DB\n return { offset: utcOffset, value: `${utcOffset}&${timezone}` } satisfies ITimezoneOption;\n });\n\n const systemTimezone = timezoneList.find(\n (timezone) => timezone.value.split('&')[1] === Intl.DateTimeFormat().resolvedOptions().timeZone\n );\n\n return { timezoneList, systemTimezone };\n};\n"],"names":["getTimezoneOffset","timezone","date","offsetPart","Intl","DateTimeFormat","timeZone","timeZoneName","formatToParts","find","part","type","offset","value","utcOffset","replace","includes","error","getTimezones","selectedDate","timezoneList","supportedValuesOf","map","systemTimezone","split","resolvedOptions"],"mappings":"AAAO,MAAMA,iBAAoB,GAAA,CAACC,QAAkBC,EAAAA,IAAAA,GAAAA;IAClD,IAAI;AACF,QAAA,MAAMC,UAAa,GAAA,IAAIC,IAAKC,CAAAA,cAAc,CAAC,IAAM,EAAA;YAC/CC,Q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