Skip to content

Commit 7b4af9c

Browse files
authored
Fixed gig calendar bug where summer time was not handled correctly (#290)
1 parent 10694cf commit 7b4af9c

1 file changed

Lines changed: 10 additions & 2 deletions

File tree

src/utils/date.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,16 @@ export const isChristmas = () => new Date().getMonth() === 11;
6464

6565
export const isJuly = () => new Date().getMonth() === 6;
6666

67+
const getHourOffset = (locale: Intl.LocalesArgument, date: Date) => {
68+
const d = new Date(date);
69+
// Set time to middle of day to handle -12 to +12
70+
d.setUTCHours(12);
71+
const hourLocale = parseInt(d.toLocaleString(locale, { hour: 'numeric' }));
72+
return hourLocale - d.getUTCHours();
73+
};
74+
6775
const parseGigTime = (date: Date, time: string) => {
68-
// `time` is a string describing a time of day in UTC+1
76+
// `time` is a string describing a time of day in Swedish time
6977
// Only consider the first two characters (incase `time` is '21:15ish')
7078
const [hour = NaN, minute = NaN] = time
7179
.split(/[:.]/)
@@ -74,7 +82,7 @@ const parseGigTime = (date: Date, time: string) => {
7482
return undefined;
7583
}
7684
const dateTime = new Date(date);
77-
dateTime.setUTCHours(hour - 1, minute);
85+
dateTime.setUTCHours(hour - getHourOffset('sv-SE', dateTime), minute);
7886
return dateTime;
7987
};
8088

0 commit comments

Comments
 (0)