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