dashboard frontend: consume rfc3339 timestamps from the api
This commit is contained in:
parent
bac2c0a65e
commit
cafef519a9
5 changed files with 46 additions and 33 deletions
|
|
@ -19,9 +19,18 @@ export function paintAtomic(liveRoot, build) {
|
|||
liveRoot.replaceChildren(buf);
|
||||
}
|
||||
|
||||
// Relative age of a unix timestamp, coarsened to one unit ("5m ago").
|
||||
export function fmtAgo(unixSecs) {
|
||||
const ageSec = Math.max(0, Math.floor(Date.now() / 1000 - unixSecs));
|
||||
// Epoch seconds from an API timestamp. The hive-c0re dashboard API
|
||||
// ships timestamps as RFC 3339 strings; a few feeds (rebuild queue,
|
||||
// meta inputs, turn stats) still carry unix-second numbers, so
|
||||
// numbers pass through unchanged.
|
||||
export function epochSec(ts) {
|
||||
return typeof ts === 'number' ? ts : Math.floor(Date.parse(ts) / 1000);
|
||||
}
|
||||
|
||||
// Relative age of a timestamp (RFC 3339 string or unix seconds),
|
||||
// coarsened to one unit ("5m ago").
|
||||
export function fmtAgo(ts) {
|
||||
const ageSec = Math.max(0, Math.floor(Date.now() / 1000 - epochSec(ts)));
|
||||
if (ageSec < 60) return ageSec + 's ago';
|
||||
if (ageSec < 3600) return Math.floor(ageSec / 60) + 'm ago';
|
||||
if (ageSec < 86400) return Math.floor(ageSec / 3600) + 'h ago';
|
||||
|
|
|
|||
Loading…
Reference in a new issue