Skip to content

Commit 92c2d01

Browse files
Merge pull request #3027 from asavageiv/tasks-nomoment
Replace dependency on moment with dayjs
2 parents 83441d6 + 38789ab commit 92c2d01

File tree

15 files changed

+2038
-1468
lines changed

15 files changed

+2038
-1468
lines changed

package-lock.json

Lines changed: 1774 additions & 1403 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,11 @@
3535
"@nextcloud/initial-state": "3.0.0",
3636
"@nextcloud/l10n": "^3.4.1",
3737
"@nextcloud/logger": "^3.0.3",
38-
"@nextcloud/moment": "^1.3.5",
3938
"@nextcloud/router": "^3.1.0",
4039
"@nextcloud/vue": "9.5.0",
4140
"@vueuse/components": "^14.2.1",
4241
"color-convert": "^3.1.3",
42+
"dayjs": "^1.11.19",
4343
"debounce": "^3.0.0",
4444
"ical.js": "^2.2.0",
4545
"markdown-it": "^14.1.1",

src/components/AppNavigation/AppNavigationSettings.vue

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ License along with this library. If not, see <http://www.gnu.org/licenses/>.
6464

6565
<script>
6666
import { translate as t } from '@nextcloud/l10n'
67-
import moment from '@nextcloud/moment'
67+
import dayjs from 'dayjs'
6868
import NcAppNavigationSettings from '@nextcloud/vue/components/NcAppNavigationSettings'
6969
7070
import CalendarToday from 'vue-material-design-icons/CalendarToday.vue'
@@ -102,7 +102,7 @@ export default {
102102
name: t('tasks', 'Automatic'),
103103
},
104104
],
105-
dayOfMonth: moment().date(),
105+
dayOfMonth: dayjs().date(),
106106
}
107107
},
108108
computed: {

src/components/AppNavigation/Trashbin.vue

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,6 @@ import { sort } from '../../store/storeHelper.js'
129129
130130
import { showError } from '@nextcloud/dialogs'
131131
import { translate as t, translatePlural as n } from '@nextcloud/l10n'
132-
import moment from '@nextcloud/moment'
133132
import NcAppNavigationItem from '@nextcloud/vue/components/NcAppNavigationItem'
134133
import NcActions from '@nextcloud/vue/components/NcActions'
135134
import NcActionButton from '@nextcloud/vue/components/NcActionButton'
@@ -210,9 +209,9 @@ export default {
210209
if (vobject.isEvent) {
211210
const event = toRaw(vobject?.calendarComponent.getFirstComponent('VEVENT'))
212211
if (event?.startDate.jsDate && event?.isAllDay()) {
213-
subline += ' · ' + moment(event.startDate.jsDate).format('LL')
212+
subline += ' · ' + dayjs(event.startDate.jsDate).format('LL')
214213
} else if (event?.startDate.jsDate) {
215-
subline += ' · ' + moment(event?.startDate.jsDate).format('LLL')
214+
subline += ' · ' + dayjs(event?.startDate.jsDate).format('LLL')
216215
}
217216
}
218217
const color = vobject.calendarComponent.getComponentIterator().next().value?.color

src/components/HeaderBar.vue

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ import SortorderDropdown from './SortorderDropdown.vue'
5858
import openNewTask from '../mixins/openNewTask.js'
5959
6060
import { translate as t } from '@nextcloud/l10n'
61-
import moment from '@nextcloud/moment'
61+
import dayjs from 'dayjs'
6262
import NcTextField from '@nextcloud/vue/components/NcTextField'
6363
6464
import Plus from 'vue-material-design-icons/Plus.vue'
@@ -140,11 +140,11 @@ export default {
140140
}
141141
if (this.$route.params.collectionId === 'today'
142142
|| this.$route.params.collectionId === 'week') {
143-
taskProperties.due = moment().startOf('day').format('YYYY-MM-DDTHH:mm:ss')
143+
taskProperties.due = dayjs().startOf('day').format('YYYY-MM-DDTHH:mm:ss')
144144
taskProperties.allDay = this.$store.state.settings.settings.allDay
145145
}
146146
if (this.$route.params.collectionId === 'current') {
147-
taskProperties.start = moment().format('YYYY-MM-DDTHH:mm:ss')
147+
taskProperties.start = dayjs().format('YYYY-MM-DDTHH:mm:ss')
148148
}
149149
return taskProperties
150150
},

src/components/TaskBody.vue

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ import { startDateString } from '../utils/dateStrings.js'
197197
198198
import { emit } from '@nextcloud/event-bus'
199199
import { translate as t, translatePlural as n } from '@nextcloud/l10n'
200-
import moment from '@nextcloud/moment'
200+
import dayjs from 'dayjs'
201201
import NcActions from '@nextcloud/vue/components/NcActions'
202202
import NcActionButton from '@nextcloud/vue/components/NcActionButton'
203203
import NcProgressBar from '@nextcloud/vue/components/NcProgressBar'
@@ -694,10 +694,10 @@ export default {
694694
taskProperties.priority = '1'
695695
}
696696
if (this.collectionId === 'today') {
697-
taskProperties.due = moment().startOf('day').format('YYYY-MM-DDTHH:mm:ss')
697+
taskProperties.due = dayjs().startOf('day').format('YYYY-MM-DDTHH:mm:ss')
698698
}
699699
if (this.collectionId === 'current') {
700-
taskProperties.start = moment().format('YYYY-MM-DDTHH:mm:ss')
700+
taskProperties.start = dayjs().format('YYYY-MM-DDTHH:mm:ss')
701701
}
702702
return taskProperties
703703
},

