Add Sat and Sun to Memorial Day
Signed-off-by: James Ketrenos <james.p.ketrenos@intel.com>
This commit is contained in:
parent
9805cef821
commit
8428e1c06d
@ -545,12 +545,14 @@ router.get("/holiday/:holiday", function(req, res/*, next*/) {
|
||||
dayIsHoliday = "",
|
||||
holidayName;
|
||||
|
||||
/* Find the holiday in the list of holidays */
|
||||
let lookup = moment().holidays([req.params.holiday]);
|
||||
if (!lookup) {
|
||||
return res.status(404).send(req.params.holiday + " holiday not found.");
|
||||
}
|
||||
holidayName = Object.getOwnPropertyNames(lookup)[0];
|
||||
|
||||
/* Lookup the date for the holiday on every year from 'startYear' (1990) to today */
|
||||
for (let year = startYear; year <= moment().year(); year++) {
|
||||
let holiday = moment(year + "-01-01", "YYYY-MM-DD").holiday(req.params.holiday);
|
||||
if (!holiday) {
|
||||
@ -558,11 +560,29 @@ router.get("/holiday/:holiday", function(req, res/*, next*/) {
|
||||
continue;
|
||||
}
|
||||
|
||||
let comparison = "strftime('%Y-%m-%d',taken)='" + holiday.format("YYYY-MM-DD") + "'"
|
||||
if (!dayIsHoliday) {
|
||||
dayIsHoliday = comparison;
|
||||
} else {
|
||||
dayIsHoliday += " OR " + comparison;
|
||||
/*
|
||||
* NOTE: Memorial Day and Labor Day are two special cases -- the holiday is a Monday,
|
||||
* however the entire weekend typically is holidy-esque. Account for that below.
|
||||
* We (should) could expand this to account for Fri or Mon on the 4th of July, Christmas,
|
||||
* or New Years as well. */
|
||||
|
||||
let extraDays = 0;
|
||||
if (req.params.holiday.toLowerCase() == 'memorial day') {
|
||||
extraDays = -2; /* Include two days prior */
|
||||
}
|
||||
let direction = extraDays < 0 ? -1 : 1;
|
||||
|
||||
for (let i = 0; i <= Math.abs(extraDays); i++) {
|
||||
let comparison = "strftime('%Y-%m-%d',taken)='" + holiday.format("YYYY-MM-DD") + "'";
|
||||
/* If no holiday has been set yet, start the comparison function passed to WHERE
|
||||
* otherwise append it with OR. */
|
||||
if (!dayIsHoliday) {
|
||||
dayIsHoliday = comparison;
|
||||
} else {
|
||||
dayIsHoliday += " OR " + comparison;
|
||||
}
|
||||
|
||||
holiday.date(holiday.date() + direction);
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user