From ff17d9bf7a075124f360e9187daf3120c78f0e0c Mon Sep 17 00:00:00 2001 From: Jonathan Bernard Date: Fri, 13 Mar 2020 23:07:06 -0500 Subject: [PATCH] Move timestamp comparator function into shared util module. --- web/src/components/measure-details/simple-details.ts | 3 ++- web/src/util.ts | 7 +++++++ 2 files changed, 9 insertions(+), 1 deletion(-) create mode 100644 web/src/util.ts diff --git a/web/src/components/measure-details/simple-details.ts b/web/src/components/measure-details/simple-details.ts index 87c241b..ef28330 100644 --- a/web/src/components/measure-details/simple-details.ts +++ b/web/src/components/measure-details/simple-details.ts @@ -4,6 +4,7 @@ import moment from 'moment'; import assign from 'lodash.assign'; import { library } from '@fortawesome/fontawesome-svg-core'; import { faPencilAlt } from '@fortawesome/free-solid-svg-icons'; +import { byTimestampComparator } from '@/util'; library.add(faPencilAlt); @@ -28,7 +29,7 @@ export class SimpleDetails extends Vue { return [{ name: this.measure.name, data: measurementData - .sort((a, b) => a.timestamp.getTime() - b.timestamp.getTime()) + .sort(byTimestampComparator) .map((m) => ({ x: m.timestamp.toISOString(), y: m.value })) }]; } diff --git a/web/src/util.ts b/web/src/util.ts new file mode 100644 index 0000000..c51f4b9 --- /dev/null +++ b/web/src/util.ts @@ -0,0 +1,7 @@ +import { Measurement, MeasurementMeta } from '@/models'; + +export function byTimestampComparator( + a: Measurement, + b: Measurement): number { + return a.timestamp.getTime() - b.timestamp.getTime(); +}