From 7486f9dd36f62870f0c4632fd51ed5feaaaf98b4 Mon Sep 17 00:00:00 2001 From: Veejer <112398263+Veejer@users.noreply.github.com> Date: Sat, 17 Sep 2022 11:35:01 -0400 Subject: [PATCH 1/3] Update flex-table-card.js --- flex-table-card.js | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/flex-table-card.js b/flex-table-card.js index 1e4b361..cd681ff 100644 --- a/flex-table-card.js +++ b/flex-table-card.js @@ -73,7 +73,24 @@ class CellFormatters { const minr = Math.floor(minutes); return (!isNaN(hours) && !isNaN(minr)) ? hours + " hours " + minr + " minutes" : null; } - + duration(data) { + let h = (data > 3600) ? Math.floor(data / 3600).toString() + ':' : ''; + let m = (data > 60) ? Math.floor((data % 3600) / 60).toString().padStart(2, 0) + ':' : ''; + let s = (data > 0) ? Math.floor((data % 3600) % 60).toString() : ''; + if (m) s = s.padStart(2, 0); + return h + m + s; + } + duration_h(data) { + let d = (data > 86400) ? Math.floor(data / 86400).toString() + 'd ' : ''; + let h = (data > 3600) ? Math.floor((data % 86400) / 3600) : '' + h = (d) ? h.toString().padStart(2,0) + ':' : ((h) ? h.toString() + ':' : ''); + + let m = (data > 60) ? Math.floor((data % 3600) / 60).toString().padStart(2, 0) + ':' : ''; + let s = (data > 0) ? Math.floor((data % 3600) % 60).toString() : ''; + if (m) s = s.padStart(2, 0); + return d + h + m + s; + } + } From 3a125a442eb3e09bfb3a3685b5b361f715736f3d Mon Sep 17 00:00:00 2001 From: Veejer <112398263+Veejer@users.noreply.github.com> Date: Sat, 17 Sep 2022 11:38:01 -0400 Subject: [PATCH 2/3] Added new standard formatters .Added duration and duration_h as standard formatters --- flex-table-card.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/flex-table-card.js b/flex-table-card.js index cd681ff..14d8fe1 100644 --- a/flex-table-card.js +++ b/flex-table-card.js @@ -73,7 +73,7 @@ class CellFormatters { const minr = Math.floor(minutes); return (!isNaN(hours) && !isNaN(minr)) ? hours + " hours " + minr + " minutes" : null; } - duration(data) { + duration(data) { let h = (data > 3600) ? Math.floor(data / 3600).toString() + ':' : ''; let m = (data > 60) ? Math.floor((data % 3600) / 60).toString().padStart(2, 0) + ':' : ''; let s = (data > 0) ? Math.floor((data % 3600) % 60).toString() : ''; From 7dc1d767e5c9e43bb09295ab58a2979b29d17812 Mon Sep 17 00:00:00 2001 From: Veejer <112398263+Veejer@users.noreply.github.com> Date: Sun, 18 Sep 2022 09:12:52 -0400 Subject: [PATCH 3/3] Update config-ref.md --- docs/config-ref.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/docs/config-ref.md b/docs/config-ref.md index f0f9b1a..97d2df5 100644 --- a/docs/config-ref.md +++ b/docs/config-ref.md @@ -81,6 +81,8 @@ Apart from that `modify` is very powerful, see [advanced cell formatting](https: * `hours_passed` * `hours_mins_passed` * `number` +* `duration` +* `duration_h` Feel free to contribute, just share your best `modify` line to allow others to use them, too.