{"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,iBAAAA,GAAoB,CAACC,QAAAA,EAAkBC,IAAAA,GAAAA;IAClD,IAAI;AACF,QAAA,MAAMC,UAAAA,GAAa,IAAIC,IAAAA,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