There is a duration extension (Durations · Day.js), but it isn’t available in the widget editor, though perhaps that warrants a feature request in the long run.
You’re right absolutely right though, I was just thinking a quick and dirty couple of conversions and a partial iso string would be one option if the metadata route wasn’t satisfactory from some reason and this had to be done in the yaml.
As rich points out, this is a bit of a kludge and you’ll still have to do a little math and also fake an ISO formatted string. The dayjs library will parse a string that has a date ISO date format and then has many of the standard date display formatting options. So if your duration item is just in seconds it might look something like this:
text: =dayjs("2000-01-01T00:" + Math.trunc(146/60).toString() + ":" + (146 - 60*Math.trunc(146/60)).toString()).format("m:ss")
The “2000-01-01T00:” at the front is just a dummy date to give the string the correct formatting, then you can use the Math.trunc method to get the minutes from your seconds value (in this case a randomly chosen 146 seconds) and conversely extract the seconds after that. The dayjs .format method would then output
Rich’s method is more elegant and you should really only resort to this in one of two cases. In the first case you modify your transform to put the duration into the iso format because then you can skip right to dayjs(item state). If you keep the simple seconds duration string then you would have to substitute into that line above your call to the items object and (as that gets you a string) use
Number to parse it. So the final line gets pretty convoluted:
text: =dayjs("2000-01-01T00:" + Math.trunc(Number(items[props.prefix+items[props.selected].state+props.duration].state)/60).toString() + ":" + (Number(items[props.prefix+items[props.selected].state+props.duration].state) - 60*Math.trunc(Number(items[props.prefix+items[props.selected].state+props.duration].state)/60)).toString()).format("m:ss")
The only other reason to go this way over Rich’s pattern would be if you want a different format in the item’s pattern for some other display elsewhere.