diff --git a/modules/default/calendar/README.md b/modules/default/calendar/README.md index b272a2d2..e3938bda 100755 --- a/modules/default/calendar/README.md +++ b/modules/default/calendar/README.md @@ -52,6 +52,8 @@ The following properties can be configured: | `hidePrivate` | Hides private calendar events.

**Possible values:** `true` or `false`
**Default value:** `false` | `hideOngoing` | Hides calendar events that have already started.

**Possible values:** `true` or `false`
**Default value:** `false` | `excludedEvents` | An array of words / phrases from event titles that will be excluded from being shown.

Additionally advanced filter objects can be passed in. Below is the configuration for the advance filtering object.
**Required**
`filterBy` - string used to determine if filter is applied.
**Optional**
`until` - Time before an event to display it Ex: [`'3 days'`, `'2 months'`, `'1 week'`]
`caseSensitive` - By default, excludedEvents are case insensitive, set this to true to enforce case sensitivity
`regex` - set to `true` if filterBy is a regex. For those not familiar with regex it is used for pattern matching, please see [here](https://regexr.com/) for more info.

**Example:** `['Birthday', 'Hide This Event', {filterBy: 'Payment', until: '6 days', caseSensitive: true}, {filterBy: '^[0-9]{1,}.*', regex: true}]`
**Default value:** `[]` +| `sliceMultiDayEvents` | If this is set to true, events exceeding at least one midnight will be sliced into separate events including a counter like (1/2). This is especially helpful in "dateheaders" mode. Events will be sliced at midnight, end time for all events but the last will be 23:59 **Default value:** `true` + ### Calendar configuration diff --git a/modules/default/calendar/calendar.js b/modules/default/calendar/calendar.js index 38b04269..2023b79a 100755 --- a/modules/default/calendar/calendar.js +++ b/modules/default/calendar/calendar.js @@ -46,7 +46,8 @@ Module.register("calendar", { "'s birthday": "" }, broadcastEvents: true, - excludedEvents: [] + excludedEvents: [], + sliceMultiDayEvents: false }, // Define required scripts. @@ -447,7 +448,31 @@ Module.register("calendar", { } event.url = c; event.today = event.startDate >= today && event.startDate < (today + 24 * 60 * 60 * 1000); - events.push(event); + + /* if sliceMultiDayEvents is set to true, multiday events (events exceeding at least one midnight) are sliced into days, + * otherwise, esp. in dateheaders mode it is not clear how long these events are. + */ + if (this.config.sliceMultiDayEvents) { + var midnight = moment(event.startDate, "x").clone().startOf("day").add(1, "day").format("x"); //next midnight + var count = 1; + var maxCount = Math.ceil(((event.endDate - 1) - moment(event.startDate, "x").endOf('day').format("x"))/(1000*60*60*24)) + 1 + if (event.endDate > midnight) { + while (event.endDate > midnight) { + var nextEvent = JSON.parse(JSON.stringify(event)); //make a copy without reference to the original event + nextEvent.startDate = midnight; + event.endDate = midnight; + event.title += " ("+count+"/"+maxCount+")"; + events.push(event); + event = nextEvent; + count += 1; + midnight = moment(midnight, "x").add(1, "day").format("x"); //move further one day for next split + } + event.title += " ("+count+"/"+maxCount+")"; + } + events.push(event); + } else { + events.push(event); + } } }