-
Notifications
You must be signed in to change notification settings - Fork 0
/
helpers.js
38 lines (35 loc) · 975 Bytes
/
helpers.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
/**
* returns the seconds of a day for a given timestamp
* @param {*} date the local date
* @return {[type]} UTC time of the day in seconds
*/
function getUtcTimeOfDayInSec(date) {
return date.getUTCHours() * 3600 +
date.getUTCMinutes() * 60 +
date.getUTCSeconds() +
date.getUTCMilliseconds() / 1000;
}
function diffInDays(date1, date2) {
var t1 = new Date(date1);
var t2 = new Date(date2);
t1.setMilliseconds(0);
t1.setSeconds(0);
t1.setMinutes(0);
t1.setHours(0);
t2.setMilliseconds(0);
t2.setSeconds(0);
t2.setMinutes(0);
t2.setHours(0);
return (t1 - t2) / 1000 / 3600 / 24;
}
/**
* Checki fgiven date is today.
* @param {[type]} d [description]
* @return {Boolean} [description]
*/
function isToday(d){
today = new Date();
if(today.getFullYear() == d.getFullYear() && today.getDate() == d.getDate() && today.getMonth() == d.getMonth())
return true;
return false;
}