Skip to content

Commit 4980372

Browse files
Merge pull request #3061 from nextcloud/revert-3027-tasks-nomoment
Revert "Replace dependency on moment with dayjs"
2 parents 92c2d01 + c961c5e commit 4980372

File tree

15 files changed

+1453
-2023
lines changed

15 files changed

+1453
-2023
lines changed

package-lock.json

Lines changed: 1388 additions & 1759 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",
3839
"@nextcloud/router": "^3.1.0",
3940
"@nextcloud/vue": "9.5.0",
4041
"@vueuse/components": "^14.2.1",
4142
"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 dayjs from 'dayjs'
67+
import moment from '@nextcloud/moment'
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: dayjs().date(),
105+
dayOfMonth: moment().date(),
106106
}
107107
},
108108
computed: {

src/components/AppNavigation/Trashbin.vue

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,7 @@ 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'
132133
import NcAppNavigationItem from '@nextcloud/vue/components/NcAppNavigationItem'
133134
import NcActions from '@nextcloud/vue/components/NcActions'
134135
import NcActionButton from '@nextcloud/vue/components/NcActionButton'
@@ -209,9 +210,9 @@ export default {
209210
if (vobject.isEvent) {
210211
const event = toRaw(vobject?.calendarComponent.getFirstComponent('VEVENT'))
211212
if (event?.startDate.jsDate && event?.isAllDay()) {
212-
subline += ' · ' + dayjs(event.startDate.jsDate).format('LL')
213+
subline += ' · ' + moment(event.startDate.jsDate).format('LL')
213214
} else if (event?.startDate.jsDate) {
214-
subline += ' · ' + dayjs(event?.startDate.jsDate).format('LLL')
215+
subline += ' · ' + moment(event?.startDate.jsDate).format('LLL')
215216
}
216217
}
217218
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 dayjs from 'dayjs'
61+
import moment from '@nextcloud/moment'
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 = dayjs().startOf('day').format('YYYY-MM-DDTHH:mm:ss')
143+
taskProperties.due = moment().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 = dayjs().format('YYYY-MM-DDTHH:mm:ss')
147+
taskProperties.start = moment().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 dayjs from 'dayjs'
200+
import moment from '@nextcloud/moment'
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 = dayjs().startOf('day').format('YYYY-MM-DDTHH:mm:ss')
697+
taskProperties.due = moment().startOf('day').format('YYYY-MM-DDTHH:mm:ss')
698698
}
699699
if (this.collectionId === 'current') {
700-
taskProperties.start = dayjs().format('YYYY-MM-DDTHH:mm:ss')
700+
taskProperties.start = moment().format('YYYY-MM-DDTHH:mm:ss')
701701
}
702702
return taskProperties
703703
},

src/models/task.js

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

