ketr.photos/server/routes/holidays.js
James Ketrenos 404d934c55 Include New Year's and New Year's Eve
Signed-off-by: James Ketrenos <james_gitlab@ketrenos.com>
2020-01-01 17:24:09 -08:00

50 lines
1.2 KiB
JavaScript

"use strict";
const express = require("express"),
moment = require("moment-holiday");
require("../lib/pascha.js")(moment);
const router = express.Router();
/* Remove the western Easter dates, except for Easter itself */
[ 'Good Friday' ].forEach(function(holiday) {
moment.modifyHolidays.remove(holiday);
});
router.get("/", function(req, res/*, next*/) {
let holidays = [], skip = {};
moment("1999-12-31", "YYYY-MM-DD").holidaysBetween("2001-01-01").forEach(function(holiday) {
/* Dates with multiple holidays will return an array of items */
let names = holiday.isHoliday();
if (!Array.isArray(names)) {
names = [ names ];
}
names.forEach(function(name) {
if (name in skip) {
return;
}
/* If this holiday already exists, remove it from the holidays list
* as we only want single day events returned, and add to the 'skip'
* list */
let index = holidays.indexOf(name);
if (index != -1) {
holidays.splice(index, 1);
skip[name] = true;
} else {
holidays.push(name);
}
});
});
return res.status(200).send({
holidays: holidays,
next: moment().nextHoliday().isHoliday()
});
});
module.exports = router;