diff --git a/packages/grafana-data/src/datetime/common.ts b/packages/grafana-data/src/datetime/common.ts index a1a8445bec0..fa7fb9454ec 100644 --- a/packages/grafana-data/src/datetime/common.ts +++ b/packages/grafana-data/src/datetime/common.ts @@ -1,19 +1,26 @@ import { TimeZone, DefaultTimeZone } from '../types/time'; +/** + * Used for helper functions handling time zones. + * + * @public + */ +export interface TimeZoneOptions { + /** + * Specify this if you want to override the timeZone used when parsing or formatting + * a date and time value. If no timeZone is set, the default timeZone for the current + * user is used. + */ + timeZone?: TimeZone; +} + /** * The type describing date and time options. Used for all the helper functions * available to parse or format date and time values. * * @public */ -export interface DateTimeOptions { - /** - * Specify this if you want to override the timeZone used when parsing or formatting - * a date and time value. If no timeZone is set, the default timeZone for the current - * user is used. - */ - timeZone?: TimeZone; - +export interface DateTimeOptions extends TimeZoneOptions { /** * Specify a {@link https://momentjs.com/docs/#/displaying/format | momentjs} format to * use a custom formatting pattern or parsing pattern. If no format is set, @@ -43,11 +50,12 @@ export const setTimeZoneResolver = (resolver: TimeZoneResolver) => { }; /** - * Used within this package to get timeZone from an options value. If timezone - * is not set in the options, then a default timeZone is be resolved instead. + * Used to get the current selected time zone. If a valid time zone is passed in the + * options it will be returned. If no valid time zone is passed either the time zone + * configured for the user account will be returned or the default for Grafana. * - * @internal + * @public */ -export const getTimeZone = (options?: T): TimeZone => { +export const getTimeZone = (options?: T): TimeZone => { return options?.timeZone ?? defaultTimeZoneResolver() ?? DefaultTimeZone; }; diff --git a/packages/grafana-data/src/datetime/index.ts b/packages/grafana-data/src/datetime/index.ts index 1e38fc76260..b3e0cc28500 100644 --- a/packages/grafana-data/src/datetime/index.ts +++ b/packages/grafana-data/src/datetime/index.ts @@ -7,4 +7,4 @@ export * from './formats'; export * from './formatter'; export * from './parser'; export { dateMath, rangeUtil }; -export { DateTimeOptions, setTimeZoneResolver, TimeZoneResolver } from './common'; +export { DateTimeOptions, setTimeZoneResolver, TimeZoneResolver, getTimeZone } from './common';