Начат перенос методов и типов для работы с датами

This commit is contained in:
goodmice 2021-11-19 18:13:28 +05:00
parent 10cf64b4d6
commit 16af0d66c1
2 changed files with 7 additions and 1 deletions

View File

@ -9,9 +9,10 @@ import { WellIcon, WellIconState } from './icons/WellIcon'
import { ReactComponent as DepositIcon } from '../images/DepositIcon.svg' import { ReactComponent as DepositIcon } from '../images/DepositIcon.svg'
import { ReactComponent as ClusterIcon } from '../images/ClusterIcon.svg' import { ReactComponent as ClusterIcon } from '../images/ClusterIcon.svg'
import { DepositDto } from '../services/api' import { DepositDto } from '../services/api'
import { RawDate } from '../utils/DateTimeUtils'
export const getWellState = (idState?: number): WellIconState => idState === 1 ? 'active' : 'unknown' 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 if (!lastTelemetryDate) return false
return Date.now() - +new Date(lastTelemetryDate) < 600_000 return Date.now() - +new Date(lastTelemetryDate) < 600_000
} }

View File

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