mirror of
https://github.com/grafana/grafana.git
synced 2025-02-12 00:25:46 -06:00
TimeSeries: fix time comparer not comparing date strings properly (#64622)
* fix time comparer not comparing times properly * move isDateTime last as it's probably the most expensive check
This commit is contained in:
parent
d6eea0c7b5
commit
3a1862f37f
@ -113,15 +113,14 @@ exports[`better eslint`] = {
|
||||
],
|
||||
"packages/grafana-data/src/datetime/moment_wrapper.ts:5381": [
|
||||
[0, 0, 0, "Unexpected any. Specify a different type.", "0"],
|
||||
[0, 0, 0, "Unexpected any. Specify a different type.", "1"],
|
||||
[0, 0, 0, "Do not use any type assertions.", "1"],
|
||||
[0, 0, 0, "Do not use any type assertions.", "2"],
|
||||
[0, 0, 0, "Do not use any type assertions.", "3"],
|
||||
[0, 0, 0, "Do not use any type assertions.", "4"],
|
||||
[0, 0, 0, "Do not use any type assertions.", "5"],
|
||||
[0, 0, 0, "Do not use any type assertions.", "6"],
|
||||
[0, 0, 0, "Do not use any type assertions.", "7"],
|
||||
[0, 0, 0, "Do not use any type assertions.", "8"],
|
||||
[0, 0, 0, "Do not use any type assertions.", "9"]
|
||||
[0, 0, 0, "Do not use any type assertions.", "8"]
|
||||
],
|
||||
"packages/grafana-data/src/datetime/parser.ts:5381": [
|
||||
[0, 0, 0, "Do not use any type assertions.", "0"],
|
||||
|
@ -89,7 +89,18 @@ export const getLocaleData = (): DateTimeLocale => {
|
||||
return moment.localeData();
|
||||
};
|
||||
|
||||
export const isDateTime = (value: any): value is DateTime => {
|
||||
export const isDateTimeInput = (value: unknown): value is DateTimeInput => {
|
||||
return (
|
||||
value === null ||
|
||||
typeof value === 'string' ||
|
||||
typeof value === 'number' ||
|
||||
value instanceof Date ||
|
||||
(Array.isArray(value) && value.every((v) => typeof v === 'string' || typeof v === 'number')) ||
|
||||
isDateTime(value)
|
||||
);
|
||||
};
|
||||
|
||||
export const isDateTime = (value: unknown): value is DateTime => {
|
||||
return moment.isMoment(value);
|
||||
};
|
||||
|
||||
|
@ -1,6 +1,6 @@
|
||||
import { isNumber } from 'lodash';
|
||||
|
||||
import { dateTime, isDateTime } from '../datetime';
|
||||
import { dateTime, isDateTimeInput } from '../datetime';
|
||||
import { Field, FieldType } from '../types/dataFrame';
|
||||
import { Vector } from '../types/vector';
|
||||
|
||||
@ -34,7 +34,7 @@ export const timeComparer = (a: unknown, b: unknown): number => {
|
||||
return numericComparer(a, b);
|
||||
}
|
||||
|
||||
if (isDateTime(a) && isDateTime(b)) {
|
||||
if (isDateTimeInput(a) && isDateTimeInput(b)) {
|
||||
if (dateTime(a).isBefore(b)) {
|
||||
return -1;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user