1
0
mirror of https://github.com/comatory/fb2iCal synced 2024-12-27 08:52:58 +01:00
Facebook-Events-iCal-Converter/lib/parser-utils.js

33 lines
601 B
JavaScript
Raw Normal View History

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 }