src/models/task.js

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

2928
import ICAL from 'ical.js'
3029
import { randomUUID } from '../utils/crypto.js'
@@ -95,27 +94,27 @@ export default class Task {
9594
this._priority = this.vtodo.getFirstPropertyValue('priority') || 0
9695
this._complete = this.vtodo.getFirstPropertyValue('percent-complete') || 0
9796
this._completedDate = this.vtodo.getFirstPropertyValue('completed')
98-
this._completedDateMoment = moment(this._completedDate, 'YYYYMMDDTHHmmssZ')
97+
this._completedDateMoment = dayjs(this._completedDate, 'YYYYMMDDTHHmmssZ')
9998
this._completed = !!this._completedDate
10099
this._status = this.vtodo.getFirstPropertyValue('status')
101100
this._note = this.vtodo.getFirstPropertyValue('description') || ''
102101
this._related = this.getParent()?.getFirstValue() || null
103102
this._hideSubtaks = +this.vtodo.getFirstPropertyValue('x-oc-hidesubtasks') || 0
104103
this._hideCompletedSubtaks = +this.vtodo.getFirstPropertyValue('x-oc-hidecompletedsubtasks') || 0
105104
this._start = this.vtodo.getFirstPropertyValue('dtstart')
106-
this._startMoment = moment(this._start, 'YYYYMMDDTHHmmssZ')
105+
this._startMoment = dayjs(this._start, 'YYYYMMDDTHHmmssZ')
107106
this._due = this.vtodo.getFirstPropertyValue('due')
108-
this._dueMoment = moment(this._due, 'YYYYMMDDTHHmmssZ')
107+
this._dueMoment = dayjs(this._due, 'YYYYMMDDTHHmmssZ')
109108
const start = this.vtodo.getFirstPropertyValue('dtstart')
110109
const due = this.vtodo.getFirstPropertyValue('due')
111110
const d = due || start
112111
this._allDay = d !== null && d.isDate
113112
this._loaded = false
114113
this._tags = this.getTags()
115114
this._modified = this.vtodo.getFirstPropertyValue('last-modified')
116-
this._modifiedMoment = moment(this._modified, 'YYYYMMDDTHHmmssZ')
115+
this._modifiedMoment = dayjs(this._modified, 'YYYYMMDDTHHmmssZ')
117116
this._created = this.vtodo.getFirstPropertyValue('created')
118-
this._createdMoment = moment(this._created, 'YYYYMMDDTHHmmssZ')
117+
this._createdMoment = dayjs(this._created, 'YYYYMMDDTHHmmssZ')
119118
this._class = this.vtodo.getFirstPropertyValue('class') || 'PUBLIC'
120119
this._pinned = this.vtodo.getFirstPropertyValue('x-pinned') === 'true'
121120
this._location = this.vtodo.getFirstPropertyValue('location') || ''
@@ -316,11 +315,11 @@ export default class Task {
316315
}
317316
this.vtodo.updatePropertyWithValue('completed', completedDate)
318317
this._completedDate = completedDate
319-
this._completedDateMoment = moment(completedDate, 'YYYYMMDDTHHmmssZ')
318+
this._completedDateMoment = dayjs(completedDate, 'YYYYMMDDTHHmmssZ')
320319
} else {
321320
this.vtodo.removeProperty('completed')
322321
this._completedDate = null
323-
this._completedDateMoment = moment(null)
322+
this._completedDateMoment = dayjs(null)
324323
}
325324
this._completed = completed
326325
this.updateLastModified()
@@ -504,7 +503,7 @@ export default class Task {
504503
this.vtodo.removeProperty('dtstart')
505504
}
506505
this._start = start
507-
this._startMoment = moment(start, 'YYYYMMDDTHHmmssZ')
506+
this._startMoment = dayjs(start, 'YYYYMMDDTHHmmssZ')
508507
this.updateLastModified()
509508
// Check all day setting
510509
const d = this._due || this._start
@@ -530,7 +529,7 @@ export default class Task {
530529
this.vtodo.removeProperty('due')
531530
}
532531
this._due = due
533-
this._dueMoment = moment(due, 'YYYYMMDDTHHmmssZ')
532+
this._dueMoment = dayjs(due, 'YYYYMMDDTHHmmssZ')
534533
this.updateLastModified()
535534
// Check all day setting
536535
const d = this._due || this._start
@@ -551,7 +550,7 @@ export default class Task {
551550
start.isDate = allDay
552551
if (!allDay) {
553552
// If we converted to datetime, we set the hour to zero in the current timezone.
554-
this.setStart(ICAL.Time.fromJSDate(moment(start, 'YYYYMMDDTHHmmssZ').toDate(), true))
553+
this.setStart(ICAL.Time.fromJSDate(dayjs(start, 'YYYYMMDDTHHmmssZ').toDate(), true))
555554
} else {
556555
this.setStart(ICAL.Time.fromDateString(this._startMoment.format('YYYY-MM-DD')))
557556
}
@@ -561,7 +560,7 @@ export default class Task {
561560
due.isDate = allDay
562561
if (!allDay) {
563562
// If we converted to datetime, we set the hour to zero in the current timezone.
564-
this.setDue(ICAL.Time.fromJSDate(moment(due, 'YYYYMMDDTHHmmssZ').toDate(), true))
563+
this.setDue(ICAL.Time.fromJSDate(dayjs(due, 'YYYYMMDDTHHmmssZ').toDate(), true))
565564
} else {
566565
this.setDue(ICAL.Time.fromDateString(this._dueMoment.format('YYYY-MM-DD')))
567566
}
@@ -709,7 +708,7 @@ export default class Task {
709708
this.vtodo.updatePropertyWithValue('last-modified', now)
710709
this.vtodo.updatePropertyWithValue('dtstamp', now)
711710
this._modified = now
712-
this._modifiedMoment = moment(now, 'YYYYMMDDTHHmmssZ')
711+
this._modifiedMoment = dayjs(now, 'YYYYMMDDTHHmmssZ')
713712
}
714713

715714
get modified() {
@@ -731,7 +730,7 @@ export default class Task {
731730
set created(createdDate) {
732731
this.vtodo.updatePropertyWithValue('created', createdDate)
733732
this._created = createdDate
734-
this._createdMoment = moment(createdDate, 'YYYYMMDDTHHmmssZ')
733+
this._createdMoment = dayjs(createdDate, 'YYYYMMDDTHHmmssZ')
735734
// Update the sortorder if necessary
736735
if (this.vtodo.getFirstPropertyValue('x-apple-sort-order') === null) {
737736
this._sortOrder = this.getSortOrder()

src/store/storeHelper.js

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727

2828
import Task from '../models/task.js'
2929

30-
import moment from '@nextcloud/moment'
30+
import dayjs from 'dayjs'
3131

3232
import ICAL from 'ical.js'
3333

@@ -105,7 +105,7 @@ function isTaskPriority(task) {
105105
* @return {boolean}
106106
*/
107107
function isTaskCurrent(task) {
108-
return !task.startMoment.isValid() || task.startMoment.diff(moment(), 'days', true) < 0 || task.dueMoment.diff(moment(), 'days', true) < 0
108+
return !task.startMoment.isValid() || task.startMoment.diff(dayjs(), 'days', true) < 0 || task.dueMoment.diff(dayjs(), 'days', true) < 0
109109
}
110110

111111
/**
@@ -121,11 +121,11 @@ function isTaskToday(task) {
121121
/**
122122
* Checks if a date is today
123123
*
124-
* @param {moment} date The date as moment
124+
* @param {dayjs} date The date as moment
125125
* @return {boolean}
126126
*/
127127
function today(date) {
128-
return date.isValid() && date.diff(moment().startOf('day'), 'days', true) < 1
128+
return date.isValid() && date.diff(dayjs().startOf('day'), 'days', true) < 1
129129
}
130130

131131
/**
@@ -141,11 +141,11 @@ function isTaskWeek(task) {
141141
/**
142142
* Checks if a date lies within the next week
143143
*
144-
* @param {moment} date The date as moment
144+
* @param {dayjs} date The date as moment
145145
* @return {boolean}
146146
*/
147147
function week(date) {
148-
return date.isValid() && date.diff(moment().startOf('day'), 'days', true) < 7
148+
return date.isValid() && date.diff(dayjs().startOf('day'), 'days', true) < 7
149149
}
150150

151151
/**
@@ -174,19 +174,19 @@ function dayOfTask(task) {
174174

175175
// Add all tasks whose start date will be reached at that day.
176176
if (start.isValid() && !due.isValid()) {
177-
diff = start.diff(moment().startOf('day'), 'days')
177+
diff = start.diff(dayjs().startOf('day'), 'days')
178178
}
179179

180180
// Add all tasks whose due date will be reached at that day.
181181
if (due.isValid() && !start.isValid()) {
182-
diff = due.diff(moment().startOf('day'), 'days')
182+
diff = due.diff(dayjs().startOf('day'), 'days')
183183
}
184184

185185
// Add all tasks whose due or start date will be reached at that day.
186186
// Add the task to the day at which either due or start date are reached first.
187187
if (start.isValid() && due.isValid()) {
188-
startdiff = start.diff(moment().startOf('day'), 'days')
189-
duediff = due.diff(moment().startOf('day'), 'days')
188+
startdiff = start.diff(dayjs().startOf('day'), 'days')
189+
duediff = due.diff(dayjs().startOf('day'), 'days')
190190
// chose the date that is reached first
191191
diff = (startdiff < duediff) ? startdiff : duediff
192192
}
@@ -197,11 +197,11 @@ function dayOfTask(task) {
197197
/**
198198
* Checks if a date is overdue
199199
*
200-
* @param {moment} date The date
200+
* @param {dayjs} date The date
201201
* @return {boolean}
202202
*/
203203
function overdue(date) {
204-
return date.isValid() && date.diff(moment()) < 0
204+
return date.isValid() && date.diff(dayjs()) < 0
205205
}
206206

207207
/**
@@ -467,7 +467,7 @@ function sortByDeletedAt(taskA, taskB) {
467467
/**
468468
* Function to convert a moment to a ICAL Time
469469
*
470-
* @param {moment} moment The moment to convert
470+
* @param {dayjs} moment The moment to convert
471471
* @param {boolean} asDate Is the moment all day
472472
* @return {ICAL.Time}
473473
*/

src/store/tasks.js

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ import Task from '../models/task.js'
3030
import { showError } from '@nextcloud/dialogs'
3131
import { emit } from '@nextcloud/event-bus'
3232
import { translate as t } from '@nextcloud/l10n'
33-
import moment from '@nextcloud/moment'
33+
import dayjs from 'dayjs'
3434

3535
import ICAL from 'ical.js'
3636

@@ -586,7 +586,7 @@ const mutations = {
586586
* @param {object} state The store data
587587
* @param {object} data Destructuring object
588588
* @param {Task} data.task The task
589-
* @param {moment} data.due The due date moment
589+
* @param {dayjs} data.due The due date moment
590590
* @param {boolean} data.allDay Whether the date is all-day
591591
*/
592592
setDue(state, { task, due, allDay }) {
@@ -600,7 +600,7 @@ const mutations = {
600600
if (start.isValid() && due.isBefore(start)) {
601601
const currentdue = task.dueMoment
602602
if (currentdue.isValid()) {
603-
start.subtract(currentdue.diff(due), 'ms')
603+
start = start.subtract(currentdue.diff(due), 'ms')
604604
} else {
605605
start = due.clone()
606606
}
@@ -617,7 +617,7 @@ const mutations = {
617617
* @param {object} state The store data
618618
* @param {object} data Destructuring object
619619
* @param {Task} data.task The task
620-
* @param {moment} data.start The start date moment
620+
* @param {dayjs} data.start The start date moment
621621
* @param {boolean} data.allDay Whether the date is all-day
622622
*/
623623
setStart(state, { task, start, allDay }) {
@@ -631,7 +631,7 @@ const mutations = {
631631
if (due.isValid() && start.isAfter(due)) {
632632
const currentstart = task.startMoment
633633
if (currentstart.isValid()) {
634-
due.add(start.diff(currentstart), 'ms')
634+
due = due.add(start.diff(currentstart), 'ms')
635635
} else {
636636
due = start.clone()
637637
}
@@ -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
@@ -1433,12 +1433,12 @@ const actions = {
14331433
async setDate(context, { task, day }) {
14341434
const start = task.startMoment.startOf('day')
14351435
const due = task.dueMoment.startOf('day')
1436-
day = moment().startOf('day').add(day, 'days')
1436+
day = dayjs().startOf('day').add(day, 'days')
14371437

14381438
let diff
14391439
// Adjust start date
14401440
if (start.isValid()) {
1441-
diff = start.diff(moment().startOf('day'), 'days')
1441+
diff = start.diff(dayjs().startOf('day'), 'days')
14421442
diff = diff < 0 ? 0 : diff
14431443
if (diff !== day) {
14441444
const newStart = task.startMoment.year(day.year()).month(day.month()).date(day.date())
@@ -1447,7 +1447,7 @@ const actions = {
14471447
}
14481448
// Adjust due date
14491449
} else if (due.isValid()) {
1450-
diff = due.diff(moment().startOf('day'), 'days')
1450+
diff = due.diff(dayjs().startOf('day'), 'days')
14511451
diff = diff < 0 ? 0 : diff
14521452
if (diff !== day) {
14531453
const newDue = task.dueMoment.year(day.year()).month(day.month()).date(day.date())

src/utils/alarms.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* SPDX-License-Identifier: AGPL-3.0-or-later
44
*/
55

6-
import moment from '@nextcloud/moment'
6+
import dayjs from 'dayjs'
77

88
/**
99
* Get the factor for a given unit
@@ -215,7 +215,7 @@ export function getDefaultAlarms(allDay = false) {
215215
*/
216216
export function getDefaultAbsoluteAlarms() {
217217
return [
218-
moment().add(1, 'day').startOf('day').add(9, 'hours').toDate(),
218+
dayjs().add(1, 'day').startOf('day').add(9, 'hours').toDate(),
219219
]
220220
}
221221

0 commit comments

Comments
 (0)