Skip to content

Commit 406e3b6

Browse files
authored
Merge pull request #4204 from nextcloud/ref/luxon-for-moment
replace moment by Luxon
2 parents 9c30063 + 38c199d commit 406e3b6

11 files changed

Lines changed: 71 additions & 83 deletions

File tree

package-lock.json

Lines changed: 1 addition & 15 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@
3838
"@nextcloud/initial-state": "^2.2.0",
3939
"@nextcloud/l10n": "^3.3.0",
4040
"@nextcloud/logger": "^3.0.2",
41-
"@nextcloud/moment": "^1.3.4",
4241
"@nextcloud/router": "^3.0.1",
4342
"@nextcloud/vue": "^9.0.0-rc.3",
4443
"@vueuse/core": "^13.4.0",

src/components/Calendar/CalendarInfo.vue

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
-->
55

66
<script setup lang="ts">
7-
import moment from '@nextcloud/moment'
87
import { computed } from 'vue'
8+
import { DateTime } from 'luxon'
99
import { CalendarEvent } from '../../components/Calendar/CalendarPeek.vue'
1010
1111
import type { Option } from '../../stores/options.types'
@@ -37,31 +37,29 @@ const fontColor = computed(() => {
3737
return l > 0.5 ? '#222' : '#ddd'
3838
})
3939
40-
const dayStart = computed(() => moment.unix(calendarEvent.start).format('ddd'))
41-
42-
const dayEnd = computed(() => moment.unix(calendarEvent.end - 1).format('ddd'))
40+
const eventStart = computed(() => DateTime.fromSeconds(calendarEvent.start))
41+
const eventEnd = computed(() => DateTime.fromSeconds(calendarEvent.end))
4342
4443
const dayDisplay = computed(() => {
45-
if (dayEnd.value === dayStart.value) {
46-
return dayStart.value
44+
if (eventEnd.value.hasSame(eventStart.value.minus({ second: 1 }), 'day')) {
45+
return eventStart.value.toLocaleString({ weekday: 'short' })
4746
}
4847
49-
return `${dayStart.value} - ${dayEnd.value}`
48+
return `${eventStart.value.toLocaleString({ weekday: 'short' })} - ${eventEnd.value.toLocaleString({ weekday: 'short' })}`
5049
})
5150
52-
const timeStart = computed(() => moment.unix(calendarEvent.start).format('LT'))
53-
54-
const timeEnd = computed(() => moment.unix(calendarEvent.end).format('LT'))
55-
5651
const timeDisplay = computed(() => {
57-
if (timeEnd.value === timeStart.value) {
58-
return timeStart.value
52+
if (eventStart.value.hasSame(eventEnd.value, 'minute')) {
53+
return eventStart.value.toLocaleString(DateTime.TIME_SIMPLE)
5954
}
60-
return `${timeStart.value} - ${timeEnd.value}`
55+
56+
return `${eventStart.value.toLocaleString(DateTime.TIME_SIMPLE)} - ${eventEnd.value.toLocaleString(DateTime.TIME_SIMPLE)}`
6157
})
6258
6359
const showJustDays = computed(
64-
() => dayStart.value !== dayEnd.value || calendarEvent.allDay,
60+
() =>
61+
!eventEnd.value.hasSame(eventStart.value.minus({ second: 1 }), 'day')
62+
|| calendarEvent.allDay,
6563
)
6664
6765
const statusClass = computed(() => calendarEvent.status.toLowerCase())

src/components/Calendar/CalendarPeek.vue

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
import { computed, onMounted, ref } from 'vue'
88
import { t } from '@nextcloud/l10n'
99
import orderBy from 'lodash/orderBy'
10-
import moment from '@nextcloud/moment'
10+
import { DateTime } from 'luxon'
1111
1212
import NcPopover from '@nextcloud/vue/components/NcPopover'
1313
import NcButton from '@nextcloud/vue/components/NcButton'
@@ -48,12 +48,13 @@ const events = ref<CalendarEvent[]>([])
4848
const pollStore = usePollStore()
4949
5050
const detectAllDay = computed(() => {
51-
const from = moment.unix(option.timestamp)
52-
const to = moment.unix(option.timestamp + Math.max(0, option.duration))
51+
const from = DateTime.fromSeconds(option.timestamp)
52+
5353
const dayLongEvent =
54-
from.unix() === moment(from).startOf('day').unix()
55-
&& to.unix() === moment(to).startOf('day').unix()
56-
&& from.unix() !== to.unix()
54+
from.startOf('day')
55+
&& from.plus({ seconds: option.duration }).startOf('day')
56+
&& option.duration > 0
57+
5758
return {
5859
allDay: dayLongEvent,
5960
type: dayLongEvent ? 'date' : 'dateTime',

src/components/Comments/CommentItem.vue

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77
import { computed } from 'vue'
88
99
import linkifyStr from 'linkify-string'
10+
import { DateTime } from 'luxon'
1011
import { t } from '@nextcloud/l10n'
11-
import moment from '@nextcloud/moment'
1212
import { showError } from '@nextcloud/dialogs'
1313
1414
import ActionDelete from '../Actions/modules/ActionDelete.vue'
@@ -30,7 +30,7 @@ const preferencesStore = usePreferencesStore()
3030
const { comment } = defineProps<{ comment: CommentsGrouped }>()
3131
3232
const dateCommentedRelative = computed(() =>
33-
moment.unix(comment.timestamp).fromNow(),
33+
DateTime.fromSeconds(comment.timestamp).toRelative(),
3434
)
3535
3636
const isCurrentUser = computed(

src/components/Configuration/ConfigClosing.vue

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
<script setup lang="ts">
77
import { computed } from 'vue'
8-
import moment from '@nextcloud/moment'
8+
import { DateTime } from 'luxon'
99
import { t } from '@nextcloud/l10n'
1010
1111
import NcButton from '@nextcloud/vue/components/NcButton'
@@ -20,9 +20,9 @@ import { usePollStore } from '../../stores/poll'
2020
const pollStore = usePollStore()
2121
2222
const expire = computed({
23-
get: () => moment.unix(pollStore.configuration.expire)._d,
23+
get: () => pollStore.getExpirationDateTime.toJSDate(),
2424
set: (value) => {
25-
pollStore.configuration.expire = moment(value).unix()
25+
pollStore.configuration.expire = DateTime.fromJSDate(value).toSeconds()
2626
pollStore.write()
2727
},
2828
})
@@ -31,17 +31,16 @@ const useExpire = computed({
3131
get: () => !!pollStore.configuration.expire,
3232
set: (value) => {
3333
if (value) {
34-
pollStore.configuration.expire = moment().add(1, 'week').unix()
34+
pollStore.configuration.expire = DateTime.now()
35+
.plus({ week: 1 })
36+
.toSeconds()
3537
} else {
3638
pollStore.configuration.expire = 0
3739
}
3840
pollStore.write()
3941
},
4042
})
4143
42-
/**
43-
*
44-
*/
4544
function clickToggleClosed() {
4645
if (pollStore.isClosed) {
4746
pollStore.reopen()

src/components/Configuration/ConfigProposals.vue

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
<script setup lang="ts">
77
import { computed } from 'vue'
8-
import moment from '@nextcloud/moment'
8+
import { DateTime } from 'luxon'
99
import { t } from '@nextcloud/l10n'
1010
1111
import NcCheckboxRadioSwitch from '@nextcloud/vue/components/NcCheckboxRadioSwitch'
@@ -24,9 +24,10 @@ const allowProposals = computed({
2424
})
2525
2626
const pollExpire = computed({
27-
get: () => moment.unix(pollStore.configuration.proposalsExpire)._d,
27+
get: () => pollStore.getProposalExpirationDateTime.toJSDate(),
2828
set: (value) => {
29-
pollStore.configuration.proposalsExpire = moment(value).unix()
29+
pollStore.configuration.proposalsExpire =
30+
DateTime.fromJSDate(value).toSeconds()
3031
pollStore.write()
3132
},
3233
})
@@ -35,7 +36,9 @@ const proposalExpiration = computed({
3536
get: () => !!pollStore.configuration.proposalsExpire,
3637
set: (value) => {
3738
if (value) {
38-
pollStore.configuration.proposalsExpire = moment().add(1, 'week').unix()
39+
pollStore.configuration.proposalsExpire = DateTime.now()
40+
.plus({ week: 1 })
41+
.toSeconds()
3942
} else {
4043
pollStore.configuration.proposalsExpire = 0
4144
}

src/components/Options/OptionCloneDate.vue

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
<script setup lang="ts">
77
import { computed, ref } from 'vue'
8-
import moment from '@nextcloud/moment'
8+
import { DateTime } from 'luxon'
99
import { t } from '@nextcloud/l10n'
1010
1111
import NcSelect from '@nextcloud/vue/components/NcSelect'
@@ -36,7 +36,7 @@ const sequence = ref<Sequence>({
3636
})
3737
3838
const dateBaseOptionString = computed(() =>
39-
moment.unix(option.timestamp).format('LLLL'),
39+
DateTime.fromSeconds(option.timestamp).toLocaleString(DateTime.DATETIME_FULL),
4040
)
4141
4242
/**

src/components/Poll/PollInfoLine.vue

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55

66
<script setup lang="ts">
77
import { computed } from 'vue'
8-
import moment from '@nextcloud/moment'
98
import { t } from '@nextcloud/l10n'
109
1110
import { usePollStore } from '../../stores/poll'
@@ -129,19 +128,19 @@ const subTexts = computed(() => {
129128
})
130129
131130
const dateCreatedRelative = computed(() =>
132-
moment.unix(pollStore.status.created).fromNow(),
131+
pollStore.getExpirationDateTime.toRelative(),
133132
)
134133
135134
const closeToClosing = computed(
136135
() =>
137136
!pollStore.isClosed
138137
&& pollStore.configuration.expire
139-
&& moment.unix(pollStore.configuration.expire).diff() < 86400000,
138+
&& pollStore.getExpirationDateTime.diffNow().as('days') < 1,
140139
)
141140
142141
const timeExpirationRelative = computed(() => {
143142
if (pollStore.configuration.expire) {
144-
return moment.unix(pollStore.configuration.expire).fromNow()
143+
return pollStore.getExpirationDateTime.toRelative() as string
145144
}
146145
return t('polls', 'never')
147146
})

src/components/Poll/PollInformation.vue

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55

66
<script setup lang="ts">
77
import { computed } from 'vue'
8-
import moment from '@nextcloud/moment'
98
import { t, n } from '@nextcloud/l10n'
109
1110
import OwnerIcon from 'vue-material-design-icons/Crown.vue'
@@ -77,11 +76,11 @@ const accessCaption = computed(() =>
7776
? t('polls', 'Private poll')
7877
: t('polls', 'Openly accessible poll'),
7978
)
80-
const dateCreatedRelative = computed(() =>
81-
moment.unix(pollStore.status.created).fromNow(),
79+
const dateCreatedRelative = computed(
80+
() => pollStore.getCreationDateTime.toRelative() as string,
8281
)
83-
const dateExpiryRelative = computed(() =>
84-
moment.unix(pollStore.configuration.expire).fromNow(),
82+
const dateExpiryRelative = computed(
83+
() => pollStore.getCreationDateTime.toRelative() as string,
8584
)
8685
const currentTimeZone = Intl.DateTimeFormat().resolvedOptions().timeZone
8786
const countAllYesVotes = computed(() => votesStore.countAllVotesByAnswer('yes'))

0 commit comments

Comments
 (0)