Skip to content

Commit

Permalink
fix: multidayevents not showing correct hours
Browse files Browse the repository at this point in the history
  • Loading branch information
marksie1988 committed Sep 12, 2023
1 parent 3c241d3 commit f9c87b8
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 6 deletions.
8 changes: 7 additions & 1 deletion src/lib/common.html.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,14 @@ export function getMultiDayEventParts(config: atomicCardConfig, event: EventClas
if (!config.showMultiDayEventParts == true || event.addDays == false && event.daysLong == undefined) {
return
}
if (config.showMultiDayEventParts == true && event.addDays >= 1 && event.daysLong) {
return html`(${event.addDays}/${event.daysLong})`
}
if (config.showMultiDayEventParts == true && event.addDays == false && event.daysLong) {
const daysSinceStart = dayjs().diff(event.startDateTime, 'day')
return html`(${daysSinceStart}/${event.daysLong})`
}

return html`(${event.addDays + 1}/${event.daysLong})`
}

/**
Expand Down
10 changes: 7 additions & 3 deletions src/lib/event.class.ts
Original file line number Diff line number Diff line change
Expand Up @@ -254,14 +254,18 @@ export default class EventClass {
daysLong = fullDays;
}

for (let i = 0; i < daysLong; i++) {
for (let i = 1; i < daysLong; i++) {
// copy event then add the current day/total days to 'new' event
const copiedEvent = JSON.parse(JSON.stringify(newEvent.rawEvent));
// count the loops, this shows which day of the event we are on
copiedEvent.addDays = i;
// count the total number of days in the event
copiedEvent.daysLong = daysLong;

copiedEvent._isFirstDay = i === 0;
copiedEvent._isLastDay = i === (daysLong - 1) && i > 0;
// is this the first day of the event?
copiedEvent._isFirstDay = i === 1;
// is this the last day of the event?
copiedEvent._isLastDay = i === (daysLong - 1) && i > 1;

// Create event object for each of the days the multi-event occurs on
const partialEvent: EventClass = new EventClass(copiedEvent, this._globalConfig);
Expand Down
1 change: 0 additions & 1 deletion src/lib/event.func.ts
Original file line number Diff line number Diff line change
Expand Up @@ -360,6 +360,5 @@ export function processEvents(allEvents: any[], config: atomicCardConfig) {
newEvents.length = config.maxEventCount;
}
newEvents = sortEventsByEntity(newEvents, config.entities)

return newEvents;
}
2 changes: 1 addition & 1 deletion src/lib/eventMode.html.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ export function getHoursHTML(config: atomicCardConfig, event: EventClass) {

}
// 5. starts before today, ends today -> 'Until end time'
else if (event.startDateTime.isBefore(today, 'day') && event.endDateTime.isSame(today, 'day')) {
else if (event.startDateTime.isBefore(today, 'day') && event.endDateTime.isSame(today, 'day') || event.isLastDay && event.endDateTime.isSame(today, 'day')) {
return html`${config.untilText} ${event.endDateTime.format('LT')} `;
}
// 6. Does not start before today, ends after start
Expand Down

0 comments on commit f9c87b8

Please sign in to comment.