mirror of
https://github.com/comatory/fb2iCal
synced 2024-12-27 08:52:58 +01:00
33 lines
601 B
JavaScript
33 lines
601 B
JavaScript
|
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 }
|