import dayjs from 'dayjs' ; import { DateAnalysis } from 'src/types' ; param { Any } timestamp return { Boolean } export function isValidDate ( timestamp ) { return new Date ( timestamp ) . getTime ( ) > 0 ; } param { String | Number } expiry param { String | Number } now return { Object } export function analyzeExpiry ( expiry ? , now = new Date ( ) . valueOf ( ) ) { if ( ! expiry ) { return { valid : true } ; } if ( ! isValidDate ( expiry ) || ! isValidDate ( now ) ) { return { valid : false } ; } const dayjsNow = dayjs ( now ) ; return { valid : true , expired : dayjsNow . isAfter ( expiry ) , years : dayjsNow . diff ( expiry , 'years' ) , } ; }