UNPKG

@grafana/ui

Version:
1 lines 1.97 kB
{"version":3,"file":"mapper.mjs","sources":["../../../../../src/components/DateTimePickers/TimeRangePicker/mapper.ts"],"sourcesContent":["import { TimeOption, TimeRange, TimeZone, rangeUtil, dateTimeFormat } from '@grafana/data';\n\nimport { getFeatureToggle } from '../../../utils/featureToggle';\nimport { commonFormat } from '../commonFormat';\n\n/**\n * Takes a printable TimeOption and builds a TimeRange with DateTime properties from it\n */\nexport const mapOptionToTimeRange = (option: TimeOption, timeZone?: TimeZone): TimeRange => {\n return rangeUtil.convertRawToRange({ from: option.from, to: option.to }, timeZone, undefined, commonFormat);\n};\n\n/**\n * Takes a TimeRange and makes a printable TimeOption with formatted date strings correct for the timezone from it\n */\nexport const mapRangeToTimeOption = (range: TimeRange, timeZone?: TimeZone): TimeOption => {\n const from = dateTimeFormat(range.from, { timeZone, format: commonFormat });\n const to = dateTimeFormat(range.to, { timeZone, format: commonFormat });\n\n let display = `${from} to ${to}`;\n\n if (getFeatureToggle('localeFormatPreference')) {\n display = rangeUtil.describeTimeRange(range, timeZone);\n }\n\n return {\n from,\n to,\n display,\n };\n};\n"],"names":[],"mappings":";;;;;AAQO,MAAM,oBAAA,GAAuB,CAAC,MAAA,EAAoB,QAAA,KAAmC;AAC1F,EAAA,OAAO,SAAA,CAAU,iBAAA,CAAkB,EAAE,IAAA,EAAM,MAAA,CAAO,IAAA,EAAM,EAAA,EAAI,MAAA,CAAO,EAAA,EAAG,EAAG,QAAA,EAAU,KAAA,CAAA,EAAW,YAAY,CAAA;AAC5G;AAKO,MAAM,oBAAA,GAAuB,CAAC,KAAA,EAAkB,QAAA,KAAoC;AACzF,EAAA,MAAM,IAAA,GAAO,eAAe,KAAA,CAAM,IAAA,EAAM,EAAE,QAAA,EAAU,MAAA,EAAQ,cAAc,CAAA;AAC1E,EAAA,MAAM,EAAA,GAAK,eAAe,KAAA,CAAM,EAAA,EAAI,EAAE,QAAA,EAAU,MAAA,EAAQ,cAAc,CAAA;AAEtE,EAAA,IAAI,OAAA,GAAU,CAAA,EAAG,IAAI,CAAA,IAAA,EAAO,EAAE,CAAA,CAAA;AAE9B,EAAA,IAAI,gBAAA,CAAiB,wBAAwB,CAAA,EAAG;AAC9C,IAAA,OAAA,GAAU,SAAA,CAAU,iBAAA,CAAkB,KAAA,EAAO,QAAQ,CAAA;AAAA,EACvD;AAEA,EAAA,OAAO;AAAA,IACL,IAAA;AAAA,IACA,EAAA;AAAA,IACA;AAAA,GACF;AACF;;;;"}