Skip to content

Commit 94aa6f8

Browse files
committed
Switch from date-fns to dayjs
1 parent a35ebfe commit 94aa6f8

File tree

4 files changed

+10
-10
lines changed

4 files changed

+10
-10
lines changed

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,9 @@
2323
"url": "https://marcus.se.net"
2424
},
2525
"dependencies": {
26-
"date-fns": "^2.16.1",
2726
"jsonpath-plus": "^4.0.0",
28-
"memory-cache": "^0.2.0"
27+
"memory-cache": "^0.2.0",
28+
"dayjs": "^1.10.4"
2929
},
3030
"devDependencies": {
3131
"@grafana/data": "latest",

src/detectFieldType.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import { isValid, parseISO } from 'date-fns';
21
import { FieldType } from '@grafana/data';
2+
import dayjs from 'dayjs';
33

44
/**
55
* Detects the field type from an array of values.
@@ -13,7 +13,7 @@ export const detectFieldType = (values: any[]): FieldType => {
1313
// If all values are valid ISO 8601, then assume that it's a time field.
1414
const isValidISO = values
1515
.filter((value) => value !== null)
16-
.every((value) => value.length >= 10 && isValid(parseISO(value)));
16+
.every((value) => value.length >= 10 && dayjs(value).isValid());
1717
if (isValidISO) {
1818
return FieldType.time;
1919
}

src/parseValues.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import { parseISO } from 'date-fns';
21
import { FieldType } from '@grafana/data';
2+
import dayjs from 'dayjs';
33

44
/**
55
* parseValues converts values to the given field type.
@@ -11,7 +11,7 @@ export const parseValues = (values: any[], type: FieldType): any[] => {
1111
// epoch in milliseconds.
1212

1313
if (values.filter((_) => _).every((value) => typeof value === 'string')) {
14-
return values.map((_) => (_ !== null ? parseISO(_).valueOf() : _));
14+
return values.map((_) => (_ !== null ? dayjs(_).valueOf() : _));
1515
}
1616

1717
if (values.filter((_) => _).every((value) => typeof value === 'number')) {

yarn.lock

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4440,10 +4440,10 @@ date-fns@^1.23.0:
44404440
resolved "https://registry.yarnpkg.com/date-fns/-/date-fns-1.30.1.tgz#2e71bf0b119153dbb4cc4e88d9ea5acfb50dc05c"
44414441
integrity sha512-hBSVCvSmWC+QypYObzwGOd9wqdDpOt+0wl0KbU+R+uuZBS1jN8VsD1ss3irQDknRj5NvxiTF6oj/nDRnN/UQNw==
44424442

4443-
date-fns@^2.16.1:
4444-
version "2.17.0"
4445-
resolved "https://registry.yarnpkg.com/date-fns/-/date-fns-2.17.0.tgz#afa55daea539239db0a64e236ce716ef3d681ba1"
4446-
integrity sha512-ZEhqxUtEZeGgg9eHNSOAJ8O9xqSgiJdrL0lzSSfMF54x6KXWJiOH/xntSJ9YomJPrYH/p08t6gWjGWq1SDJlSA==
4443+
dayjs@^1.10.4:
4444+
version "1.10.4"
4445+
resolved "https://registry.yarnpkg.com/dayjs/-/dayjs-1.10.4.tgz#8e544a9b8683f61783f570980a8a80eaf54ab1e2"
4446+
integrity sha512-RI/Hh4kqRc1UKLOAf/T5zdMMX5DQIlDxwUe3wSyMMnEbGunnpENCdbUgM+dW7kXidZqCttBrmw7BhN4TMddkCw==
44474447

44484448
debug@^2.2.0, debug@^2.3.3, debug@^2.6.0, debug@^2.6.9:
44494449
version "2.6.9"

0 commit comments

Comments
 (0)