2 return (x
< 10 ? "0" : "") + x
;
5 export function getDate(d
) {
9 zeroPad(d
.getMonth() + 1) +
15 export function getTime(d
) {
17 zeroPad(d
.getHours()) +
19 zeroPad(d
.getMinutes()) +
21 zeroPad(d
.getSeconds())
25 function padDigits(x
) {
26 if (x
< 10) return "0" + x
;
30 export function ppt(t
) {
31 // "Pretty print" an amount of time given in seconds
32 const dayInSeconds
= 60 * 60 * 24;
33 const hourInSeconds
= 60 * 60;
34 const days
= Math
.floor(t
/ dayInSeconds
);
35 const hours
= Math
.floor((t
% dayInSeconds
) / hourInSeconds
);
36 const minutes
= Math
.floor((t
% hourInSeconds
) / 60);
37 const seconds
= Math
.floor(t
% 60);
39 if (days
> 0) res
+= days
+ "d ";
40 if (days
<= 3 && hours
> 0)
41 //NOTE: 3 is arbitrary
43 if (days
== 0 && minutes
> 0)
44 res
+= hours
> 0 ? padDigits(minutes
) + "m " : minutes
+ ":";
45 if (days
== 0 && hours
== 0) {
46 res
+= padDigits(seconds
);
47 if (minutes
== 0) res
+= "s"; //seconds indicator, since this is the only number printed
49 return res
.trim(); //remove potential last space