Skip to content

Commit

Permalink
[5.1] MSPB-343: Fix issue where deleting a range for a specific year …
Browse files Browse the repository at this point in the history
…is not… (#514)

* MSPB-343: Fix issue where deleting a range for a specific year is not respected

* Fix issue where range in different months was not excluding years

* Fix issue where the month is incorrect
  • Loading branch information
pcandia committed Dec 12, 2023
1 parent 526215a commit 78f9383
Showing 1 changed file with 56 additions and 16 deletions.
72 changes: 56 additions & 16 deletions submodules/strategyHolidays/strategyHolidays.js
Original file line number Diff line number Diff line change
Expand Up @@ -858,12 +858,17 @@ define(function(require) {
holidaysData.push({ holidayType: holidayType, holidayData: holidayData });

if (val.hasOwnProperty('exclude')) {
holidayData.excludeYear = [];

_.forEach(val.exclude, function(date) {
var year = parseInt(date.substring(0, 4));
holidayData.excludeYear.push(year);
});
if (val.hasOwnProperty('temporal_rules')) {
holidayData.excludeYear = val.exclude;
} else {
holidayData.excludeYear = [];
_.forEach(val.exclude, function(date) {
var year = parseInt(date.substring(0, 4));
if (!_.includes(holidayData.excludeYear, year)) {
holidayData.excludeYear.push(year);
}
});
}
}
}
self.appFlags.strategyHolidays.allHolidays = holidaysData;
Expand Down Expand Up @@ -1013,6 +1018,15 @@ define(function(require) {
}
},

/**
* Returns Date in the format MMDDYYYY
* @param {string} endYear
* @return {Date}
*/
formatDate: function formatDateToExclude(date) {
return date.toISOString().split('T')[0].split('-').join('');
},

/**
* Returns an objects with formatted data for a holiday.
* @param {Object} holiday
Expand Down Expand Up @@ -1082,8 +1096,18 @@ define(function(require) {
holidayRule.exclude = [];

_.forEach(holidayData.excludeYear, function(year) {
var excludeDate = self.strategyHolidaysGetEndDate(year, holiday).toISOString().split('T')[0].split('-').join('');
holidayRule.exclude.push(excludeDate);
if (holiday.holidayType === 'range' && holidayData.set) {
holidayRule.exclude.push(year);
} else if (holiday.holidayType === 'range') {
_.forEach(_.range(fromDay, toDay + 1), function(day) {
holidayRule.exclude.push(
self.formatDate(new Date(year, holidayData.toMonth - 1, day))
);
});
} else {
var excludeDate = self.formatDate(self.strategyHolidaysGetEndDate(year, holiday));
holidayRule.exclude.push(excludeDate);
}
});
}

Expand All @@ -1107,15 +1131,27 @@ define(function(require) {
var month = parseInt(pMonth),
fromDay = pStartDay || 1,
toDay = pEndDay || 31,
days = _.range(fromDay, toDay + 1);
days = _.range(fromDay, toDay + 1),
rule = {
name: name + '_' + month,
cycle: 'yearly',
days: days,
interval: 1,
month: month
};

return {
name: name + '_' + month,
cycle: 'yearly',
days: days,
interval: 1,
month: month
};
if (data.exclude) {
rule.exclude = [];
_.forEach(data.exclude, function(year) {
_.forEach(_.range(fromDay, toDay + 1), function(day) {
rule.exclude.push(
self.formatDate(new Date(year, month - 1, day))
);
});
});
}

return rule;
},
rulesToCreate = [],
ruleSet = {
Expand All @@ -1126,6 +1162,10 @@ define(function(require) {
parallelRequests = {},
junkName = name + '_' + monster.util.randomString(6);

if (data.exclude) {
ruleSet.exclude = data.exclude;
}

if (fromMonth !== toMonth) {
rulesToCreate.push(getMonthRule(junkName, fromMonth, fromDay, 31));

Expand Down

0 comments on commit 78f9383

Please sign in to comment.