mirror of
https://github.com/MichMich/MagicMirror.git
synced 2025-06-27 11:50:00 +00:00
included split function to split multiday events
This commit is contained in:
parent
b79b49e8f3
commit
d9fcc46994
@ -52,6 +52,8 @@ The following properties can be configured:
|
||||
| `hidePrivate` | Hides private calendar events. <br><br> **Possible values:** `true` or `false` <br> **Default value:** `false`
|
||||
| `hideOngoing` | Hides calendar events that have already started. <br><br> **Possible values:** `true` or `false` <br> **Default value:** `false`
|
||||
| `excludedEvents` | An array of words / phrases from event titles that will be excluded from being shown. <br><br>Additionally advanced filter objects can be passed in. Below is the configuration for the advance filtering object.<br>**Required**<br>`filterBy` - string used to determine if filter is applied.<br>**Optional**<br>`until` - Time before an event to display it Ex: [`'3 days'`, `'2 months'`, `'1 week'`]<br>`caseSensitive` - By default, excludedEvents are case insensitive, set this to true to enforce case sensitivity<br>`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.<br><br> **Example:** `['Birthday', 'Hide This Event', {filterBy: 'Payment', until: '6 days', caseSensitive: true}, {filterBy: '^[0-9]{1,}.*', regex: true}]` <br> **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
|
||||
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user