mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-12-17 14:47:53 +01:00
fix some date issues with scheduling
This commit is contained in:
committed by
Sabe Jones
parent
962456204e
commit
2a84561e00
@@ -711,6 +711,20 @@ export const GALA_SCHEDULE = {
|
|||||||
],
|
],
|
||||||
};
|
};
|
||||||
|
|
||||||
|
function getDay (date) {
|
||||||
|
if (date === undefined) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
return date instanceof moment ? date.date() : date.getDate();
|
||||||
|
}
|
||||||
|
|
||||||
|
function getMonth (date) {
|
||||||
|
if (date === undefined) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
return date instanceof moment ? date.month() : date.getMonth();
|
||||||
|
}
|
||||||
|
|
||||||
function getGalaIndex (date) {
|
function getGalaIndex (date) {
|
||||||
const month = date instanceof moment ? date.month() : date.getMonth();
|
const month = date instanceof moment ? date.month() : date.getMonth();
|
||||||
const todayDay = date instanceof moment ? date.date() : date.getDate();
|
const todayDay = date instanceof moment ? date.date() : date.getDate();
|
||||||
@@ -745,11 +759,22 @@ export function assembleScheduledMatchers (date) {
|
|||||||
let cachedScheduleMatchers = null;
|
let cachedScheduleMatchers = null;
|
||||||
|
|
||||||
export function getScheduleMatchingGroup (type, date) {
|
export function getScheduleMatchingGroup (type, date) {
|
||||||
|
let checkedDate = date;
|
||||||
|
if (checkedDate === undefined) {
|
||||||
|
checkedDate = new Date();
|
||||||
|
}
|
||||||
|
if (cacheDate !== null && (getDay(checkedDate) !== getDay(cacheDate)
|
||||||
|
|| getMonth(checkedDate) !== getMonth(cacheDate))) {
|
||||||
|
cacheDate = null;
|
||||||
|
cachedScheduleMatchers = null;
|
||||||
|
}
|
||||||
|
console.log('Loading content for', type, 'on', checkedDate, 'with cached date', cacheDate, 'and cached schedule');
|
||||||
if (!cachedScheduleMatchers) {
|
if (!cachedScheduleMatchers) {
|
||||||
cachedScheduleMatchers = {};
|
cacheDate = new Date();
|
||||||
assembleScheduledMatchers(date || new Date()).forEach(matcher => {
|
const scheduleMatchers = {};
|
||||||
if (!cachedScheduleMatchers[matcher.type]) {
|
assembleScheduledMatchers(checkedDate).forEach(matcher => {
|
||||||
cachedScheduleMatchers[matcher.type] = {
|
if (!scheduleMatchers[matcher.type]) {
|
||||||
|
scheduleMatchers[matcher.type] = {
|
||||||
matchers: [],
|
matchers: [],
|
||||||
items: [],
|
items: [],
|
||||||
match (key) {
|
match (key) {
|
||||||
|
|||||||
Reference in New Issue
Block a user