blob: 10c425072a1cacf83a88117eddaf2803f7211ca6 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
|
// s: DD-MM-YYYY, return: Date
function stringToDate(s) {
const date = s.split("-");
return new Date(`${date[2].padStart(4, "0")}-${date[1].padStart(2, "0")}-${date[0].padStart(2, "0")}`);
}
const isBetweenDates = (date, date1, date2) => {
date = approxDate(date);
date1 = approxDate(date1);
date2 = approxDate(date2);
return ((date.getTime() >= date1.getTime())
&& (date.getTime() <= date2.getTime()));
};
function approxDate(d)
{
return new Date(`${d.getFullYear()}-${(d.getMonth() + 1).toString().padStart(2, "0")}-${d.getDate().toString().padStart(2, "0")}`);
}
module.exports = {
fromString: stringToDate,
between: isBetweenDates
}
|