1
0
mirror of https://github.com/comatory/fb2iCal synced 2025-02-17 20:20:48 +01:00

add fallback time for unknown start date

This commit is contained in:
Ondřej Synáček 2019-12-15 10:56:26 +01:00
parent 946d1957dd
commit 0f5c9cf59c
2 changed files with 7 additions and 10 deletions

View File

@ -2,23 +2,18 @@ const cheerio = require('cheerio')
const dayjs = require('dayjs')
const { parseDates } = require('../parser-utils')
const parseDate = (timeText) => {
const parseDate = (timeText = '') => {
const parts = timeText.split('at')
const datePart = parts[0] || null
const timePart = parts[1] || null
if (!datePart) {
return {
start: null,
duration: null,
}
}
const rangeTimeParts = timePart ? timePart.split('') : []
const startTimePart = `${datePart || ''}${rangeTimeParts[0] || ''}`
const endTimePart = `${datePart || ''}${rangeTimeParts[1] || ''}`
const startTime = dayjs(startTimePart)
const startTime = startTimePart ?
dayjs(startTimePart) :
dayjs(new Date())
const endTime = dayjs(endTimePart)
const normalizedStartTime = startTime.isValid() ? startTime : dayjs(new Date())

View File

@ -3,7 +3,9 @@ const dayjs = require('dayjs')
const { parseDates } = require('../parser-utils')
const parseEventData = (eventData) => {
const startDate = eventData.startDate && dayjs(eventData.startDate)
const startDate = eventData.startDate ?
dayjs(eventData.startDate) :
dayjs(new Date())
const endDate = eventData.endDate && dayjs(eventData.endDate)
const { start, duration } = parseDates(startDate, endDate)
const { location } = eventData || {}