Skip to content
Open
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
18 changes: 16 additions & 2 deletions lib/meal-planning-calendar-event.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,17 @@ class MealPlanningCalendarEvent {
*/
constructor(event, {client, protobuf, uid, calendarId}) {
this.identifier = event.identifier || uuid();
this.date = typeof event.date === 'string' ? new Date(event.date) : event.date || new Date();
if (typeof event.date === 'string') {
this.date = new Date(event.date);
} else if (event.date instanceof Date) {
this.date = event.date;
} else if (Object.prototype.hasOwnProperty.call(event, 'date')) {
// Queue entries from the API have a null date.
this.date = null;
} else {
this.date = new Date();
}

this.details = event.details;
this.labelId = event.labelId;
this.logicalTimestamp = event.logicalTimestamp;
Expand Down Expand Up @@ -66,11 +76,15 @@ class MealPlanningCalendarEvent {
}

_encode() {
const encodedDate = this.date instanceof Date && !Number.isNaN(this.date.getTime())
? this.date.toISOString().slice(0, 10)
: undefined;

return new this._protobuf.PBCalendarEvent({
identifier: this.identifier,
logicalTimestamp: this.logicalTimestamp,
calendarId: this._calendarId,
date: this.date.toISOString().slice(0, 10), // Only date, no time
date: encodedDate,
title: this.title,
details: this.details,
recipeId: this.recipeId,
Expand Down