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()) +}