From 35e44a8a8034942c6d2e0a92e5e18020bd2d7a81 Mon Sep 17 00:00:00 2001 From: lesion Date: Wed, 27 Apr 2022 11:58:58 +0200 Subject: [PATCH] use local instance timezone everywhere #151 --- components/Calendar.vue | 7 +++-- pages/add/DateInput.vue | 19 +++++++------- pages/add/_edit.vue | 10 +++---- pages/index.vue | 52 +++++++++++++++++-------------------- plugins/filters.js | 31 ++++++++++++---------- server/api/models/event.js | 12 +++++---- server/initialize.server.js | 6 +++++ 7 files changed, 72 insertions(+), 65 deletions(-) diff --git a/components/Calendar.vue b/components/Calendar.vue index 8426f0c0..899fd16b 100644 --- a/components/Calendar.vue +++ b/components/Calendar.vue @@ -9,6 +9,7 @@ @update:from-page='updatePage' :locale='$i18n.locale' :attributes='attributes' + :timezone='settings.instance_timezone' transition='fade' aria-label='Calendar' is-expanded @@ -26,8 +27,8 @@ export default { events: { type: Array, default: () => [] } }, data () { - const month = dayjs().month() + 1 - const year = dayjs().year() + const month = dayjs.tz().month() + 1 + const year = dayjs.tz().year() return { selectedDate: null, page: { month, year } @@ -42,9 +43,7 @@ export default { methods: { ...mapActions(['updateEvents', 'showPastEvents']), updatePage (page) { - return new Promise((resolve, reject) => { this.$emit('monthchange', page) - }) }, click (day) { this.$emit('dayclick', day) diff --git a/pages/add/DateInput.vue b/pages/add/DateInput.vue index b6d605ef..0cc27494 100644 --- a/pages/add/DateInput.vue +++ b/pages/add/DateInput.vue @@ -78,8 +78,7 @@ export default { todayEvents () { const start = dayjs(this.value.from).startOf('day').unix() const end = dayjs(this.value.from).endOf('day').unix() - const events = this.events.filter(e => e.start_datetime >= start && e.start_datetime <= end) - return events + return this.events.filter(e => e.start_datetime >= start && e.start_datetime <= end) }, attributes () { return attributesFromEvents(this.events, this.tags) @@ -92,10 +91,10 @@ export default { }, fromHour () { - return this.value.from && this.value.fromHour ? dayjs(this.value.from).format('HH:mm') : null + return this.value.from && this.value.fromHour ? dayjs.tz(this.value.from).format('HH:mm') : null }, dueHour () { - return this.value.due && this.value.dueHour ? dayjs(this.value.due).format('HH:mm') : null + return this.value.due && this.value.dueHour ? dayjs.tz(this.value.due).format('HH:mm') : null }, hourList () { const hourList = [] @@ -196,7 +195,7 @@ export default { } else if (what === 'fromHour') { if (value) { const [hour, minute] = value.split(':') - const from = dayjs(this.value.from).hour(hour).minute(minute).second(0) + const from = dayjs.tz(this.value.from).hour(hour).minute(minute).second(0) this.$emit('input', { ...this.value, from, fromHour: true }) } else { this.$emit('input', { ...this.value, fromHour: false }) @@ -204,7 +203,7 @@ export default { } else if (what === 'dueHour') { if (value) { const [hour, minute] = value.split(':') - const fromHour = dayjs(this.value.from).hour() + const fromHour = dayjs.tz(this.value.from).hour() // add a day let due = dayjs(this.value.from) @@ -226,20 +225,20 @@ export default { let from = value.start let due = value.end if (this.value.fromHour) { - from = dayjs(value.start).hour(dayjs(this.value.from).hour()) + from = dayjs.tz(value.start).hour(dayjs.tz(this.value.from).hour()) } if (this.value.dueHour) { - due = dayjs(value.end).hour(dayjs(this.value.due).hour()) + due = dayjs.tz(value.end).hour(dayjs.tz(this.value.due).hour()) } this.$emit('input', { ...this.value, from, due }) } else { let from = value let due = this.value.due if (this.value.fromHour) { - from = dayjs(value).hour(dayjs(this.value.from).hour()) + from = dayjs.tz(value).hour(dayjs.tz(this.value.from).hour()) } if (this.value.dueHour && this.value.due) { - due = dayjs(value).hour(dayjs(this.value.due).hour()) + due = dayjs.tz(value).hour(dayjs.tz(this.value.due).hour()) } this.$emit('input', { ...this.value, from, due }) } diff --git a/pages/add/_edit.vue b/pages/add/_edit.vue index d2563df6..81a7bc65 100644 --- a/pages/add/_edit.vue +++ b/pages/add/_edit.vue @@ -84,7 +84,7 @@ export default { validate ({ store }) { return (store.state.auth.loggedIn || store.state.settings.allow_anon_event) }, - async asyncData ({ params, $axios, error, store }) { + async asyncData ({ params, $axios, error }) { if (params.edit) { const data = { event: { place: {}, media: [] } } data.id = params.edit @@ -101,8 +101,8 @@ export default { data.event.place.address = event.place.address || '' data.date = { recurrent: event.recurrent, - from: new Date(dayjs.unix(event.start_datetime)), - due: new Date(dayjs.unix(event.end_datetime)), + from: dayjs.unix(event.start_datetime).toDate(), + due: dayjs.unix(event.end_datetime).toDate(), multidate: event.multidate, fromHour: true, dueHour: true @@ -118,8 +118,8 @@ export default { return {} }, data () { - const month = dayjs().month() + 1 - const year = dayjs().year() + const month = dayjs.tz().month() + 1 + const year = dayjs.tz().year() return { mdiFileImport, mdiFormatTitle, mdiTagMultiple, mdiCloseCircle, valid: false, diff --git a/pages/index.vue b/pages/index.vue index 94225393..aaeb53d1 100644 --- a/pages/index.vue +++ b/pages/index.vue @@ -1,26 +1,25 @@