-
Notifications
You must be signed in to change notification settings - Fork 0
/
TimeUtils.gs
57 lines (49 loc) · 1.07 KB
/
TimeUtils.gs
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
52
53
54
55
56
57
function getTimestamp() {
var milliseconds = new Date().getTime();
return Math.floor(milliseconds / 1000);
}
function secondsToTime(secs) {
var hours = Math.floor(secs / (60 * 60));
var divisor_for_minutes = secs % (60 * 60);
var minutes = Math.floor(divisor_for_minutes / 60);
var divisor_for_seconds = divisor_for_minutes % 60;
var seconds = Math.ceil(divisor_for_seconds);
var obj = {
"h": hours,
"m": minutes,
"s": seconds
};
return obj;
}
function timeString(timeDiff) {
var due;
var time = secondsToTime(timeDiff);
if(timeDiff <= 60) {
due = '1 min';
}
else if(timeDiff < 3600) {
if(time.m == 1) {
due = '1 min';
}
else {
due = time.m + ' mins';
}
}
else if(time.h == 1){
if(time.m == 1) {
due = time.h + ' hour ' + time.m + ' min';
}
else {
due = time.h + ' hour ' + time.m + ' mins';
}
}
else {
if(time.m == 1) {
due = time.h + ' hours ' + time.m + ' min';
}
else {
due = time.h + ' hours ' + time.m + ' mins';
}
}
return due;
}