Create a table of tasks with defined start and end time

What I’m trying to do

I want to track my work hours for each workday individually. I keep a work log file where I define some tasks with [start:: ] and [end:: ] parameters. I have searched the forum for ideas and I combined them into this code

TABLE WITHOUT ID 
  task.text as "Task",
  task.start as "Start time", 
  task.end as "End time",
  sum(date(task.end) - date(task.start)) as "Elapsed time"
WHERE file = this.file 
FLATTEN file.tasks as task
WHERE task.start != null
WHERE task.end != null 

Q: How do I sum the entries in the last column?

Things I have tried

Below the table, I have the following line but it tries adding up the elapsed time for the tasks with undefined start and/or end time.

Total duration: `=sum( map(this.file.tasks, (task) => date(task.end) - date(task.start) ) )`

I modified the example here based on dataviewjs like this

// Query
const result = await dv.query(`
  TABLE WITHOUT ID 
  sum(date(task.end) - date(task.start)) as Elapsed 
  WHERE file = this.file 
  FLATTEN file.tasks as task
  WHERE task.start != null
  WHERE task.end != null
`)

// Summation

if ( result.successful ) {
  const values = result.value.values
  console.log("Values:")
  console.log(values[0].values)

  dv.paragraph("Values: " + values)

}

But the output looks like this:
Values: PT5M,PT29M,PT5M,PT13M

I tried adding GROUP by Elapsed to the query but the output is empty.

I suppose I need something like
let total = sum(number(values))
but how do I extract the values of values?

My background is in C and Python, but I have next to no experience with JS.

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.