Skip to content

Commit 1c40044

Browse files
phillipthelenSabreCat
authored andcommitted
better timezone handling
1 parent 5784694 commit 1c40044

File tree

1 file changed

+9
-8
lines changed

1 file changed

+9
-8
lines changed

website/common/script/content/constants/schedule.js

+9-8
Original file line numberDiff line numberDiff line change
@@ -796,22 +796,24 @@ export const TYPE_SCHEDULE = {
796796
customizations: GALA_SWITCHOVER_DAY,
797797
};
798798

799+
function adjustDateForUTCAndSwitch (date) {
800+
const checkDate = new Date(date.getTime() + date.getTimezoneOffset() * 60000);
801+
checkDate.setHours(checkDate.getHours() - SWITCHOVER_TIME);
802+
return checkDate;
803+
}
804+
799805
function getDay (date) {
800806
if (date === undefined) {
801807
return 0;
802808
}
803-
const checkDate = new Date(date.getTime());
804-
checkDate.setHours(checkDate.getHours() - SWITCHOVER_TIME);
805-
return checkDate.getDate();
809+
return adjustDateForUTCAndSwitch(date).getDate();
806810
}
807811

808812
function getMonth (date) {
809813
if (date === undefined) {
810814
return 0;
811815
}
812-
const checkDate = new Date(date.getTime());
813-
checkDate.setHours(checkDate.getHours() - SWITCHOVER_TIME);
814-
return checkDate.getMonth();
816+
return adjustDateForUTCAndSwitch(date).getMonth();
815817
}
816818

817819
function getGalaIndex (date) {
@@ -919,8 +921,7 @@ export function getAllScheduleMatchingGroups (date) {
919921
// subtract switchover time for the matcher classes, but
920922
// NOT to decide which matchers to assemble.
921923
// assembly uses getDate and getMonth which already adjust for switchover time
922-
const adjustedDate = new Date(checkedDate.getTime());
923-
adjustedDate.setHours(adjustedDate.getHours() - SWITCHOVER_TIME);
924+
const adjustedDate = adjustDateForUTCAndSwitch(checkedDate);
924925
assembleScheduledMatchers(checkedDate).forEach(matcher => {
925926
if (!cachedScheduleMatchers[matcher.type]) {
926927
cachedScheduleMatchers[matcher.type] = makeMatcherClass(adjustedDate);

0 commit comments

Comments
 (0)