1
0
mirror of https://github.com/comatory/fb2iCal synced 2024-12-25 16:02:46 +01:00

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

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,