parent
544eb030b8
commit
368a945826
@ -1,9 +1,21 @@ |
|||||||
|
import endsWith from 'lodash/endsWith' |
||||||
import parse from 'date-fns/parse' |
import parse from 'date-fns/parse' |
||||||
|
|
||||||
export const parseDate = (dateString: string, format = 'yyyy-MM-dd HH:mm:ss') => ( |
const dateFormats = { |
||||||
parse( |
withTimezone: 'yyyy-MM-dd HH:mm:ssx', |
||||||
|
withoutTimezone: 'yyyy-MM-dd HH:mm:ss', |
||||||
|
} |
||||||
|
|
||||||
|
export const parseDate = ( |
||||||
|
dateString: string, |
||||||
|
format?: string, |
||||||
|
) => { |
||||||
|
const defaultFormat = endsWith(dateString, 'Z') |
||||||
|
? dateFormats.withTimezone |
||||||
|
: dateFormats.withoutTimezone |
||||||
|
return parse( |
||||||
dateString, |
dateString, |
||||||
format, |
format ?? defaultFormat, |
||||||
new Date(), |
new Date(), |
||||||
) |
) |
||||||
) |
} |
||||||
|
|||||||
Loading…
Reference in new issue