From 16af0d66c120d6c60d6db386ddef01cc01a801f1 Mon Sep 17 00:00:00 2001 From: goodmice Date: Fri, 19 Nov 2021 18:13:28 +0500 Subject: [PATCH] =?UTF-8?q?=D0=9D=D0=B0=D1=87=D0=B0=D1=82=20=D0=BF=D0=B5?= =?UTF-8?q?=D1=80=D0=B5=D0=BD=D0=BE=D1=81=20=D0=BC=D0=B5=D1=82=D0=BE=D0=B4?= =?UTF-8?q?=D0=BE=D0=B2=20=D0=B8=20=D1=82=D0=B8=D0=BF=D0=BE=D0=B2=20=D0=B4?= =?UTF-8?q?=D0=BB=D1=8F=20=D1=80=D0=B0=D0=B1=D0=BE=D1=82=D1=8B=20=D1=81=20?= =?UTF-8?q?=D0=B4=D0=B0=D1=82=D0=B0=D0=BC=D0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/WellTreeSelector.tsx | 3 ++- src/utils/DateTimeUtils.ts | 5 +++++ 2 files changed, 7 insertions(+), 1 deletion(-) create mode 100644 src/utils/DateTimeUtils.ts diff --git a/src/components/WellTreeSelector.tsx b/src/components/WellTreeSelector.tsx index cb22068..3d4a421 100644 --- a/src/components/WellTreeSelector.tsx +++ b/src/components/WellTreeSelector.tsx @@ -9,9 +9,10 @@ import { WellIcon, WellIconState } from './icons/WellIcon' import { ReactComponent as DepositIcon } from '../images/DepositIcon.svg' import { ReactComponent as ClusterIcon } from '../images/ClusterIcon.svg' import { DepositDto } from '../services/api' +import { RawDate } from '../utils/DateTimeUtils' export const getWellState = (idState?: number): WellIconState => idState === 1 ? 'active' : 'unknown' -export const checkIsWellOnline = (lastTelemetryDate?: string | number | Date | null): boolean => { +export const checkIsWellOnline = (lastTelemetryDate?: RawDate): boolean => { if (!lastTelemetryDate) return false return Date.now() - +new Date(lastTelemetryDate) < 600_000 } diff --git a/src/utils/DateTimeUtils.ts b/src/utils/DateTimeUtils.ts new file mode 100644 index 0000000..79a8063 --- /dev/null +++ b/src/utils/DateTimeUtils.ts @@ -0,0 +1,5 @@ +export type RawDate = number | string | Date + +export function isRawDate(value: unknown): value is RawDate { + return isNaN(new Date(value as RawDate).getTime()) +}