I have a base table listing visits I have made. Each visit has a duration. I want to summarise the duration in the bottom line. Is there a way to add a custom function to achieve this ?
I have been running my project reporting for some years with dataview. I am trying to convert to bases for reporting. In dv I need two statements to do what I want to do on the same table as shown above:
const total = pages.duration.array().reduce((acc,val) => acc + val, 0);
const d = dv.luxon.Duration.fromMillis(total).rescale().toHuman();
After some testing I found there are at least three misconceptions in my simple approach:
My way of specifying a duration value as “1h 35 m” is not supported by the base duration() function. Duration expects duration(“1h”) + duration(“35m”).
It seems the duration() function does not return a number of miliseconds when used in number(duration(“1h”)). I can fake this by adding the duration to now() and subtracting now() from the result though.
I could find no way to format a duration value like you can do for dates with moments.js. Probably not too big a problem.
It seems you cannot use Javascript arrow functions as the second parameter in a string.replace(regex,arrow_function)
So I came up with the following formula with a regex that works very well, however because I cannot use arrow functions I cannot use this to calculate the number of minutes: