Skip to content

Commit 188ff32

Browse files
authored
Fix adress review comments (#1)
* Fix make timezoneoffset typescript Signed-off-by: taiebot <dedreuil@yahoo.fr> * Delete src/services/timezoneOffsetService.js Signed-off-by: taiebot <dedreuil@yahoo.fr> * Fix adress review comments Signed-off-by: taiebot <dedreuil@yahoo.fr> --------- Signed-off-by: taiebot <dedreuil@yahoo.fr>
1 parent 3131d8a commit 188ff32

3 files changed

Lines changed: 46 additions & 56 deletions

File tree

src/components/Proposal/ProposalResponseMatrix.vue

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -201,15 +201,15 @@ export default {
201201
const groups = {}
202202
dates.forEach((d) => {
203203
// Apply timezone offset for grouping by day
204-
const offset = getTimezoneOffset(d.date.toISOString(), this.timezoneId)
204+
const offset = getTimezoneOffset(d.date, this.timezoneId)
205205
const key = moment(d.date).utcOffset(offset).format('YYYY-MM-DD')
206206
if (!groups[key]) {
207207
groups[key] = []
208208
}
209209
groups[key].push(d)
210210
})
211211
return Object.entries(groups).map(([key, grp]: [string, ProposalDate[]]) => {
212-
const offset = getTimezoneOffset(grp[0].date.toISOString(), this.timezoneId)
212+
const offset = getTimezoneOffset(grp[0].date, this.timezoneId)
213213
return {
214214
key,
215215
label: moment(grp[0].date).utcOffset(offset).format('dddd, MMMM Do'),
@@ -230,7 +230,7 @@ export default {
230230
t,
231231
232232
dateTimeSpan(date) {
233-
const offset = getTimezoneOffset(date.toISOString(), this.timezoneId)
233+
const offset = getTimezoneOffset(date, this.timezoneId)
234234
const startDate = moment(date).utcOffset(offset)
235235
const endDate = moment(date).utcOffset(offset).add(this.proposal.duration, 'minutes')
236236
@@ -255,7 +255,7 @@ export default {
255255
return ''
256256
}
257257
// Apply timezone offset and format very compact: "7/8 2PM"
258-
const offset = getTimezoneOffset(date.toISOString(), this.timezoneId)
258+
const offset = getTimezoneOffset(date, this.timezoneId)
259259
const adjustedDate = moment(date).utcOffset(offset)
260260
return adjustedDate.format('M/D LT').replace(':00', '').replace(' ', ' ')
261261
},

src/services/timezoneOffsetService.js

Lines changed: 0 additions & 52 deletions
This file was deleted.
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
/**
2+
* SPDX-FileCopyrightText: 2026 Nextcloud GmbH and Nextcloud contributors
3+
* SPDX-License-Identifier: AGPL-3.0-or-later
4+
*/
5+
export function getTimezoneOffset(proposalDate: Date, timezoneId: string): number {
6+
let timezoneOffset = 0
7+
8+
try {
9+
const dtf = new Intl.DateTimeFormat('en-US', {
10+
timeZone: timezoneId,
11+
hour12: false,
12+
year: 'numeric',
13+
month: '2-digit',
14+
day: '2-digit',
15+
hour: '2-digit',
16+
minute: '2-digit',
17+
second: '2-digit',
18+
})
19+
20+
const parts = dtf.formatToParts(proposalDate)
21+
22+
const values: Record<string, string> = {}
23+
parts.forEach(({ type, value }) => {
24+
if (type !== 'literal') values[type] = value
25+
})
26+
27+
const asUTC = Date.UTC(
28+
Number(values.year),
29+
Number(values.month) - 1,
30+
Number(values.day),
31+
Number(values.hour),
32+
Number(values.minute),
33+
Number(values.second),
34+
)
35+
36+
timezoneOffset = Math.round((asUTC - proposalDate.getTime()) / 60000)
37+
} catch (e) {
38+
timezoneOffset = 0
39+
}
40+
41+
return timezoneOffset
42+
}

0 commit comments

Comments
 (0)