MCPcopy Index your code
hub / github.com/MagicMirrorOrg/MagicMirror / buildAbsoluteTimeText

Function buildAbsoluteTimeText

defaultmodules/calendar/calendar.js:730–789  ·  view source on GitHub ↗
(event, eventStartDateMoment, eventEndDateMoment, now)

Source from the content-addressed store, hash-verified

728 },
729
730 buildAbsoluteTimeText (event, eventStartDateMoment, eventEndDateMoment, now) {
731 let timeText = CalendarUtils.capFirst(eventStartDateMoment.format(this.config.dateFormat));
732
733 if (this.config.showEnd && (!this.config.showEndsOnlyWithDuration || this.hasEventDuration(event))) {
734 const sameDay = this.isSameDay(eventStartDateMoment, eventEndDateMoment);
735 if (sameDay && !this.dateFormatIncludesTime()) {
736 timeText += `, ${eventStartDateMoment.format("LT")}`;
737 }
738 timeText += `-${this.formatTimedEventEnd(eventStartDateMoment, eventEndDateMoment)}`;
739 }
740
741 if (event.fullDayEvent) {
742 const adjustedEndMoment = this.getAdjustedFullDayEndMoment(eventEndDateMoment);
743 timeText = CalendarUtils.capFirst(eventStartDateMoment.format(this.config.fullDayEventDateFormat));
744
745 if (this.config.showEnd && !this.config.showEndsOnlyWithDuration && !eventStartDateMoment.isSame(adjustedEndMoment, "d")) {
746 timeText += `-${CalendarUtils.capFirst(adjustedEndMoment.format(this.config.fullDayEventDateFormat))}`;
747 } else if (!eventStartDateMoment.isSame(adjustedEndMoment, "d") && eventStartDateMoment.isBefore(now)) {
748 timeText = CalendarUtils.capFirst(now.format(this.config.fullDayEventDateFormat));
749 }
750
751 if (this.config.nextDaysRelative) {
752 let relativeLabel = false;
753 if (event.today) {
754 timeText = CalendarUtils.capFirst(this.translate("TODAY"));
755 relativeLabel = true;
756 } else if (event.yesterday) {
757 timeText = CalendarUtils.capFirst(this.translate("YESTERDAY"));
758 relativeLabel = true;
759 } else if (event.tomorrow) {
760 timeText = CalendarUtils.capFirst(this.translate("TOMORROW"));
761 relativeLabel = true;
762 } else if (event.dayAfterTomorrow && this.translate("DAYAFTERTOMORROW") !== "DAYAFTERTOMORROW") {
763 timeText = CalendarUtils.capFirst(this.translate("DAYAFTERTOMORROW"));
764 relativeLabel = true;
765 }
766
767 if (relativeLabel && this.config.showEnd && !this.config.showEndsOnlyWithDuration && !eventStartDateMoment.isSame(adjustedEndMoment, "d")) {
768 timeText += `-${CalendarUtils.capFirst(adjustedEndMoment.format(this.config.fullDayEventDateFormat))}`;
769 }
770 }
771
772 return timeText;
773 }
774
775 if (this.config.getRelative > 0 && eventStartDateMoment.isBefore(now)) {
776 return CalendarUtils.capFirst(
777 this.translate("RUNNING", {
778 fallback: `${this.translate("RUNNING")} {timeUntilEnd}`,
779 timeUntilEnd: eventEndDateMoment.fromNow(true)
780 })
781 );
782 }
783
784 if (this.config.urgency > 0 && eventStartDateMoment.diff(now, "d") < this.config.urgency) {
785 return CalendarUtils.capFirst(eventStartDateMoment.fromNow());
786 }
787

Callers

nothing calls this directly

Calls 1

translateMethod · 0.80

Tested by

no test coverage detected