improve parsing for start and end dates for DOMparser

This commit is contained in:
Ondřej Synáček 2019-11-26 22:38:47 +01:00
parent 7234d442e3
commit f22841e1f4
1 changed files with 9 additions and 3 deletions

View File

@ -14,10 +14,16 @@ const parseDate = (timeText) => {
}
}
const normalizedTimeString = `${datePart}${timePart || ''}`
const startTime = dayjs(normalizedTimeString)
const rangeTimeParts = timePart ? timePart.split('') : []
const startTimePart = `${datePart || ''}${rangeTimeParts[0] || ''}`
const endTimePart = `${datePart || ''}${rangeTimeParts[1] || ''}`
const { start, duration } = parseDates(startTime, null)
const startTime = dayjs(startTimePart)
const endTime = dayjs(endTimePart)
const normalizedStartTime = startTime.isValid() ? startTime : dayjs(new Date())
const normalizedEndTime = endTime.isValid() ? endTime : dayjs(new Date())
const { start, duration } = parseDates(normalizedStartTime, normalizedEndTime)
return {
start,