2829
import ICAL from 'ical.js'
2930
import { randomUUID } from '../utils/crypto.js'
@@ -94,27 +95,27 @@ export default class Task {
9495
this._priority = this.vtodo.getFirstPropertyValue('priority') || 0
9596
this._complete = this.vtodo.getFirstPropertyValue('percent-complete') || 0
9697
this._completedDate = this.vtodo.getFirstPropertyValue('completed')
97-
this._completedDateMoment = dayjs(this._completedDate, 'YYYYMMDDTHHmmssZ')
98+
this._completedDateMoment = moment(this._completedDate, 'YYYYMMDDTHHmmssZ')
9899
this._completed = !!this._completedDate
99100
this._status = this.vtodo.getFirstPropertyValue('status')
100101
this._note = this.vtodo.getFirstPropertyValue('description') || ''
101102
this._related = this.getParent()?.getFirstValue() || null
102103
this._hideSubtaks = +this.vtodo.getFirstPropertyValue('x-oc-hidesubtasks') || 0
103104
this._hideCompletedSubtaks = +this.vtodo.getFirstPropertyValue('x-oc-hidecompletedsubtasks') || 0
104105
this._start = this.vtodo.getFirstPropertyValue('dtstart')
105-
this._startMoment = dayjs(this._start, 'YYYYMMDDTHHmmssZ')
106+
this._startMoment = moment(this._start, 'YYYYMMDDTHHmmssZ')
106107
this._due = this.vtodo.getFirstPropertyValue('due')
107-
this._dueMoment = dayjs(this._due, 'YYYYMMDDTHHmmssZ')
108+
this._dueMoment = moment(this._due, 'YYYYMMDDTHHmmssZ')
108109
const start = this.vtodo.getFirstPropertyValue('dtstart')
109110
const due = this.vtodo.getFirstPropertyValue('due')
110111
const d = due || start
111112
this._allDay = d !== null && d.isDate
112113
this._loaded = false
113114
this._tags = this.getTags()
114115
this._modified = this.vtodo.getFirstPropertyValue('last-modified')
115-
this._modifiedMoment = dayjs(this._modified, 'YYYYMMDDTHHmmssZ')
116+
this._modifiedMoment = moment(this._modified, 'YYYYMMDDTHHmmssZ')
116117
this._created = this.vtodo.getFirstPropertyValue('created')
117-
this._createdMoment = dayjs(this._created, 'YYYYMMDDTHHmmssZ')
118+
this._createdMoment = moment(this._created, 'YYYYMMDDTHHmmssZ')
118119
this._class = this.vtodo.getFirstPropertyValue('class') || 'PUBLIC'
119120
this._pinned = this.vtodo.getFirstPropertyValue('x-pinned') === 'true'
120121
this._location = this.vtodo.getFirstPropertyValue('location') || ''
@@ -315,11 +316,11 @@ export default class Task {
315316
}
316317
this.vtodo.updatePropertyWithValue('completed', completedDate)
317318
this._completedDate = completedDate
318-
this._completedDateMoment = dayjs(completedDate, 'YYYYMMDDTHHmmssZ')
319+
this._completedDateMoment = moment(completedDate, 'YYYYMMDDTHHmmssZ')
319320
} else {
320321
this.vtodo.removeProperty('completed')
321322
this._completedDate = null
322-
this._completedDateMoment = dayjs(null)
323+
this._completedDateMoment = moment(null)
323324
}
324325
this._completed = completed
325326
this.updateLastModified()
@@ -503,7 +504,7 @@ export default class Task {
503504
this.vtodo.removeProperty('dtstart')
504505
}
505506
this._start = start
506-
this._startMoment = dayjs(start, 'YYYYMMDDTHHmmssZ')
507+
this._startMoment = moment(start, 'YYYYMMDDTHHmmssZ')
507508
this.updateLastModified()
508509
// Check all day setting
509510
const d = this._due || this._start
@@ -529,7 +530,7 @@ export default class Task {
529530
this.vtodo.removeProperty('due')
530531
}
531532
this._due = due
532-
this._dueMoment = dayjs(due, 'YYYYMMDDTHHmmssZ')
533+
this._dueMoment = moment(due, 'YYYYMMDDTHHmmssZ')
533534
this.updateLastModified()
534535
// Check all day setting
535536
const d = this._due || this._start
@@ -550,7 +551,7 @@ export default class Task {
550551
start.isDate = allDay
551552
if (!allDay) {
552553
// If we converted to datetime, we set the hour to zero in the current timezone.
553-
this.setStart(ICAL.Time.fromJSDate(dayjs(start, 'YYYYMMDDTHHmmssZ').toDate(), true))
554+
this.setStart(ICAL.Time.fromJSDate(moment(start, 'YYYYMMDDTHHmmssZ').toDate(), true))
554555
} else {
555556
this.setStart(ICAL.Time.fromDateString(this._startMoment.format('YYYY-MM-DD')))
556557
}
@@ -560,7 +561,7 @@ export default class Task {
560561
due.isDate = allDay
561562
if (!allDay) {
562563
// If we converted to datetime, we set the hour to zero in the current timezone.
563-
this.setDue(ICAL.Time.fromJSDate(dayjs(due, 'YYYYMMDDTHHmmssZ').toDate(), true))
564+
this.setDue(ICAL.Time.fromJSDate(moment(due, 'YYYYMMDDTHHmmssZ').toDate(), true))
564565
} else {
565566
this.setDue(ICAL.Time.fromDateString(this._dueMoment.format('YYYY-MM-DD')))
566567
}
@@ -708,7 +709,7 @@ export default class Task {
708709
this.vtodo.updatePropertyWithValue('last-modified', now)
709710
this.vtodo.updatePropertyWithValue('dtstamp', now)
710711
this._modified = now
711-
this._modifiedMoment = dayjs(now, 'YYYYMMDDTHHmmssZ')
712+
this._modifiedMoment = moment(now, 'YYYYMMDDTHHmmssZ')
712713
}
713714

714715
get modified() {
@@ -730,7 +731,7 @@ export default class Task {
730731
set created(createdDate) {
731732
this.vtodo.updatePropertyWithValue('created', createdDate)
732733
this._created = createdDate
733-
this._createdMoment = dayjs(createdDate, 'YYYYMMDDTHHmmssZ')
734+
this._createdMoment = moment(createdDate, 'YYYYMMDDTHHmmssZ')
734735
// Update the sortorder if necessary
735736
if (this.vtodo.getFirstPropertyValue('x-apple-sort-order') === null) {
736737
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 dayjs from 'dayjs'
30+
import moment from '@nextcloud/moment'
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(dayjs(), 'days', true) < 0 || task.dueMoment.diff(dayjs(), 'days', true) < 0
108+
return !task.startMoment.isValid() || task.startMoment.diff(moment(), 'days', true) < 0 || task.dueMoment.diff(moment(), 'days', true) < 0
109109
}
110110

111111
/**
@@ -121,11 +121,11 @@ function isTaskToday(task) {
121121
/**
122122
* Checks if a date is today
123123
*
124-
* @param {dayjs} date The date as moment
124+
* @param {moment} date The date as moment
125125
* @return {boolean}
126126
*/
127127
function today(date) {
128-
return date.isValid() && date.diff(dayjs().startOf('day'), 'days', true) < 1
128+
return date.isValid() && date.diff(moment().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 {dayjs} date The date as moment
144+
* @param {moment} date The date as moment
145145
* @return {boolean}
146146
*/
147147
function week(date) {
148-
return date.isValid() && date.diff(dayjs().startOf('day'), 'days', true) < 7
148+
return date.isValid() && date.diff(moment().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(dayjs().startOf('day'), 'days')
177+
diff = start.diff(moment().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(dayjs().startOf('day'), 'days')
182+
diff = due.diff(moment().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(dayjs().startOf('day'), 'days')
189-
duediff = due.diff(dayjs().startOf('day'), 'days')
188+
startdiff = start.diff(moment().startOf('day'), 'days')
189+
duediff = due.diff(moment().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 {dayjs} date The date
200+
* @param {moment} date The date
201201
* @return {boolean}
202202
*/
203203
function overdue(date) {
204-
return date.isValid() && date.diff(dayjs()) < 0
204+
return date.isValid() && date.diff(moment()) < 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 {dayjs} moment The moment to convert
470+
* @param {moment} 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 dayjs from 'dayjs'
33+
import moment from '@nextcloud/moment'
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 {dayjs} data.due The due date moment
589+
* @param {moment} 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 = start.subtract(currentdue.diff(due), 'ms')
603+
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 {dayjs} data.start The start date moment
620+
* @param {moment} 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 = due.add(start.diff(currentstart), 'ms')
634+
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 = dayjs(ICAL.Time.fromJSDate(new Date(), true), 'YYYYMMDDTHHmmssZ')
656+
const now = moment(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 = dayjs().startOf('day').add(day, 'days')
1436+
day = moment().startOf('day').add(day, 'days')
14371437

14381438
let diff
14391439
// Adjust start date
14401440
if (start.isValid()) {
1441-
diff = start.diff(dayjs().startOf('day'), 'days')
1441+
diff = start.diff(moment().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(dayjs().startOf('day'), 'days')
1450+
diff = due.diff(moment().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 dayjs from 'dayjs'
6+
import moment from '@nextcloud/moment'
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-
dayjs().add(1, 'day').startOf('day').add(9, 'hours').toDate(),
218+
moment().add(1, 'day').startOf('day').add(9, 'hours').toDate(),
219219
]
220220
}
221221

0 commit comments

Comments
 (0)