Worldclock in HAB-Panel oder Display Time from other TimeZone in Basic-UI

Hi,
I was looking for a way to display at least the current Time from another Timezone in my Basic-UI. I tried to get it to work wit the NTP-Bindung.

My Things-File

ntp:ntp:local "Berlin" [hostname="192.168.6.1", refreshInterval=60, refreshNtp=30, locale="", timeZone="Europe/Berlin" ]
ntp:ntp:japan "Tokyo" [hostname="192.168.6.1", refreshInterval=60, refreshNtp=30, locale="", timeZone="Asia/Tokyo" ]
ntp:ntp:uspacific "US-Pacific" [hostname="192.168.6.1", refreshInterval=60, refreshNtp=30, locale="", timeZone="America/Denver" ]

My Item-File

DateTime CurrentDate_DE "Heutiges Datum [%1$tH:%1$tM, %1$td.%1$tm.%1$tY]" <calendar> { channel="ntp:ntp:local:dateTime" }
DateTime CurrentDate_JP "Heutiges Datum [%1$tH:%1$tM, %1$td.%1$tm.%1$tY]" <calendar> { channel="ntp:ntp:japan:dateTime" }
DateTime CurrentDate_US_Pacific "Heutiges Datum [%1$tH:%1$tM, %1$td.%1$tm.%1$tY]" <calendar> { channel="ntp:ntp:us-pacific:dateTime" }

And in the Logs the Time was set correctly to the specific Timezone-Item:

CurrentDate_DE changed from 2020-08-14T21:34:26.809+0200 to 2020-08-14T21:35:26.810+0200
CurrentDate_US_Pacific changed from 2020-08-14T13:34:26.815-0600 to 2020-08-14T13:35:26.815-0600
CurrentDate_JP changed from 2020-08-15T04:34:26.815+0900 to 2020-08-15T04:35:26.815+0900

But in the Sitemap it’s always my local date and time.

Does anybody has some hint for me where I’ve made a mistake?

Thanks in advance!

Bopp

Can you show your sitemap configuration too?

You have to remember that all those Item state values are the same time, just with different zones.

[%1$tH:%1$tM, %1$td.%1$tm.%1$tY]
the java string formatter will always assume your local timezone and display your data converted for that local timezone.

I don’t think it is possible to request [%1$xxx] style formatting in any other timezone. I think you would have to use a transformation, probably JS javascript.

EDIT - This is quite an interesting puzzle really :crazy_face:
I loaded a test DateTime Item with
2020-08-14T13:35:26.815-0600
and using REST API it’s easy enough to confirm that’s exactly how it is held in the Item state, no conversion takes place during update.

If you try sitemap -
Text item=testDate label="test [%s]"
you might expect the %s to give you the “raw string”. But it doesn’t, I will see
2020-08-14T20:35:26.815+0100
it’s auto converted to my own +1 timezone.

This blows up the idea of using javascript transform, if we have a test.js like

(function(inputData) {
    var out = inputData ;      // allow anything to pass through
    return out ;      // return a string
})(input)

and use sitemap
Text item=testDate label="test [JS(test.js):%s]"
we get the same unwanted result
2020-08-14T20:35:26.815+0100
which means OH has auto-converted the datetime to my local zone before passing to my javascript. This means there is no way in the transform to find out what the time stored in the Item state actually was.

Of course you can write a transform to take a DateTime state and do its own maths like subtracting 6 hours before passing to display, but this is not the same as reading the stored real datetime.

I can’t think of a clean way to accomplish this, without using String Items and/or proxy Items and rules.

Hi Rossko57 and thanks for your reply and trying to find a solution!!
It’s really puzzeling and I think now as well, that I have to do it via a String and some math…
Too bad, as the item has already stored the correct time as the log let’s expect you.

But once again, thanks for your time and effort! Really appreciated!

@hafniumzinc
I tried it with different ways…

Text	item=CurrentDate_DE label="Jetzt ist es [%1$tH:%1$tM, %1$td.%1$tm.%1$tY]" icon="time"
or
Text	item=CurrentDate_DE label="Jetzt ist es [%s]" icon="time"

and other formatings as I questioned myself really badly… :roll_eyes:

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