Skip to content

Commit

Permalink
Merge pull request #1143 from totaldebug/develop
Browse files Browse the repository at this point in the history
Bug Fixes
  • Loading branch information
marksie1988 authored Sep 12, 2023
2 parents 85be60c + 0f786af commit 309ff9c
Show file tree
Hide file tree
Showing 6 changed files with 470 additions and 295 deletions.
22 changes: 11 additions & 11 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,12 @@
"author": "Steven Marks",
"license": "ISC",
"devDependencies": {
"@babel/cli": "^7.22.10",
"@babel/core": "^7.22.11",
"@babel/cli": "^7.22.15",
"@babel/core": "^7.22.17",
"@babel/plugin-proposal-class-properties": "^7.18.6",
"@babel/plugin-proposal-decorators": "^7.22.10",
"@babel/plugin-proposal-decorators": "^7.22.15",
"@babel/plugin-transform-template-literals": "^7.22.5",
"@babel/preset-env": "^7.22.14",
"@babel/preset-env": "^7.22.15",
"@rollup/plugin-babel": "^6.0.3",
"@rollup/plugin-commonjs": "^25.0.4",
"@rollup/plugin-eslint": "^9.0.4",
Expand All @@ -38,23 +38,23 @@
"@semantic-release/changelog": "^6.0.3",
"@semantic-release/exec": "^6.0.3",
"@semantic-release/git": "^10.0.1",
"@typescript-eslint/eslint-plugin": "^6.5.0",
"@typescript-eslint/parser": "^6.5.0",
"@typescript-eslint/eslint-plugin": "^6.7.0",
"@typescript-eslint/parser": "^6.7.0",
"babel-preset-minify": "^0.5.2",
"commitizen": "^4.3.0",
"conventional-changelog-conventionalcommits": "^7.0.1",
"conventional-changelog-conventionalcommits": "^7.0.2",
"cz-conventional-changelog": "^3.3.0",
"eslint": "^8.48.0",
"eslint": "^8.49.0",
"eslint-config-prettier": "^9.0.0",
"eslint-plugin-prettier": "^5.0.0",
"prettier": "^3.0.3",
"rollup": "^3.28.1",
"rollup": "^3.29.1",
"rollup-plugin-serve": "^2.0.2",
"rollup-plugin-typescript2": "^0.35.0",
"semantic-release": "^21.1.1"
},
"dependencies": {
"@formatjs/icu-messageformat-parser": "^2.6.0",
"@formatjs/icu-messageformat-parser": "^2.6.2",
"@lit-labs/scoped-registry-mixin": "^1.0.1",
"@lit/reactive-element": "^1.6.3",
"@material/mwc-formfield": "^0.27.0",
Expand All @@ -73,7 +73,7 @@
"dayjs": "^1.11.9",
"lit": "^2.8.0",
"lit-element": "^3.3.3",
"npm": "^10.0.0",
"npm": "^10.1.0",
"typescript": "^5.2.2"
},
"resolutions": {
Expand Down
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
62 changes: 36 additions & 26 deletions src/lib/event.class.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import dayjs from 'dayjs';
import utc from 'dayjs/plugin/utc';

dayjs.extend(utc)
/**
* Creates an generalized Calendar Event to use when creating the calendar card
* There can be Google Events and CalDav Events. This class normalizes those
Expand Down Expand Up @@ -70,9 +72,12 @@ export default class EventClass {
*/
get startDateTime() {
if (this._startDateTime === undefined) {
const date =
(this.rawEvent.start && this.rawEvent.start.date) || this.rawEvent.start.dateTime || this.rawEvent.start || '';
this._startDateTime = this._processDate(date);
if (this.rawEvent.start.date) {
this._startDateTime = this._processDate(dayjs(this.rawEvent.start.date, 'YYYY-MM-DD').startOf('day'));
} else {
this._startDateTime = this._processDate(dayjs(this.rawEvent.start.dateTime));
}

}

return this._startDateTime!.clone();
Expand All @@ -84,12 +89,15 @@ export default class EventClass {
*/
get endDateTime() {
if (this._endDateTime === undefined) {
const date = (this.rawEvent.end && this.rawEvent.end.date) || this.rawEvent.end.dateTime || this.rawEvent.end;
this._endDateTime = this._processDate(date, true);
if (this.rawEvent.end.date) {
this._endDateTime = this._processDate(dayjs(this.rawEvent.end.date, 'YYYY-MM-DD').subtract(1, 'day').endOf('day'), true);
} else {
this._endDateTime = this._processDate(dayjs(this.rawEvent.end.dateTime), true);
}
}

return this._endDateTime!.clone();
}

get addDays() {
return this.rawEvent.addDays !== undefined ? this.rawEvent.addDays : false;
}
Expand All @@ -114,27 +122,22 @@ export default class EventClass {

/**
*
* @param {string} date
* @param {boolean} isEndDate
* @param {dayjs} date
* @param {boolean} isEndDateTime
*/
_processDate(date, isEndDate = false) {
if (!date) {
return date;
}

date = dayjs(date);
_processDate(date, isEndDateTime = false) {

// add days to a start date for multi day event
if (this.addDays !== false) {
if (!isEndDate && this.addDays) {
if (!isEndDateTime && this.addDays) {
date = date.add(this.addDays, 'days');
}

// if not the last day and we are modifying the endDateTime then
// set end dateTimeDate as end of start day for that partial event
if (!this.isLastDay && isEndDate) {
date = dayjs(this.startDateTime).endOf('day');
} else if (this.isLastDay && !isEndDate) {
if (!this.isLastDay && isEndDateTime) {
date = this.startDateTime.endOf('day');
} else if (!this.isFirstDay && !isEndDateTime) {
// if last day and start time then set start as start of day
date = date.startOf('day');
}
Expand All @@ -148,6 +151,7 @@ export default class EventClass {
* @return {boolean}
*/
get isRecurring() {

return !!this.rawEvent.recurringEventId;
}

Expand Down Expand Up @@ -218,18 +222,20 @@ export default class EventClass {
* @return {Boolean}
*/
get isAllDayEvent() {
const isMidnightStart = this.startDateTime.startOf('day').diff(this.startDateTime) === 0;
const isMidnightEnd = this.endDateTime.startOf('day').diff(this.endDateTime) === 0;
if (isMidnightStart && isMidnightEnd) {
// if start and end are both "date" then it's an all day event
if (this.rawEvent.start.date && this.rawEvent.end.date) {
return true;
}

// check for days that are between multi days - they ARE all day
if (!this.isFirstDay && !this.isLastDay && this.daysLong && this._globalConfig.showMultiDay) {
return true;
}
// if start and end are both "dateTime" then it's NOT an all day event
if (this.rawEvent.start.dateTime && this.rawEvent.end.dateTime) {
return false
}

return isMidnightStart && isMidnightEnd;
return undefined;
}

/**
Expand All @@ -248,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
5 changes: 3 additions & 2 deletions src/lib/event.func.ts
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,9 @@ export function processEvents(allEvents: any[], config: atomicCardConfig) {
// Update calendar names for the kept events and append removed calendar names
updatedEvents.forEach(event => {
const eventIdentifier = event.title + '|' + event.startDateTime + '|' + event.endDateTime;
event.originName = eventMap[eventIdentifier].calendars.join(', ');
if (eventMap[eventIdentifier]) { // Check if eventMap[eventIdentifier] is defined
event.originName = eventMap[eventIdentifier].calendars.join(', ');
}
});

newEvents = updatedEvents;
Expand All @@ -358,6 +360,5 @@ export function processEvents(allEvents: any[], config: atomicCardConfig) {
newEvents.length = config.maxEventCount;
}
newEvents = sortEventsByEntity(newEvents, config.entities)

return newEvents;
}
28 changes: 21 additions & 7 deletions src/lib/eventMode.html.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,22 +79,36 @@ export function getHoursHTML(config: atomicCardConfig, event: EventClass) {
${config.fullDayEventText}, ${config.untilText!.toLowerCase()}
${getCurrDayAndMonth(event.endDateTime)}
`;
} else if (event.isAllDayEvent && event.isMultiDay &&
}
// 2. Is an all day event, over multiple days and the start time is before today or the
// end time is after today -> 'All dat, until end date'
else if (event.isAllDayEvent && event.isMultiDay &&
(event.startDateTime.isBefore(today, 'day') || event.endDateTime.isAfter(today, 'day'))) {
return html`
${config.fullDayEventText}, ${config.untilText!.toLowerCase()}
${getCurrDayAndMonth(event.endDateTime)}
`;
} else if (event.isAllDayEvent) {
}
// 3. Is an all day event, not matching 1 or 2 -> 'All Day'
else if (event.isAllDayEvent) {
return html`${config.fullDayEventText}`;
} else if (event.startDateTime.isBefore(today, 'day') && event.endDateTime.isAfter(today, 'day')) {
}
// 4. Starts before today, ends after today -> 'Until end date'
else if (event.startDateTime.isBefore(today, 'day') && event.endDateTime.isAfter(today, 'day')) {
return html`${config.untilText} ${getCurrDayAndMonth(event.endDateTime)}`;
} else if (event.startTimeToShow.isBefore(today, 'day') && event.endDateTime.isSame(today, 'day')) {

}
// 5. starts before today, ends today -> 'Until end time'
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')} `;
} else if (!event.startDateTime.isBefore(today, 'day') && event.endDateTime.isAfter(event.startDateTime, 'day')) {
}
// 6. Does not start before today, ends after start
else if (!event.startDateTime.isBefore(today, 'day') && event.endDateTime.isAfter(event.startDateTime, 'day')) {
return html`${event.startDateTime.format('LT')}, ${config.untilText!.toLowerCase()}
${getCurrDayAndMonth(event.endDateTime)} ${event.endDateTime.format('HH:mm')}`;
} else {
${getCurrDayAndMonth(event.endDateTime)} ${event.endDateTime.format('HH:mm')}`;
}
// 7. anything that doesnt fit -> 'start time - end time'
else {
return html`${event.startDateTime.format('LT')} - ${event.endDateTime.format('LT')} `;
}
}
Expand Down
Loading

0 comments on commit 309ff9c

Please sign in to comment.