When I create an instance of my ClementineRemote binding and create an Item of this channel, I want the elapsed time to be formatted as hours:minutes:seconds.
I tried to use %1$tH:%1$tM:%1$tS or %1$tT as pattern in the stateDescription of the item.
This almost gets the job done; however any track now starts at 1:00:00, since my timezone offset to UTC is one hour.
How can I mitigate this offset problem?
Of course I could use my zone within the .atZone call, but this would break the function for any user not in my zone.
Thanks for the hint. That is what I tried first. Unfortunately, the clock of the system on which my openhabian runs uses UTC zone. Thus, the timestamps I get are the same for both versions:
.atZone(ZoneOffset.UTC)
and
.atZone(ZoneId.systemDefault())
And the epoch object I get out of this is correctly carrying the seconds elapsed.
My problem is, that the formatting in the Item’s stateDescription pattern does apply a zone conversion where none is needed.
You should not use DateTime for duration, but instead Number:Time. DateTime with or without date (i.e. time-only) is used to express a point in time, whereas Number:Time is used to express an amount of time.
See this PR for an example, which also shows how it can be formatted: