mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-12-17 06:37:23 +01:00
better timezone handling
This commit is contained in:
committed by
Sabe Jones
parent
5784694dc9
commit
1c40044525
@@ -796,22 +796,24 @@ export const TYPE_SCHEDULE = {
|
|||||||
customizations: GALA_SWITCHOVER_DAY,
|
customizations: GALA_SWITCHOVER_DAY,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
function adjustDateForUTCAndSwitch (date) {
|
||||||
|
const checkDate = new Date(date.getTime() + date.getTimezoneOffset() * 60000);
|
||||||
|
checkDate.setHours(checkDate.getHours() - SWITCHOVER_TIME);
|
||||||
|
return checkDate;
|
||||||
|
}
|
||||||
|
|
||||||
function getDay (date) {
|
function getDay (date) {
|
||||||
if (date === undefined) {
|
if (date === undefined) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
const checkDate = new Date(date.getTime());
|
return adjustDateForUTCAndSwitch(date).getDate();
|
||||||
checkDate.setHours(checkDate.getHours() - SWITCHOVER_TIME);
|
|
||||||
return checkDate.getDate();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function getMonth (date) {
|
function getMonth (date) {
|
||||||
if (date === undefined) {
|
if (date === undefined) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
const checkDate = new Date(date.getTime());
|
return adjustDateForUTCAndSwitch(date).getMonth();
|
||||||
checkDate.setHours(checkDate.getHours() - SWITCHOVER_TIME);
|
|
||||||
return checkDate.getMonth();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function getGalaIndex (date) {
|
function getGalaIndex (date) {
|
||||||
@@ -919,8 +921,7 @@ export function getAllScheduleMatchingGroups (date) {
|
|||||||
// subtract switchover time for the matcher classes, but
|
// subtract switchover time for the matcher classes, but
|
||||||
// NOT to decide which matchers to assemble.
|
// NOT to decide which matchers to assemble.
|
||||||
// assembly uses getDate and getMonth which already adjust for switchover time
|
// assembly uses getDate and getMonth which already adjust for switchover time
|
||||||
const adjustedDate = new Date(checkedDate.getTime());
|
const adjustedDate = adjustDateForUTCAndSwitch(checkedDate);
|
||||||
adjustedDate.setHours(adjustedDate.getHours() - SWITCHOVER_TIME);
|
|
||||||
assembleScheduledMatchers(checkedDate).forEach(matcher => {
|
assembleScheduledMatchers(checkedDate).forEach(matcher => {
|
||||||
if (!cachedScheduleMatchers[matcher.type]) {
|
if (!cachedScheduleMatchers[matcher.type]) {
|
||||||
cachedScheduleMatchers[matcher.type] = makeMatcherClass(adjustedDate);
|
cachedScheduleMatchers[matcher.type] = makeMatcherClass(adjustedDate);
|
||||||
|
|||||||
Reference in New Issue
Block a user