From 8d20832bc57e3fd54cb65468a8f87bab9a16224c Mon Sep 17 00:00:00 2001 From: Karsten Hassel Date: Mon, 24 Jun 2024 21:52:19 +0200 Subject: [PATCH] [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 --- CHANGELOG.md | 4 ++++ modules/default/calendar/calendar.js | 15 ++++++++++++--- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 916c6877..cada597d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,8 +9,12 @@ This project adheres to [Semantic Versioning](https://semver.org/). _This release is scheduled to be released on 2024-07-01._ +Thanks to: @kleinmantara (to be continued before release) + ### Added +- [calendar] Added config option "showEndsOnlyWithDuration" for default calendar + ### Removed - [test suite] delete node v18 support diff --git a/modules/default/calendar/calendar.js b/modules/default/calendar/calendar.js index a3f59759..4b0409c0 100644 --- a/modules/default/calendar/calendar.js +++ b/modules/default/calendar/calendar.js @@ -29,6 +29,7 @@ Module.register("calendar", { dateEndFormat: "LT", fullDayEventDateFormat: "MMM Do", showEnd: false, + showEndsOnlyWithDuration: false, getRelative: 6, hidePrivate: false, hideOngoing: false, @@ -388,7 +389,11 @@ Module.register("calendar", { // Add endDate to dataheaders if showEnd is enabled if (this.config.showEnd) { - timeWrapper.innerHTML += ` - ${CalendarUtils.capFirst(moment(event.endDate, "x").format("LT"))}`; + 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"))}`; + } } eventWrapper.appendChild(timeWrapper); @@ -407,8 +412,12 @@ Module.register("calendar", { timeWrapper.innerHTML = CalendarUtils.capFirst(moment(event.startDate, "x").format(this.config.dateFormat)); // Add end time if showEnd if (this.config.showEnd) { - timeWrapper.innerHTML += "-"; - timeWrapper.innerHTML += CalendarUtils.capFirst(moment(event.endDate, "x").format(this.config.dateEndFormat)); + if (this.config.showEndsOnlyWithDuration && event.startDate === event.endDate) { + // no duration here, don't display end + } else { + timeWrapper.innerHTML += "-"; + timeWrapper.innerHTML += CalendarUtils.capFirst(moment(event.endDate, "x").format(this.config.dateEndFormat)); + } } // For full day events we use the fullDayEventDateFormat if (event.fullDayEvent) {