-
Notifications
You must be signed in to change notification settings - Fork 2
/
holiday.js
41 lines (27 loc) · 820 Bytes
/
holiday.js
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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
module.exports = function() {
return {
/*
* Returns a Date object that represents Thanksgiving (US)
* for this year. The fourth Thursday in November.
*/
thanksgiving: function() {
var d = new Date();
d.setDate(1);
d.setMonth(10);
while (d.getDay() != 4) {
d.setDate(d.getDate()+1);
}
d.setDate(d.getDate()+21);
return d;
},
/*
* This function return true during the Christmas season.
* I define that as Thanksgiving through the end of December.
*/
isChristmasSeason: function() {
var monthToday = (new Date()).getMonth();
var dateToday = (new Date()).getDate();
return (monthToday == 11 || (monthToday == 10 && dateToday >= this.thanksgiving().getDate()));
}
};
};