mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
table panel: assume string dates to be on UTC (#47246)
* add tests for display processor relating to datetimes as strings Co-authored-by: Oscar Kilhed <oscar.kilhed@grafana.com>
This commit is contained in:
committed by
GitHub
parent
76b221e9d5
commit
8428446466
@@ -414,6 +414,46 @@ describe('Date display options', () => {
|
||||
expect(processor('2020-08-01T08:48:43.783337Z').text).toEqual('2020-08-01 08:48:43');
|
||||
});
|
||||
|
||||
it('should handle ISO string dates when in other timezones than UTC', () => {
|
||||
const processor = getDisplayProcessor({
|
||||
timeZone: 'CET',
|
||||
field: {
|
||||
type: FieldType.time,
|
||||
config: {},
|
||||
},
|
||||
theme: createTheme(),
|
||||
});
|
||||
|
||||
expect(processor('2020-08-01T08:48:43.783337Z').text).toEqual('2020-08-01 10:48:43'); //DST
|
||||
expect(processor('2020-12-01T08:48:43.783337Z').text).toEqual('2020-12-01 09:48:43'); //STD
|
||||
});
|
||||
|
||||
it('should handle ISO string dates with timezone offset', () => {
|
||||
const processor = getDisplayProcessor({
|
||||
timeZone: 'utc',
|
||||
field: {
|
||||
type: FieldType.time,
|
||||
config: {},
|
||||
},
|
||||
theme: createTheme(),
|
||||
});
|
||||
|
||||
expect(processor('2020-12-01T08:48:43.783337+02:00').text).toEqual('2020-12-01 06:48:43');
|
||||
});
|
||||
|
||||
it('should handle ISO string dates without timezone qualifier by assuming UTC', () => {
|
||||
const processor = getDisplayProcessor({
|
||||
timeZone: 'CET',
|
||||
field: {
|
||||
type: FieldType.time,
|
||||
config: {},
|
||||
},
|
||||
theme: createTheme(),
|
||||
});
|
||||
|
||||
expect(processor('2020-12-01T08:48:43.783337').text).toEqual('2020-12-01 09:48:43');
|
||||
});
|
||||
|
||||
describe('number formatting for string values', () => {
|
||||
it('should preserve string unchanged if unit is strings', () => {
|
||||
const processor = getDisplayProcessor({
|
||||
|
||||
@@ -6,7 +6,7 @@ import { Field, FieldType } from '../types/dataFrame';
|
||||
import { DisplayProcessor, DisplayValue } from '../types/displayValue';
|
||||
import { getValueFormat, isBooleanUnit } from '../valueFormats/valueFormats';
|
||||
import { getValueMappingResult } from '../utils/valueMappings';
|
||||
import { dateTime, dateTimeParse } from '../datetime';
|
||||
import { toUtc, dateTimeParse } from '../datetime';
|
||||
import { KeyValue, TimeZone } from '../types';
|
||||
import { getScaleCalculator } from './scale';
|
||||
import { GrafanaTheme2 } from '../themes/types';
|
||||
@@ -77,7 +77,7 @@ export function getDisplayProcessor(options?: DisplayProcessorOptions): DisplayP
|
||||
const isStringUnit = unit === 'string';
|
||||
|
||||
if (hasDateUnit && typeof value === 'string') {
|
||||
value = dateTime(value).valueOf();
|
||||
value = toUtc(value).valueOf();
|
||||
}
|
||||
|
||||
let numeric = isStringUnit ? NaN : anyToNumber(value);
|
||||
|
||||
Reference in New Issue
Block a user