Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions src/components/Proposal/ProposalResponseMatrix.vue
Original file line number Diff line number Diff line change
Expand Up @@ -201,15 +201,15 @@ export default {
const groups = {}
dates.forEach((d) => {
// Apply timezone offset for grouping by day
const offset = getTimezoneOffset(d.date.toISOString(), this.timezoneId)
const offset = getTimezoneOffset(d.date, this.timezoneId)
const key = moment(d.date).utcOffset(offset).format('YYYY-MM-DD')
if (!groups[key]) {
groups[key] = []
}
groups[key].push(d)
})
return Object.entries(groups).map(([key, grp]: [string, ProposalDate[]]) => {
const offset = getTimezoneOffset(grp[0].date.toISOString(), this.timezoneId)
const offset = getTimezoneOffset(grp[0].date, this.timezoneId)
return {
key,
label: moment(grp[0].date).utcOffset(offset).format('dddd, MMMM Do'),
Expand All @@ -230,7 +230,7 @@ export default {
t,

dateTimeSpan(date) {
const offset = getTimezoneOffset(date.toISOString(), this.timezoneId)
const offset = getTimezoneOffset(date, this.timezoneId)
const startDate = moment(date).utcOffset(offset)
const endDate = moment(date).utcOffset(offset).add(this.proposal.duration, 'minutes')

Expand All @@ -255,7 +255,7 @@ export default {
return ''
}
// Apply timezone offset and format very compact: "7/8 2PM"
const offset = getTimezoneOffset(date.toISOString(), this.timezoneId)
const offset = getTimezoneOffset(date, this.timezoneId)
const adjustedDate = moment(date).utcOffset(offset)
return adjustedDate.format('M/D LT').replace(':00', '').replace(' ', ' ')
},
Expand Down
52 changes: 0 additions & 52 deletions src/services/timezoneOffsetService.js

This file was deleted.

42 changes: 42 additions & 0 deletions src/services/timezoneOffsetService.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/**
* SPDX-FileCopyrightText: 2026 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
export function getTimezoneOffset(proposalDate: Date, timezoneId: string): number {
let timezoneOffset = 0

try {
const dtf = new Intl.DateTimeFormat('en-US', {
timeZone: timezoneId,
hour12: false,
year: 'numeric',
month: '2-digit',
day: '2-digit',
hour: '2-digit',
minute: '2-digit',
second: '2-digit',
})

const parts = dtf.formatToParts(proposalDate)

const values: Record<string, string> = {}
parts.forEach(({ type, value }) => {
if (type !== 'literal') values[type] = value
})

const asUTC = Date.UTC(
Number(values.year),
Number(values.month) - 1,
Number(values.day),
Number(values.hour),
Number(values.minute),
Number(values.second),
)

timezoneOffset = Math.round((asUTC - proposalDate.getTime()) / 60000)
} catch (e) {
timezoneOffset = 0
}

return timezoneOffset
}
Loading