Skip to content

Commit 0ce572b

Browse files
committed
Replace dependency on moment with dayjs
Following nextcloud/server#57503, this saves about 15% of the zipped bundle size for Tasks. Signed-off-by: Alan Savage <3028205+asavageiv@users.noreply.github.com>
1 parent bac289c commit 0ce572b

File tree

13 files changed

+118
-556
lines changed

13 files changed

+118
-556
lines changed

package-lock.json

Lines changed: 88 additions & 523 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.3.1",
4140
"@vueuse/components": "^14.0.0",
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.0",

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: 0 additions & 1 deletion
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'

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: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,6 @@
2424
*
2525
*/
2626

27-
import moment from '@nextcloud/moment'
28-
2927
import ICAL from 'ical.js'
3028
import { randomUUID } from '../utils/crypto.js'
3129

src/store/storeHelper.js

Lines changed: 9 additions & 9 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
/**
@@ -125,7 +125,7 @@ function isTaskToday(task) {
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
/**
@@ -145,7 +145,7 @@ function isTaskWeek(task) {
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
}
@@ -201,7 +201,7 @@ function dayOfTask(task) {
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
/**

src/store/tasks.js

Lines changed: 4 additions & 4 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

@@ -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)