{"version":3,"file":"common.cjs","sources":["../../../src/datetime/common.ts"],"sourcesContent":["import { isEmpty } from 'lodash';\n\nimport { TimeZone, DefaultTimeZone } from '../types/time';\n\n/**\n * Used for helper functions handling time zones.\n *\n * @public\n */\nexport interface TimeZoneOptions {\n  /**\n   * Specify this if you want to override the timeZone used when parsing or formatting\n   * a date and time value. If no timeZone is set, the default timeZone for the current\n   * user is used.\n   */\n  timeZone?: TimeZone;\n}\n\n/**\n * The type describing date and time options. Used for all the helper functions\n * available to parse or format date and time values.\n *\n * @public\n */\nexport interface DateTimeOptions extends TimeZoneOptions {\n  /**\n   * Specify a {@link https://momentjs.com/docs/#/displaying/format | momentjs} format to\n   * use a custom formatting pattern or parsing pattern. If no format is set,\n   * then system configured default format is used.\n   */\n  format?: string;\n}\n\n/**\n * The type to describe the time zone resolver function that will be used to access\n * the default time zone of a user.\n *\n * @public\n */\nexport type TimeZoneResolver = () => TimeZone | undefined;\n\nlet defaultTimeZoneResolver: TimeZoneResolver = () => DefaultTimeZone;\n\n/**\n * Used by Grafana internals to set the {@link TimeZoneResolver} to access the current\n * user timeZone.\n *\n * @internal\n */\nexport const setTimeZoneResolver = (resolver: TimeZoneResolver) => {\n  defaultTimeZoneResolver = resolver ?? defaultTimeZoneResolver;\n};\n\n/**\n * Used to get the current selected time zone. If a valid time zone is passed in the\n * options it will be returned. If no valid time zone is passed either the time zone\n * configured for the user account will be returned or the default for Grafana.\n *\n * @public\n */\nexport const getTimeZone = <T extends TimeZoneOptions>(options?: T): TimeZone => {\n  if (options?.timeZone && !isEmpty(options.timeZone)) {\n    return options.timeZone;\n  }\n  return defaultTimeZoneResolver() ?? DefaultTimeZone;\n};\n"],"names":["DefaultTimeZone","isEmpty"],"mappings":";;;;;;;;AAyCA,IAAI,0BAA4C,MAAMA,oBAAA;AAQ/C,MAAM,mBAAA,GAAsB,CAAC,QAAA,KAA+B;AACjE,EAAA,uBAAA,GAA0B,QAAA,IAAA,IAAA,GAAA,QAAA,GAAY,uBAAA;AACxC;AASO,MAAM,WAAA,GAAc,CAA4B,OAAA,KAA0B;AA5DjF,EAAA,IAAA,EAAA;AA6DE,EAAA,IAAA,CAAI,mCAAS,QAAA,KAAY,CAACC,cAAA,CAAQ,OAAA,CAAQ,QAAQ,CAAA,EAAG;AACnD,IAAA,OAAO,OAAA,CAAQ,QAAA;AAAA,EACjB;AACA,EAAA,OAAA,CAAO,EAAA,GAAA,uBAAA,OAAA,IAAA,GAAA,EAAA,GAA6BD,oBAAA;AACtC;;;;;"}