UNPKG

@grafana/ui

Version:
1 lines 2.5 kB
{"version":3,"file":"mapper.mjs","sources":["../../../../../src/components/DateTimePickers/TimeRangePicker/mapper.ts"],"sourcesContent":["import { TimeOption, TimeRange, TimeZone, rangeUtil, dateTimeFormat } from '@grafana/data';\nimport { formatDateRange } from '@grafana/i18n';\n\nimport { getFeatureToggle } from '../../../utils/featureToggle';\nexport const mapOptionToTimeRange = (option: TimeOption, timeZone?: TimeZone): TimeRange => {\n return rangeUtil.convertRawToRange({ from: option.from, to: option.to }, timeZone);\n};\n\nconst rangeFormatShort: Intl.DateTimeFormatOptions = {\n dateStyle: 'short',\n timeStyle: 'short',\n};\n\nconst rangeFormatFull: Intl.DateTimeFormatOptions = {\n dateStyle: 'short',\n timeStyle: 'medium',\n};\n\nexport const mapRangeToTimeOption = (range: TimeRange, timeZone?: TimeZone): TimeOption => {\n const from = dateTimeFormat(range.from, { timeZone });\n const to = dateTimeFormat(range.to, { timeZone });\n\n let display = `${from} to ${to}`;\n\n if (getFeatureToggle('localeFormatPreference')) {\n const fromDate = range.from.toDate();\n const toDate = range.to.toDate();\n\n // The short time format doesn't include seconds, so change the format\n // if the range includes seconds\n const hasSeconds = fromDate.getSeconds() !== 0 || toDate.getSeconds() !== 0;\n display = formatDateRange(fromDate, toDate, hasSeconds ? rangeFormatFull : rangeFormatShort);\n }\n\n return {\n from,\n to,\n display,\n };\n};\n"],"names":[],"mappings":";;;;AAIa,MAAA,oBAAA,GAAuB,CAAC,MAAA,EAAoB,QAAmC,KAAA;AAC1F,EAAO,OAAA,SAAA,CAAU,iBAAkB,CAAA,EAAE,IAAM,EAAA,MAAA,CAAO,MAAM,EAAI,EAAA,MAAA,CAAO,EAAG,EAAA,EAAG,QAAQ,CAAA;AACnF;AAEA,MAAM,gBAA+C,GAAA;AAAA,EACnD,SAAW,EAAA,OAAA;AAAA,EACX,SAAW,EAAA;AACb,CAAA;AAEA,MAAM,eAA8C,GAAA;AAAA,EAClD,SAAW,EAAA,OAAA;AA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