diff --git a/CHANGELOG.md b/CHANGELOG.md index 153031cd..94e4e6e3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -18,6 +18,7 @@ This project adheres to [Semantic Versioning](http://semver.org/). - Added autoLocation options for weather forcast and current weather modules. - Added autoTimezone option for the default clock module. - Danish translation for "Feels" and "Weeks" +- Added option to split multiple day events in calendar to separate numbered events ### Updated - Bumped the Electron dependency to v3.0.13 to support the most recent Raspbian. [#1500](https://github.com/MichMich/MagicMirror/issues/1500) diff --git a/modules/default/calendar/README.md b/modules/default/calendar/README.md index e0d727c8..72aedd74 100755 --- a/modules/default/calendar/README.md +++ b/modules/default/calendar/README.md @@ -53,6 +53,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 96ab322c..c647c505 100755 --- a/modules/default/calendar/calendar.js +++ b/modules/default/calendar/calendar.js @@ -47,7 +47,8 @@ Module.register("calendar", { "'s birthday": "" }, broadcastEvents: true, - excludedEvents: [] + excludedEvents: [], + sliceMultiDayEvents: false }, // Define required scripts. @@ -448,7 +449,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); + } } }