From 0b620a07effd2e2b9c002a40dfc5c392961c332d Mon Sep 17 00:00:00 2001 From: kolaente Date: Tue, 8 Dec 2020 15:43:51 +0100 Subject: [PATCH] Fix parsing task done at date --- src/models/task.js | 15 +++++++++++---- src/services/task.js | 16 ++++++++++++---- 2 files changed, 23 insertions(+), 8 deletions(-) diff --git a/src/models/task.js b/src/models/task.js index 0b1c8e42..091f58b7 100644 --- a/src/models/task.js +++ b/src/models/task.js @@ -3,6 +3,13 @@ import UserModel from './user' import LabelModel from './label' import AttachmentModel from './attachment' +const parseDate = date => { + if (date && !date.startsWith('0001')) { + return new Date(date) + } + return null +} + export default class TaskModel extends AbstractModel { defaultColor = '198CFF' @@ -14,9 +21,10 @@ export default class TaskModel extends AbstractModel { this.listId = Number(this.listId) // Make date objects from timestamps - this.dueDate = this.dueDate && !this.dueDate.startsWith('0001') ? new Date(this.dueDate) : null - this.startDate = this.startDate && !this.startDate.startsWith('0001') ? new Date(this.startDate) : null - this.endDate = this.endDate && !this.endDate.startsWith('0001') ? new Date(this.endDate) : null + this.dueDate = parseDate(this.dueDate) + this.startDate = parseDate(this.startDate) + this.endDate = parseDate(this.endDate) + this.doneAt = parseDate(this.doneAt) // Cancel all scheduled notifications for this task to be sure to only have available notifications this.cancelScheduledNotifications() @@ -69,7 +77,6 @@ export default class TaskModel extends AbstractModel { this.created = new Date(this.created) this.updated = new Date(this.updated) - this.doneAt = this.doneAt ? new Date(this.doneAt) : null } defaults() { diff --git a/src/services/task.js b/src/services/task.js index 108861ae..39364a78 100644 --- a/src/services/task.js +++ b/src/services/task.js @@ -5,6 +5,14 @@ import LabelService from './label' import {formatISO} from 'date-fns' +const parseDate = date => { + if (date) { + return formatISO(new Date(date)) + } + + return null +} + export default class TaskService extends AbstractService { constructor() { super({ @@ -34,12 +42,12 @@ export default class TaskService extends AbstractService { model.listId = Number(model.listId) // Convert dates into an iso string - model.dueDate = !model.dueDate ? null : formatISO(new Date(model.dueDate)) - model.startDate = !model.startDate ? null : formatISO(new Date(model.startDate)) - model.endDate = !model.endDate ? null : formatISO(new Date(model.endDate)) + model.dueDate = parseDate(model.dueDate) + model.startDate = parseDate(model.startDate) + model.endDate = parseDate(model.endDate) + model.doneAt = parseDate(model.doneAt) model.created = formatISO(new Date(model.created)) model.updated = formatISO(new Date(model.updated)) - model.doneAt = formatISO(new Date(model.doneAt)) // remove all nulls, these would create empty reminders for (const index in model.reminderDates) {