mirror of
https://github.com/vector-im/hydrogen-web.git
synced 2024-12-23 11:35:04 +01:00
format times between root items better
This commit is contained in:
parent
19df43ca3c
commit
560918e373
@ -23,6 +23,7 @@
|
|||||||
min-width: 0;
|
min-width: 0;
|
||||||
min-height: 0;
|
min-height: 0;
|
||||||
overflow-y: auto;
|
overflow-y: auto;
|
||||||
|
padding: 8px;
|
||||||
}
|
}
|
||||||
|
|
||||||
main section h2 {
|
main section h2 {
|
||||||
|
@ -81,7 +81,7 @@ async function loadFile() {
|
|||||||
const fragment = logs.items.reduce((fragment, item, i, items) => {
|
const fragment = logs.items.reduce((fragment, item, i, items) => {
|
||||||
const prevItem = i === 0 ? null : items[i - 1];
|
const prevItem = i === 0 ? null : items[i - 1];
|
||||||
fragment.appendChild(t.section([
|
fragment.appendChild(t.section([
|
||||||
t.h2(prevItem ? `+ ${itemStart(item) - itemEnd(prevItem)} ms` : new Date(itemStart(item)).toString()),
|
t.h2(prevItem ? `+ ${formatTime(itemStart(item) - itemEnd(prevItem))}` : new Date(itemStart(item)).toString()),
|
||||||
t.div({className: "timeline"}, t.ol(itemToNode(item, [i])))
|
t.div({className: "timeline"}, t.ol(itemToNode(item, [i])))
|
||||||
]));
|
]));
|
||||||
return fragment;
|
return fragment;
|
||||||
@ -89,6 +89,20 @@ async function loadFile() {
|
|||||||
main.replaceChildren(fragment);
|
main.replaceChildren(fragment);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function formatTime(ms) {
|
||||||
|
if (ms < 1000) {
|
||||||
|
return `${ms}ms`;
|
||||||
|
} else if (ms < 1000 * 60) {
|
||||||
|
return `${(ms / 1000).toFixed(2)}s`;
|
||||||
|
} else if (ms < 1000 * 60 * 60) {
|
||||||
|
return `${(ms / (1000 * 60)).toFixed(2)}m`;
|
||||||
|
} else if (ms < 1000 * 60 * 60 * 24) {
|
||||||
|
return `${(ms / (1000 * 60 * 60)).toFixed(2)}h`;
|
||||||
|
} else {
|
||||||
|
return `${(ms / (1000 * 60 * 60 * 24)).toFixed(2)}d`;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
function itemChildren(item) { return item.c; }
|
function itemChildren(item) { return item.c; }
|
||||||
function itemStart(item) { return item.s; }
|
function itemStart(item) { return item.s; }
|
||||||
function itemEnd(item) { return item.s + item.d; }
|
function itemEnd(item) { return item.s + item.d; }
|
||||||
|
Loading…
Reference in New Issue
Block a user