Where $tM is defined as minutes within an hour. I’m guessing this will not work for me, but I do not see any options for elapsed minutes. Anyone have any ideas?
In Java 11 you can use the class java.time.Duration. With the between(Temporal startInclusive, Temporal endExclusive method you can calculate the Duration between to temporals and then the toMinutes() method will give you what you are asking for.
Because ZonedDateTime, which is the internal representation in OH3, implements Temporal you can directly use it with Duration
From this log I got the impression that this is from a rule triggered by and item change event. That is why I suggested some programming hints using Duration. If this is the case, then you have the new state and the old state as DatenTimeType. You can simple convert them to a ZonedDateTime and give that to the duration.
If you want to convert a string directly to a duration, there is no way I can think of. The reason for this is that there is no concept of durations in OH and therefore no way of formatting them.
The only way would be to calculate a duration by using your string to parse a ZonedDateTime from it and use the epoc start as the other ZonedDateTime, calculate the duration like I suggested and format it with the formatting methods of Duration. But this can only be done in a rule or script not with item format descriptions.
You can’t do that with the java datetime formatter, which offers no duration options.
You could display hh:mm using $H:$M but it will go wrong when duration exceeds 24 hours.
But I don’t think any of that works on your String type Item, because the state is not held as a datetime for the formatter to work with…
You’ll want a transformation to do this properly, probably a javascript that calculates epoch seconds and then does maths division to get the time values you want.
Thanks for the pointer @rossko57. I developed a small js transform for this. In case someone looks for something similar in the future, here is what worked for me in openHAB 2.5.11
//Example of raw input string: "1969-12-31T19:04:52-05:00"
//This would be converted to 292 mins
//Example item:
//String historyTime "Total Clean Time [JS(elapsedtime.js):%s]"
(function(i) {
if (i == 'NULL') { return i; }
if (i == '-') { return 'Undefined'; }
//split the string at on colons. The second item is then hours. Parse this string into an Int
var hour = parseInt((i.split(":"))[1]);
//split the string at on colons. The third item is then minutes and the time zone. Split the
//String again at the - and the first item is the minutes. Parse this string into an Int
//Note, if you are in a timezone + from GMT, you'll need to have the second split be on "+" rather than "-"
var min = parseInt(((i.split(":"))[2].split("-"))[0]);
//Convert HH to mins and add together
var total_mins = (hour*60)+min;
//Return as a whole number only (no decimal)
var returnString = total_mins.toFixed(0) + " mins";
return returnString;
})(input)