Skip to content

Commit aa53ba0

Browse files
authored
Merge pull request #8096 from nextcloud/fix/remove-moment-usage-from-DueDate-badge
fix(ui): remove moment usage from due date badge
2 parents e6ebefe + 353bbca commit aa53ba0

3 files changed

Lines changed: 9 additions & 20 deletions

File tree

cypress/e2e/cardFeatures.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -272,16 +272,14 @@ describe('Card', function () {
272272

273273
cy.get('#app-sidebar-vue [data-cy-due-date-actions]').should('be.visible').click()
274274

275+
const now = new Date().setHours(11, 0, 0, 0)
276+
cy.clock(now)
275277
// Set a due date through shortcut
276278
cy.get('[data-cy-due-date-shortcut="tomorrow"] button').should('be.visible').click()
277279

278280
const tomorrow = moment().add(1, 'days').hour(8).minutes(0).seconds(0)
279281
cy.get('#card-duedate-picker').should('have.value', tomorrow.format('YYYY-MM-DDTHH:mm'))
280282

281-
const now = moment().hour(11).minutes(0).seconds(0).toDate()
282-
cy.clock(now)
283-
cy.log(now)
284-
cy.tick(60_000)
285283

286284
cy.get(`.card:contains("${newCardTitle}")`).find('[data-due-state="Now"]').should('be.visible').should('contain', '21 hours')
287285

src/components/cards/badges/DueDate.vue

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,10 @@
1818

1919
<script>
2020
import { mapState } from 'vuex'
21-
import moment from '@nextcloud/moment'
2221
import Clock from 'vue-material-design-icons/Clock.vue'
2322
import ClockOutline from 'vue-material-design-icons/ClockOutline.vue'
2423
import CheckCircle from 'vue-material-design-icons/CheckCircle.vue'
24+
import { useFormatTime, useFormatRelativeTime } from '@nextcloud/vue'
2525
2626
const DueState = {
2727
Done: 'Done',
@@ -51,7 +51,7 @@ export default {
5151
if (this.card.done) {
5252
return DueState.Done
5353
}
54-
const days = Math.floor(moment(this.card.duedate).diff(this.$root.time, 'seconds') / 60 / 60 / 24)
54+
const days = Math.floor((new Date(this.card.duedate).getTime() - new Date(this.$root.time).getTime()) / 60 / 60 / 24 / 1000)
5555
if (days < 0) {
5656
return DueState.Overdue
5757
}
@@ -68,16 +68,11 @@ export default {
6868
return this.dueState === DueState.Overdue
6969
},
7070
relativeDate() {
71-
const date = this.card.done ? this.card.done : this.card.duedate
72-
const diff = moment(this.$root.time).diff(date, 'seconds')
73-
if (diff >= 0 && diff < 45) {
74-
return t('core', 'seconds ago')
75-
}
76-
return moment(date).fromNow()
71+
return useFormatRelativeTime(this.card.done ? this.card.done : this.card.duedate).value
7772
},
7873
absoluteDate() {
79-
const date = this.card.done ? this.card.done : this.card.duedate
80-
return moment(date).format('LLLL')
74+
const date = new Date(this.card.done ? this.card.done : this.card.duedate)
75+
return useFormatTime(date, { format: { dateStyle: 'full', timeStyle: 'short' } }).value
8176
},
8277
},
8378
}

src/mixins/relativeDate.js

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

6-
import moment from '@nextcloud/moment'
6+
import { useFormatRelativeTime } from '@nextcloud/vue'
77

88
export default {
99
computed: {
1010
relativeDate() {
1111
return (timestamp) => {
12-
const diff = moment(this.$root.time).diff(moment(timestamp))
13-
if (diff >= 0 && diff < 45000) {
14-
return t('core', 'seconds ago')
15-
}
16-
return moment(timestamp).fromNow()
12+
return useFormatRelativeTime(timestamp)
1713
}
1814
},
1915
},

0 commit comments

Comments
 (0)