-
Notifications
You must be signed in to change notification settings - Fork 1
/
timer.js
52 lines (39 loc) · 1.11 KB
/
timer.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
42
43
44
45
46
47
48
49
50
51
/* file: timer.js
* date: 5/18/14
* author: David Weinman
*
* description: functions
* which together can model
* the functionality of a
* kitchen timer.
*/
function checkTime(i) {
if (i < 0) {
i = i * (-1);
};
return i;
}
function checkTens(i) {
if (i < 10) {
i = "0" + i;
};
return i;
}
function getTimeSince(starting_time) {
var now = new Date();
var h = now.getHours() - starting_time.getHours();
var m = now.getMinutes() - starting_time.getMinutes();
var s = (starting_time.getSeconds() - now.getSeconds()) % 60;
return checkTens( checkTime(h) ) + ":" + checkTens( checkTime(m) ) + ":" + checkTens( checkTime(s) );
}
function hasPassed(starting_time, duration) {
var curTime = new Date();
var ending_times = duration.split(":");
var ending_hrs = ending_times[0] * 1;
var ending_min = ending_times[1] * 1;
var ending_sec = ending_times[2] * 1;
if (((curTime.getHours() - starting_time.getHours()) >= ending_hrs) && ((curTime.getMinutes() - starting_time.getMinutes()) >= ending_min) && ((curTime.getSeconds() - starting_time.getSeconds()) >= ending_sec)) {
return true;
}
return false;
}