1
0
mirror of https://github.com/comatory/fb2iCal synced 2025-06-05 22:09:25 +02:00

add fallback parser when LD/JSON not found, use DOM parser

This commit is contained in:
Ondrej Synacek
2019-10-23 22:03:20 +02:00
parent a41992d53b
commit 889de553f9
5 changed files with 127 additions and 37 deletions

32
lib/parser-utils.js Normal file
View File

@@ -0,0 +1,32 @@
const dayjs = require('dayjs')
// NOTE: Specific formatting for `ics` library
const parseDates = (startDate, endDate) => {
const start = startDate ? [
startDate.year(),
startDate.month() + 1,
startDate.date(),
startDate.hour(),
startDate.minute(),
] : (() => {
const now = dayjs()
return [
now.year(),
now.month() + 1,
now.date()
]
})()
const diffInMinutes = endDate ?
endDate.diff(startDate, 'minutes') :
120
const duration = { minutes: diffInMinutes }
return {
start,
duration,
}
}
module.exports = { parseDates }