[calendar] add config option "showEndsOnlyWithDuration" (#3477)

redo and rebase changes made in PR
https://github.com/MagicMirrorOrg/MagicMirror/pull/2968 by
https://github.com/kleinmantara
This commit is contained in:
Karsten Hassel 2024-06-24 21:52:19 +02:00 committed by GitHub
parent e95c144c3e
commit 8d20832bc5
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 16 additions and 3 deletions

View File

@ -9,8 +9,12 @@ This project adheres to [Semantic Versioning](https://semver.org/).
_This release is scheduled to be released on 2024-07-01._ _This release is scheduled to be released on 2024-07-01._
Thanks to: @kleinmantara (to be continued before release)
### Added ### Added
- [calendar] Added config option "showEndsOnlyWithDuration" for default calendar
### Removed ### Removed
- [test suite] delete node v18 support - [test suite] delete node v18 support

View File

@ -29,6 +29,7 @@ Module.register("calendar", {
dateEndFormat: "LT", dateEndFormat: "LT",
fullDayEventDateFormat: "MMM Do", fullDayEventDateFormat: "MMM Do",
showEnd: false, showEnd: false,
showEndsOnlyWithDuration: false,
getRelative: 6, getRelative: 6,
hidePrivate: false, hidePrivate: false,
hideOngoing: false, hideOngoing: false,
@ -388,8 +389,12 @@ Module.register("calendar", {
// Add endDate to dataheaders if showEnd is enabled // Add endDate to dataheaders if showEnd is enabled
if (this.config.showEnd) { if (this.config.showEnd) {
if (this.config.showEndsOnlyWithDuration && event.startDate === event.endDate) {
// no duration here, don't display end
} else {
timeWrapper.innerHTML += ` - ${CalendarUtils.capFirst(moment(event.endDate, "x").format("LT"))}`; timeWrapper.innerHTML += ` - ${CalendarUtils.capFirst(moment(event.endDate, "x").format("LT"))}`;
} }
}
eventWrapper.appendChild(timeWrapper); eventWrapper.appendChild(timeWrapper);
@ -407,9 +412,13 @@ Module.register("calendar", {
timeWrapper.innerHTML = CalendarUtils.capFirst(moment(event.startDate, "x").format(this.config.dateFormat)); timeWrapper.innerHTML = CalendarUtils.capFirst(moment(event.startDate, "x").format(this.config.dateFormat));
// Add end time if showEnd // Add end time if showEnd
if (this.config.showEnd) { if (this.config.showEnd) {
if (this.config.showEndsOnlyWithDuration && event.startDate === event.endDate) {
// no duration here, don't display end
} else {
timeWrapper.innerHTML += "-"; timeWrapper.innerHTML += "-";
timeWrapper.innerHTML += CalendarUtils.capFirst(moment(event.endDate, "x").format(this.config.dateEndFormat)); timeWrapper.innerHTML += CalendarUtils.capFirst(moment(event.endDate, "x").format(this.config.dateEndFormat));
} }
}
// For full day events we use the fullDayEventDateFormat // For full day events we use the fullDayEventDateFormat
if (event.fullDayEvent) { if (event.fullDayEvent) {
//subtract one second so that fullDayEvents end at 23:59:59, and not at 0:00:00 one the next day //subtract one second so that fullDayEvents end at 23:59:59, and not at 0:00:00 one the next day