-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
76 lines (64 loc) · 1.48 KB
/
index.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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
const shortTime = (timestamp) => {
let duration = [];
const hrs = Math.floor(timestamp / 3600);
if (hrs > 0) {
duration.push(hrs);
timestamp = timestamp % 3600;
}
const min = Math.floor(timestamp / 60);
if (min > 0) {
if (min < 10 && hrs > 0) {
duration.push("0" + min);
} else {
duration.push(min);
}
} else {
duration.push("00");
}
const sec = Math.floor(timestamp % 60);
if (sec > 0) {
if (sec < 10) {
duration.push("0" + sec);
} else {
duration.push(sec);
}
} else {
duration.push("00");
}
duration = duration.join(":");
return duration;
};
const longTime = (timestamp) => {
let duration = [];
const hrs = Math.floor(timestamp / 3600);
if (hrs === 0) {
duration.push("00");
} else if (hrs > 0 && hrs < 10) {
duration.push("0" + hrs);
} else {
duration.push(hrs);
}
timestamp = timestamp % 3600;
const mins = Math.floor(timestamp / 60);
if (mins === 0) {
duration.push("00");
} else if (mins > 0 && mins < 10) {
duration.push("0" + mins);
} else {
duration.push(mins);
}
const secs = Math.floor(timestamp % 60);
if (secs === 0) {
duration.push("00");
} else if (secs > 0 && secs < 10) {
duration.push("0" + secs);
} else {
duration.push(secs);
}
duration = duration.join(":");
return duration;
};
module.exports = {
shortTime,
longTime
};