Added ability to pass specific date as the holiday
Signed-off-by: James Ketrenos <james_gitlab@ketrenos.com>
This commit is contained in:
parent
594a2bdc68
commit
8c7a9dbcf4
@ -542,20 +542,37 @@ router.delete("/:id?", function(req, res/*, next*/) {
|
|||||||
|
|
||||||
router.get("/holiday/:holiday", function(req, res/*, next*/) {
|
router.get("/holiday/:holiday", function(req, res/*, next*/) {
|
||||||
let startYear = 1990,
|
let startYear = 1990,
|
||||||
|
endYear = moment().year(),
|
||||||
dayIsHoliday = "",
|
dayIsHoliday = "",
|
||||||
holidayName;
|
holidayName,
|
||||||
|
date = undefined;
|
||||||
|
|
||||||
/* Find the holiday in the list of holidays */
|
/* Find the holiday in the list of holidays */
|
||||||
let lookup = moment().holidays([req.params.holiday]);
|
let lookup = moment().holidays([req.params.holiday]);
|
||||||
if (!lookup) {
|
if (!lookup) {
|
||||||
|
date = req.params.holiday.match(/^((\d{4})-)?(\d{2})-(\d{2})$/);
|
||||||
|
if (!date) {
|
||||||
return res.status(404).send(req.params.holiday + " holiday not found.");
|
return res.status(404).send(req.params.holiday + " holiday not found.");
|
||||||
}
|
}
|
||||||
holidayName = Object.getOwnPropertyNames(lookup)[0];
|
date = {
|
||||||
|
year: date[1],
|
||||||
|
month: date[3],
|
||||||
|
day: date[4]
|
||||||
|
};
|
||||||
|
if (date.year) {
|
||||||
|
startYear = date.year;
|
||||||
|
endYear = date.year;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
holidayName = date ? req.params.holiday : Object.getOwnPropertyNames(lookup)[0];
|
||||||
console.log("Searching for holiday: " + holidayName);
|
console.log("Searching for holiday: " + holidayName);
|
||||||
/* Lookup the date for the holiday on every year from 'startYear' (1990) to today */
|
/* Lookup the date for the holiday on every year from 'startYear' (1990) to today */
|
||||||
for (let year = startYear; year <= moment().year(); year++) {
|
for (let year = startYear; year <= endYear; year++) {
|
||||||
console.log("Getting year: " + year);
|
console.log("Getting year: " + year);
|
||||||
let holiday = moment(year + "-01-01", "YYYY-MM-DD").holiday(req.params.holiday);
|
let holiday;
|
||||||
|
|
||||||
|
if (!date) {
|
||||||
|
holiday = moment(year + "-01-01", "YYYY-MM-DD").holiday(req.params.holiday);
|
||||||
if (!holiday) {
|
if (!holiday) {
|
||||||
/* 'Leap Year' doesn't exist every year... */
|
/* 'Leap Year' doesn't exist every year... */
|
||||||
continue;
|
continue;
|
||||||
@ -584,7 +601,9 @@ router.get("/holiday/:holiday", function(req, res/*, next*/) {
|
|||||||
let direction = extraDays < 0 ? -1 : 1;
|
let direction = extraDays < 0 ? -1 : 1;
|
||||||
|
|
||||||
for (let i = 0; i <= Math.abs(extraDays); i++) {
|
for (let i = 0; i <= Math.abs(extraDays); i++) {
|
||||||
let comparison = "strftime('%Y-%m-%d',taken)='" + holiday.format("YYYY-MM-DD") + "'";
|
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
|
/* If no holiday has been set yet, start the comparison function passed to WHERE
|
||||||
* otherwise append it with OR. */
|
* otherwise append it with OR. */
|
||||||
if (!dayIsHoliday) {
|
if (!dayIsHoliday) {
|
||||||
@ -595,6 +614,16 @@ router.get("/holiday/:holiday", function(req, res/*, next*/) {
|
|||||||
|
|
||||||
holiday.date(holiday.date() + direction);
|
holiday.date(holiday.date() + direction);
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
let comparison = "strftime('%Y-%m-%d',taken)='"
|
||||||
|
+ moment(year + "-" + date.month + "-" + date.day, "YYYY-MM-DD").format("YYYY-MM-DD")
|
||||||
|
+ "'";
|
||||||
|
if (!dayIsHoliday) {
|
||||||
|
dayIsHoliday = comparison;
|
||||||
|
} else {
|
||||||
|
dayIsHoliday += " OR " + comparison;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let query = "SELECT photos.*,albums.path AS path FROM photos " +
|
let query = "SELECT photos.*,albums.path AS path FROM photos " +
|
||||||
|
Loading…
x
Reference in New Issue
Block a user