Skip to content

Commit f903475

Browse files
committed
Fix missed switches to dayjs and immutability change
1 parent 0ce572b commit f903475

File tree

5 files changed

+26
-22
lines changed

5 files changed

+26
-22
lines changed

src/components/AppNavigation/Trashbin.vue

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -209,9 +209,9 @@ export default {
209209
if (vobject.isEvent) {
210210
const event = toRaw(vobject?.calendarComponent.getFirstComponent('VEVENT'))
211211
if (event?.startDate.jsDate && event?.isAllDay()) {
212-
subline += ' · ' + moment(event.startDate.jsDate).format('LL')
212+
subline += ' · ' + dayjs(event.startDate.jsDate).format('LL')
213213
} else if (event?.startDate.jsDate) {
214-
subline += ' · ' + moment(event?.startDate.jsDate).format('LLL')
214+
subline += ' · ' + dayjs(event?.startDate.jsDate).format('LLL')
215215
}
216216
}
217217
const color = vobject.calendarComponent.getComponentIterator().next().value?.color

src/models/task.js

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
2424
*
2525
*/
26+
import dayjs from 'dayjs'
2627

2728
import ICAL from 'ical.js'
2829
import { randomUUID } from '../utils/crypto.js'
@@ -93,27 +94,27 @@ export default class Task {
9394
this._priority = this.vtodo.getFirstPropertyValue('priority') || 0
9495
this._complete = this.vtodo.getFirstPropertyValue('percent-complete') || 0
9596
this._completedDate = this.vtodo.getFirstPropertyValue('completed')
96-
this._completedDateMoment = moment(this._completedDate, 'YYYYMMDDTHHmmssZ')
97+
this._completedDateMoment = dayjs(this._completedDate, 'YYYYMMDDTHHmmssZ')
9798
this._completed = !!this._completedDate
9899
this._status = this.vtodo.getFirstPropertyValue('status')
99100
this._note = this.vtodo.getFirstPropertyValue('description') || ''
100101
this._related = this.getParent()?.getFirstValue() || null
101102
this._hideSubtaks = +this.vtodo.getFirstPropertyValue('x-oc-hidesubtasks') || 0
102103
this._hideCompletedSubtaks = +this.vtodo.getFirstPropertyValue('x-oc-hidecompletedsubtasks') || 0
103104
this._start = this.vtodo.getFirstPropertyValue('dtstart')
104-
this._startMoment = moment(this._start, 'YYYYMMDDTHHmmssZ')
105+
this._startMoment = dayjs(this._start, 'YYYYMMDDTHHmmssZ')
105106
this._due = this.vtodo.getFirstPropertyValue('due')
106-
this._dueMoment = moment(this._due, 'YYYYMMDDTHHmmssZ')
107+
this._dueMoment = dayjs(this._due, 'YYYYMMDDTHHmmssZ')
107108
const start = this.vtodo.getFirstPropertyValue('dtstart')
108109
const due = this.vtodo.getFirstPropertyValue('due')
109110
const d = due || start
110111
this._allDay = d !== null && d.isDate
111112
this._loaded = false
112113
this._tags = this.getTags()
113114
this._modified = this.vtodo.getFirstPropertyValue('last-modified')
114-
this._modifiedMoment = moment(this._modified, 'YYYYMMDDTHHmmssZ')
115+
this._modifiedMoment = dayjs(this._modified, 'YYYYMMDDTHHmmssZ')
115116
this._created = this.vtodo.getFirstPropertyValue('created')
116-
this._createdMoment = moment(this._created, 'YYYYMMDDTHHmmssZ')
117+
this._createdMoment = dayjs(this._created, 'YYYYMMDDTHHmmssZ')
117118
this._class = this.vtodo.getFirstPropertyValue('class') || 'PUBLIC'
118119
this._pinned = this.vtodo.getFirstPropertyValue('x-pinned') === 'true'
119120
this._location = this.vtodo.getFirstPropertyValue('location') || ''
@@ -314,11 +315,11 @@ export default class Task {
314315
}
315316
this.vtodo.updatePropertyWithValue('completed', completedDate)
316317
this._completedDate = completedDate
317-
this._completedDateMoment = moment(completedDate, 'YYYYMMDDTHHmmssZ')
318+
this._completedDateMoment = dayjs(completedDate, 'YYYYMMDDTHHmmssZ')
318319
} else {
319320
this.vtodo.removeProperty('completed')
320321
this._completedDate = null
321-
this._completedDateMoment = moment(null)
322+
this._completedDateMoment = dayjs(null)
322323
}
323324
this._completed = completed
324325
this.updateLastModified()
@@ -502,7 +503,7 @@ export default class Task {
502503
this.vtodo.removeProperty('dtstart')
503504
}
504505
this._start = start
505-
this._startMoment = moment(start, 'YYYYMMDDTHHmmssZ')
506+
this._startMoment = dayjs(start, 'YYYYMMDDTHHmmssZ')
506507
this.updateLastModified()
507508
// Check all day setting
508509
const d = this._due || this._start
@@ -528,7 +529,7 @@ export default class Task {
528529
this.vtodo.removeProperty('due')
529530
}
530531
this._due = due
531-
this._dueMoment = moment(due, 'YYYYMMDDTHHmmssZ')
532+
this._dueMoment = dayjs(due, 'YYYYMMDDTHHmmssZ')
532533
this.updateLastModified()
533534
// Check all day setting
534535
const d = this._due || this._start
@@ -549,7 +550,7 @@ export default class Task {
549550
start.isDate = allDay
550551
if (!allDay) {
551552
// If we converted to datetime, we set the hour to zero in the current timezone.
552-
this.setStart(ICAL.Time.fromJSDate(moment(start, 'YYYYMMDDTHHmmssZ').toDate(), true))
553+
this.setStart(ICAL.Time.fromJSDate(dayjs(start, 'YYYYMMDDTHHmmssZ').toDate(), true))
553554
} else {
554555
this.setStart(ICAL.Time.fromDateString(this._startMoment.format('YYYY-MM-DD')))
555556
}
@@ -559,7 +560,7 @@ export default class Task {
559560
due.isDate = allDay
560561
if (!allDay) {
561562
// If we converted to datetime, we set the hour to zero in the current timezone.
562-
this.setDue(ICAL.Time.fromJSDate(moment(due, 'YYYYMMDDTHHmmssZ').toDate(), true))
563+
this.setDue(ICAL.Time.fromJSDate(dayjs(due, 'YYYYMMDDTHHmmssZ').toDate(), true))
563564
} else {
564565
this.setDue(ICAL.Time.fromDateString(this._dueMoment.format('YYYY-MM-DD')))
565566
}
@@ -707,7 +708,7 @@ export default class Task {
707708
this.vtodo.updatePropertyWithValue('last-modified', now)
708709
this.vtodo.updatePropertyWithValue('dtstamp', now)
709710
this._modified = now
710-
this._modifiedMoment = moment(now, 'YYYYMMDDTHHmmssZ')
711+
this._modifiedMoment = dayjs(now, 'YYYYMMDDTHHmmssZ')
711712
}
712713

713714
get modified() {
@@ -729,7 +730,7 @@ export default class Task {
729730
set created(createdDate) {
730731
this.vtodo.updatePropertyWithValue('created', createdDate)
731732
this._created = createdDate
732-
this._createdMoment = moment(createdDate, 'YYYYMMDDTHHmmssZ')
733+
this._createdMoment = dayjs(createdDate, 'YYYYMMDDTHHmmssZ')
733734
// Update the sortorder if necessary
734735
if (this.vtodo.getFirstPropertyValue('x-apple-sort-order') === null) {
735736
this._sortOrder = this.getSortOrder()

src/store/tasks.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -653,7 +653,7 @@ const mutations = {
653653
setCompletedDate(state, { task, completedDate }) {
654654
if (completedDate !== null) {
655655
// Check that the completed date is in the past.
656-
const now = moment(ICAL.Time.fromJSDate(new Date(), true), 'YYYYMMDDTHHmmssZ')
656+
const now = dayjs(ICAL.Time.fromJSDate(new Date(), true), 'YYYYMMDDTHHmmssZ')
657657
if (completedDate.isAfter(now)) {
658658
showError(t('tasks', 'Completion date must be in the past.'))
659659
return

src/utils/dateStrings.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ export function formatAlarm(alarm, isAllDay, currentUserTimezone, locale) {
168168
date.setMinutes(alarm.relativeMinutesAllDay)
169169
date.setSeconds(0)
170170
date.setMilliseconds(0)
171-
const formattedHourMinute = moment(date).locale(locale).format('LT')
171+
const formattedHourMinute = dayjs(date).locale(locale).format('LT')
172172

173173
if (alarm.relativeTrigger < 0) {
174174
if (alarm.relativeUnitAllDay === 'days') {
@@ -220,7 +220,7 @@ export function formatAlarm(alarm, isAllDay, currentUserTimezone, locale) {
220220
// Absolute trigger
221221
// There are no timezones in the VALARM component, since dates can only be relative or saved as UTC.
222222
const currentUserTimezoneDate = convertTimeZone(alarm.absoluteDate, currentUserTimezone)
223-
return moment(currentUserTimezoneDate).locale(locale).calendar(null, {
223+
return dayjs(currentUserTimezoneDate).locale(locale).calendar(null, {
224224
sameElse: 'LLL', // Overwrites the default `DD/MM/YYYY` (which misses the time)
225225
})
226226
}

src/views/AppSidebar.vue

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -290,6 +290,7 @@ import { startDateString, dueDateString } from '../utils/dateStrings.js'
290290
import { subscribe, unsubscribe } from '@nextcloud/event-bus'
291291
import { translate as t, translatePlural as n } from '@nextcloud/l10n'
292292
import dayjs from 'dayjs'
293+
import calendar from 'dayjs/plugin/calendar'
293294
import NcActionButton from '@nextcloud/vue/components/NcActionButton'
294295
import NcActionLink from '@nextcloud/vue/components/NcActionLink'
295296
import NcEmptyContent from '@nextcloud/vue/components/NcEmptyContent'
@@ -319,6 +320,8 @@ import Web from 'vue-material-design-icons/Web.vue'
319320
320321
import { mapGetters, mapActions } from 'vuex'
321322
323+
dayjs.extend(calendar)
324+
322325
export default {
323326
components: {
324327
NcAppSidebar,
@@ -543,7 +546,7 @@ export default {
543546
if (due.isBefore(reference)) {
544547
reference = due.subtract(1, 'm')
545548
}
546-
reference.startOf(this.allDay ? 'day' : 'hour')
549+
reference = reference.startOf(this.allDay ? 'day' : 'hour')
547550
return reference.toDate()
548551
},
549552
@@ -824,7 +827,7 @@ export default {
824827
*/
825828
setStartDate({ task, value: start }) {
826829
if (start) {
827-
start = moment(start)
830+
start = dayjs(start)
828831
}
829832
if (this.task.startMoment.isSame(start)) {
830833
return
@@ -842,7 +845,7 @@ export default {
842845
*/
843846
setDueDate({ task, value: due }) {
844847
if (due) {
845-
due = moment(due)
848+
due = dayjs(due)
846849
}
847850
if (this.task.dueMoment.isSame(due)) {
848851
return
@@ -859,7 +862,7 @@ export default {
859862
*/
860863
changeCompletedDate({ task, value: completedDate }) {
861864
if (completedDate) {
862-
completedDate = moment(completedDate)
865+
completedDate = dayjs(completedDate)
863866
}
864867
if (this.task.completedDateMoment.isSame(completedDate)) {
865868
return

0 commit comments

Comments
 (0)