fix: handle long dates with time

This commit is contained in:
Rickard Natt och Dag 2021-04-01 12:53:31 +02:00
parent 9c87535c5b
commit 3ba96feec9
2 changed files with 6 additions and 4 deletions

View File

@ -5,6 +5,8 @@ test.each([
['2021-05-28', '2021-05-27T22:00:00.000Z'],
['2 oktober 2020', '2020-10-01T22:00:00.000Z'],
['12 oktober 2020', '2020-10-11T22:00:00.000Z'],
['5 oktober 2020 11:34', '2020-10-05T09:34:00.000Z'],
['15 oktober 2020 11:34', '2020-10-15T09:34:00.000Z'],
['This is an invalid date', undefined],
])('handles date parsing of %s', (input, expected) => {
expect(parseDate(input)).toEqual(expected)

View File

@ -24,16 +24,16 @@ export const parseDate = (input?: string): string | undefined => {
return onlyDate.toUTC().toISO()
}
const dateLongForm = dateParse('dd MMMM yyyy')
const dateLongForm = dateParse('d MMMM yyyy')
if (dateLongForm.isValid) {
return dateLongForm.toUTC().toISO()
}
const dateLongFormOneDigit = dateParse('d MMMM yyyy')
const dateTimeLongForm = dateParse('d MMMM yyyy HH:mm')
if (dateLongFormOneDigit.isValid) {
return dateLongFormOneDigit.toUTC().toISO()
if (dateTimeLongForm.isValid) {
return dateTimeLongForm.toUTC().toISO()
}
// Explicit return to satisfy ESLint