forked from nodejs/nodejs.org
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbetweenDate.js
More file actions
27 lines (24 loc) · 866 Bytes
/
Copy pathbetweenDate.js
File metadata and controls
27 lines (24 loc) · 866 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
'use strict';
module.exports = (startDate, endDate) => {
const parsedStartDate = new Date(startDate);
const parsedEndDate = new Date(endDate);
const now = Date.now();
if (!(parsedStartDate instanceof Date && isFinite(parsedStartDate))) {
// If date is invalid (but not undefined) log error for debugging
if (startDate && process.env.NODE_ENV !== 'test') {
console.error(
'[handlebars] betweenDate - Invalid start date:',
startDate
);
}
return false;
}
if (!(parsedEndDate instanceof Date && isFinite(parsedEndDate))) {
// If date is invalid (but not undefined) log error for debugging
if (endDate && process.env.NODE_ENV !== 'test') {
console.error('[handlebars] betweenDate - Invalid end date:', endDate);
}
return false;
}
return parsedStartDate < now && now < parsedEndDate;
};