Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 33 additions & 1 deletion MMM-GoogleCalendar.js
Original file line number Diff line number Diff line change
Expand Up @@ -431,7 +431,15 @@ Module.register("MMM-GoogleCalendar", {
}
} else {
// Show relative times
if (event.startDate >= now) {
if (event.fullDayEvent) {
// All-day events (e.g. holidays) have no meaningful time of day,
// so "at 12:00 AM", "in 5 hours" or "Running" is misleading.
// Show a date-only label instead: Today / Tomorrow / weekday /
// date. (issue #85)
timeWrapper.innerHTML = this.fullDayEventRelativeLabel(
event.startDate
);
} else if (event.startDate >= now) {
// Use relative time
if (!this.config.hideTime) {
timeWrapper.innerHTML = this.capFirst(
Expand Down Expand Up @@ -1095,6 +1103,30 @@ Module.register("MMM-GoogleCalendar", {
return string.charAt(0).toUpperCase() + string.slice(1);
},

/**
* Builds a date-only relative label for an all-day event (no time of day):
* Today / Tomorrow / weekday / configured date format. Used so holidays and
* other all-day events don't show misleading times such as "in 5 hours" or
* "Running" (issue #85).
*
* Relies only on existing infrastructure: TODAY/TOMORROW are MagicMirror
* core translation keys, and moment is locale-aware, so this works in every
* supported language without adding translation strings.
*
* @param {number} startDate The event start timestamp.
* @returns {string} The capitalized relative label.
*/
fullDayEventRelativeLabel: function (startDate) {
return this.capFirst(
moment(startDate).calendar(null, {
sameDay: `[${this.translate("TODAY")}]`,
nextDay: `[${this.translate("TOMORROW")}]`,
nextWeek: "dddd",
sameElse: this.config.dateFormat
})
);
},

/**
* Transforms the title of an event for usage.
* Replaces parts of the text as defined in config.titleReplace.
Expand Down
17 changes: 17 additions & 0 deletions __tests__/MMM-GoogleCalendar.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -156,5 +156,22 @@ describe('MMM-GoogleCalendar', () => {
});
});

describe('fullDayEventRelativeLabel', () => {
test('builds a date-only label from core TODAY/TOMORROW keys, no time (issue #85)', () => {
GCal.translate = jest.fn((key) => key);
GCal.config.dateFormat = 'MMM Do';

const label = GCal.fullDayEventRelativeLabel(0);

// Returns a non-empty capitalized string (moment is mocked).
expect(typeof label).toBe('string');
expect(label.length).toBeGreaterThan(0);

// Uses date-only relative keys (no "at LT" time component).
expect(GCal.translate).toHaveBeenCalledWith('TODAY');
expect(GCal.translate).toHaveBeenCalledWith('TOMORROW');
});
});

// Add more describe blocks for other pure functions if identified
});
Loading