From 78f938367b211c3e451746484756d4fb068e9c5c Mon Sep 17 00:00:00 2001 From: Pilar Candia Date: Sat, 21 Oct 2023 16:43:28 -0400 Subject: [PATCH] =?UTF-8?q?[5.1]=20MSPB-343:=20Fix=20issue=20where=20delet?= =?UTF-8?q?ing=20a=20range=20for=20a=20specific=20year=20is=20not=E2=80=A6?= =?UTF-8?q?=20(#514)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * 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 --- .../strategyHolidays/strategyHolidays.js | 72 ++++++++++++++----- 1 file changed, 56 insertions(+), 16 deletions(-) diff --git a/submodules/strategyHolidays/strategyHolidays.js b/submodules/strategyHolidays/strategyHolidays.js index cf2fa7e2..5428a0ca 100644 --- a/submodules/strategyHolidays/strategyHolidays.js +++ b/submodules/strategyHolidays/strategyHolidays.js @@ -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; @@ -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 @@ -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); + } }); } @@ -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 = { @@ -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));