Skip to content

Commit 6d3e368

Browse files
author
rs222kn
committed
replaced buildTodaysSchedule with more generic function buildScheduleByDate
1 parent 2220534 commit 6d3e368

File tree

1 file changed

+9
-8
lines changed

1 file changed

+9
-8
lines changed

Diff for: dataParser.js

+9-8
Original file line numberDiff line numberDiff line change
@@ -65,18 +65,19 @@ const buildSchedule = (object, id) => {
6565
};
6666

6767
/**
68-
* [todays room schedule information]
68+
* [gets room schedule information by specific date]
6969
* @param {[object]} object [cherio html object]
70-
* @return {[object]} [only todays room schedule information]
70+
* @param {[string]} id [sechdule id]
71+
* @param {Date} [date=new Date()] [Date object]
72+
* @return {[object]} [only room schedule information for specific date]
7173
*/
72-
const buildTodaysSchedule = (object, id) => {
74+
const buildScheduleByDate = (object, id, date = new Date()) => {
7375
const todaysSchedule = buildSchedule(object, id)
7476
.filter((reservation) => {
7577
const reservationDate = _parseDate(reservation.time.startDate);
76-
const todaysDate = new Date();
77-
return reservationDate.getFullYear() === todaysDate.getFullYear() &&
78-
reservationDate.getMonth() === todaysDate.getMonth() &&
79-
reservationDate.getDate() === todaysDate.getDate();
78+
return reservationDate.getFullYear() === date.getFullYear() &&
79+
reservationDate.getMonth() === date.getMonth() &&
80+
reservationDate.getDate() === date.getDate();
8081
});
8182
return todaysSchedule.length > 0 ? todaysSchedule : null;
8283
};
@@ -88,7 +89,7 @@ const isValidSearch = html => {
8889

8990
module.exports = {
9091
isValidSearch,
91-
buildTodaysSchedule,
92+
buildScheduleByDate,
9293
buildSchedule,
9394
getSearchId,
9495
getTypes,

0 commit comments

Comments
 (0)