projects
/
vchess.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Merge pull request #18 from prendradjaja/fix-broken-variant-links
[vchess.git]
/
client
/
src
/
utils
/
datetime.js
diff --git
a/client/src/utils/datetime.js
b/client/src/utils/datetime.js
index
49b70ca
..
5f75f6d
100644
(file)
--- a/
client/src/utils/datetime.js
+++ b/
client/src/utils/datetime.js
@@
-1,47
+1,51
@@
-function zeroPad(x)
-{
- return (x<10 ? "0" : "") + x;
+function zeroPad(x) {
+ return (x < 10 ? "0" : "") + x;
}
}
-export function getDate(d)
-{
- return d.getFullYear() + '-' + zeroPad(d.getMonth()+1) + '-' + zeroPad(d.getDate());
+export function getDate(d) {
+ return (
+ d.getFullYear() +
+ "-" +
+ zeroPad(d.getMonth() + 1) +
+ "-" +
+ zeroPad(d.getDate())
+ );
}
}
-export function getTime(d)
-{
- return zeroPad(d.getHours()) + ":" + zeroPad(d.getMinutes()) + ":" +
- zeroPad(d.getSeconds());
+export function getTime(d) {
+ return (
+ zeroPad(d.getHours()) +
+ ":" +
+ zeroPad(d.getMinutes()) +
+ ":" +
+ zeroPad(d.getSeconds())
+ );
}
}
-function padDigits(x)
-{
- if (x < 10)
- return "0" + x;
+function padDigits(x) {
+ if (x < 10) return "0" + x;
return x;
}
return x;
}
-export function ppt(t)
-{
+export function ppt(t) {
// "Pretty print" an amount of time given in seconds
const dayInSeconds = 60 * 60 * 24;
const hourInSeconds = 60 * 60;
// "Pretty print" an amount of time given in seconds
const dayInSeconds = 60 * 60 * 24;
const hourInSeconds = 60 * 60;
-
cons
t days = Math.floor(t / dayInSeconds);
- const hours = Math.floor(
t%dayInSeconds
/ hourInSeconds);
- const minutes = Math.floor(
t%hourInSeconds
/ 60);
+
le
t days = Math.floor(t / dayInSeconds);
+ const hours = Math.floor(
(t % dayInSeconds)
/ hourInSeconds);
+ const minutes = Math.floor(
(t % hourInSeconds)
/ 60);
const seconds = Math.floor(t % 60);
let res = "";
const seconds = Math.floor(t % 60);
let res = "";
- if (days > 0)
-
res += days + "d "
;
- if (days
<= 3 && hours > 0) //NOTE: 3 is arbitrary
-
res += hours + "h ";
+ // NOTE: 3 days limit is rather arbitrary
+
if (days >= 3 && hours >= 12) days++
;
+ if (days
> 0) res += days + "d ";
+
if (days < 3 && hours > 0)
res += hours + "h ";
if (days == 0 && minutes > 0)
if (days == 0 && minutes > 0)
- res += (hours > 0 ? padDigits(minutes) + "m " : minutes + ":");
- if (days == 0 && hours == 0)
- {
+ res += hours > 0 ? padDigits(minutes) + "m " : minutes + ":";
+ if (days == 0 && hours == 0) {
res += padDigits(seconds);
res += padDigits(seconds);
- if (minutes == 0)
- res += "s"; //seconds indicator, since this is the only number printed
+ // Seconds indicator, since this is the only number printed:
+ if (minutes == 0) res += "s";
}
return res.trim(); //remove potential last space
}
}
return res.trim(); //remove potential last space
}