Skip to content

Commit

Permalink
Add hours minutes and seconds duration to task list view.
Browse files Browse the repository at this point in the history
  • Loading branch information
flippedbits authored and ikeycode committed Sep 25, 2024
1 parent dd42ffe commit 7126f89
Showing 1 changed file with 24 additions and 7 deletions.
31 changes: 24 additions & 7 deletions static/tasks.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/**
* tasks.js
*
*
* Helpers for the task listing
*/

Expand Down Expand Up @@ -37,16 +37,33 @@ function renderStatus(status)
/**
* Render a task as a list group item
*
* @param {JSON} task The task to be rendered
* @returns
* @param {JSON} task The task to be rendered
* @returns
*/
export function renderTask(task)
{
const started = new Date(task.tsStarted * 1000).toLocaleString();
const ended = task.tsEnded != 0 ? new Date(task.tsEnded * 1000).toLocaleString() : "--";
const status = renderStatus(task.status);
const hasEnded = task.tsEnded != 0;
const start = new Date(task.tsStarted * 1000);
const end = hasEnded ? new Date(task.tsEnded * 1000) : null;
let duration = "--";

if (hasEnded) {
const difference = Math.abs(start.getTime() - end.getTime());
const hours = Math.floor(difference / (1000 * 60 * 60));
const minutes = Math.floor((difference % (1000 * 60 * 60)) / (1000 * 60));
const seconds = Math.floor((difference % (1000 * 60)) / 1000);

duration =
(hours ? hours + "h " : "") +
(minutes ? minutes + "m " : "") +
seconds +
"s";
}

const timestamp = hasEnded
? `Ended @ ${end.toLocaleString()} (${duration} on ${task.allocatedBuilder})`
: `Started @ ${start.toLocaleString()} on ${task.allocatedBuilder}`;

const timestamp = task.tsEnded != 0 ? "Ended @ " + ended : "Started @ " + started;
return `
<div class="list-group-item list-group-item-hoverable">
<div class="row align-items-center">
Expand Down

0 comments on commit 7126f89

Please sign in to comment.