Verified Commit f39ab70b authored by les's avatar les
Browse files

improve recurrent event management

parent a8c58e93
......@@ -544,17 +544,10 @@ const eventController = {
// get weekday
log.info(type)
// get recurrent freq details
if (type === -1) {
cursor = cursor.endOf('month')
cursor = cursor.subtract(1, 'week')
cursor = cursor.day(start_date.day())
} else {
cursor = cursor.startOf('month')
cursor = cursor.add(type, 'week')
cursor = cursor.day(start_date.day())
if (cursor.isBefore(dayjs())) {
cursor = cursor.add(1, 'month')
}
cursor = helpers.getWeekdayN(cursor, type, start_date.day())
if (cursor.isBefore(dayjs())) {
cursor = cursor.add(4, 'week')
cursor = helpers.getWeekdayN(cursor, type, start_date.day())
}
}
}
......
......@@ -135,12 +135,14 @@ module.exports = {
return {
title: get(props, 'name[0]', ''),
description: get(props, 'description[0]', ''),
place: get(props, 'location[0].properties.name', ''),
address: get(props, 'location[0].properties.street-address'),
start: get(props, 'start[0]', ''),
end: get(props, 'end[0]', ''),
place: {
name: get(props, 'location[0].properties.name', '') || get(props, 'location[0]'),
address: get(props, 'location[0].properties.street-address')
},
start_datetime: dayjs(get(props, 'start[0]', '')).unix(),
end_datetime: dayjs(get(props, 'end[0]', '')).unix(),
tags: get(props, 'category', []),
image: get(props, 'featured[0]')
image_path: get(props, 'featured[0]')
}
})
return res.json(events)
......@@ -160,14 +162,27 @@ module.exports = {
}
}))
}
// const event = dom.window.document.querySelected(".h-event")
// console.error(event)
// console.error(response)
} catch (e) {
log.error(e)
res.status(400).json(e.toString)
}
},
// res.json('ok')
getWeekdayN (date, n, weekday) {
let cursor
if (n === -1) {
cursor = date.endOf('month')
cursor = cursor.day(weekday)
if (cursor.month() !== date.month()) {
cursor = cursor.subtract(1, 'week')
}
} else {
cursor = date.startOf('month')
cursor = cursor.add(cursor.day() <= date.day() ? n - 1 : n, 'week')
cursor = cursor.day(weekday)
}
cursor = cursor.hour(date.hour()).minute(date.minute()).second(0)
log.debug(cursor)
return cursor
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment