summaryrefslogtreecommitdiff
path: root/src/client/app/common/scripts
diff options
context:
space:
mode:
authorMeiMei <30769358+mei23@users.noreply.github.com>2018-12-16 07:06:43 +0900
committersyuilo <Syuilotan@yahoo.co.jp>2018-12-16 07:06:43 +0900
commit2faa58928fb4fc772002aa40df0fbddee3d3457b (patch)
tree5cfcd826f2b2f208e90032ea9657797da6879583 /src/client/app/common/scripts
parentReturn 404 for invalid Object ID (#3627) (diff)
downloadsharkey-2faa58928fb4fc772002aa40df0fbddee3d3457b.tar.gz
sharkey-2faa58928fb4fc772002aa40df0fbddee3d3457b.tar.bz2
sharkey-2faa58928fb4fc772002aa40df0fbddee3d3457b.zip
Format uptimes (#3629)
* Format uptime * 逆だわ * ザ * 1個多い * Fix comment
Diffstat (limited to 'src/client/app/common/scripts')
-rw-r--r--src/client/app/common/scripts/format-uptime.ts25
1 files changed, 25 insertions, 0 deletions
diff --git a/src/client/app/common/scripts/format-uptime.ts b/src/client/app/common/scripts/format-uptime.ts
new file mode 100644
index 0000000000..6a2718f640
--- /dev/null
+++ b/src/client/app/common/scripts/format-uptime.ts
@@ -0,0 +1,25 @@
+
+/**
+ * Format like the uptime command
+ */
+export default function(sec) {
+ if (!sec) return sec;
+
+ const day = Math.floor(sec / 86400);
+ const tod = sec % 86400;
+
+ // Days part in string: 2 days, 1 day, null
+ const d = day >= 2 ? `${day} days` : day >= 1 ? `${day} day` : null;
+
+ // Time part in string: 1 sec, 1 min, 1:01
+ const t
+ = tod < 60 ? `${Math.floor(tod)} sec`
+ : tod < 3600 ? `${Math.floor(tod / 60)} min`
+ : `${Math.floor(tod / 60 / 60)}:${Math.floor((tod / 60) % 60).toString().padStart(2, "0")}`;
+
+ let str = '';
+ if (d) str += `${d}, `;
+ str += t;
+
+ return str;
+}