Fix parsing task done at date

This commit is contained in:
kolaente 2020-12-08 15:43:51 +01:00
parent b885eb7ff2
commit 0b620a07ef
No known key found for this signature in database
GPG key ID: F40E70337AB24C9B
2 changed files with 23 additions and 8 deletions

View file

@ -3,6 +3,13 @@ import UserModel from './user'
import LabelModel from './label' import LabelModel from './label'
import AttachmentModel from './attachment' import AttachmentModel from './attachment'
const parseDate = date => {
if (date && !date.startsWith('0001')) {
return new Date(date)
}
return null
}
export default class TaskModel extends AbstractModel { export default class TaskModel extends AbstractModel {
defaultColor = '198CFF' defaultColor = '198CFF'
@ -14,9 +21,10 @@ export default class TaskModel extends AbstractModel {
this.listId = Number(this.listId) this.listId = Number(this.listId)
// Make date objects from timestamps // Make date objects from timestamps
this.dueDate = this.dueDate && !this.dueDate.startsWith('0001') ? new Date(this.dueDate) : null this.dueDate = parseDate(this.dueDate)
this.startDate = this.startDate && !this.startDate.startsWith('0001') ? new Date(this.startDate) : null this.startDate = parseDate(this.startDate)
this.endDate = this.endDate && !this.endDate.startsWith('0001') ? new Date(this.endDate) : null 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 // Cancel all scheduled notifications for this task to be sure to only have available notifications
this.cancelScheduledNotifications() this.cancelScheduledNotifications()
@ -69,7 +77,6 @@ export default class TaskModel extends AbstractModel {
this.created = new Date(this.created) this.created = new Date(this.created)
this.updated = new Date(this.updated) this.updated = new Date(this.updated)
this.doneAt = this.doneAt ? new Date(this.doneAt) : null
} }
defaults() { defaults() {

View file

@ -5,6 +5,14 @@ import LabelService from './label'
import {formatISO} from 'date-fns' import {formatISO} from 'date-fns'
const parseDate = date => {
if (date) {
return formatISO(new Date(date))
}
return null
}
export default class TaskService extends AbstractService { export default class TaskService extends AbstractService {
constructor() { constructor() {
super({ super({
@ -34,12 +42,12 @@ export default class TaskService extends AbstractService {
model.listId = Number(model.listId) model.listId = Number(model.listId)
// Convert dates into an iso string // Convert dates into an iso string
model.dueDate = !model.dueDate ? null : formatISO(new Date(model.dueDate)) model.dueDate = parseDate(model.dueDate)
model.startDate = !model.startDate ? null : formatISO(new Date(model.startDate)) model.startDate = parseDate(model.startDate)
model.endDate = !model.endDate ? null : formatISO(new Date(model.endDate)) model.endDate = parseDate(model.endDate)
model.doneAt = parseDate(model.doneAt)
model.created = formatISO(new Date(model.created)) model.created = formatISO(new Date(model.created))
model.updated = formatISO(new Date(model.updated)) model.updated = formatISO(new Date(model.updated))
model.doneAt = formatISO(new Date(model.doneAt))
// remove all nulls, these would create empty reminders // remove all nulls, these would create empty reminders
for (const index in model.reminderDates) { for (const index in model.reminderDates) {