forked from stravid/sleepyti.me
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathsleepytime.js
33 lines (28 loc) · 897 Bytes
/
sleepytime.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
var FOURTEEN_MIN = 1000 * 60 * 14,
NINETY_MIN = 1000 * 60 * 90;
function formatTime (date) {
var hours = date.getHours(),
minutes = date.getMinutes();
return hours + ":" + (minutes < 10 ? "0" + minutes : minutes);
}
function wakeupTimes (bedtime) {
bedtime = +bedtime + FOURTEEN_MIN;
return [0, 0, 0, 0, 0, 0].map(
function(_, i){
return new Date(bedtime + NINETY_MIN * (i + 1));
}
);
}
function updateWakeupTimes(wakeupTimes) {
var timeNodes = document.getElementById("results").children;
for (var time in wakeupTimes) {
timeNodes[time].textContent = formatTime(wakeupTimes[time]);
}
}
document.getElementById("sleepNow").addEventListener("click", function(){
updateWakeupTimes(wakeupTimes(new Date()));
document.body.className = "sleeping";
}, false);
document.getElementById("back").addEventListener("click", function(){
document.body.className = "home";
}, false);