How to correctly format datetimeoffset in item?

  • Platform information:
    • Hardware: Rasperry Pi
    • OS: raspbian Bullseye
    • Java Runtime Environment: openjdk version “11.0.13” 2021-10-19 LTS
    • openHAB version: 3.3.0.M2 - Milestone Build
  • Automower binding.

I would like to correctly display a time for the next automatic run of the automower.
I have an item with the planner-next-start channel with a datetime type (Automower - Bindings | openHAB).
The unformatted time shows as a (I think, Items | openHAB) RFC 822 timezone, like so: 2022-04-04T12:00:00.000+0200
This is correct. The schedule is a daily one from 10:00 to 16:00.
Under “Regional settings” I have set my language and country/location.
However if I define a state description under the items “metadata” (%1$ta %1$td-%1$tm-%1$tY %1$tk:%1$tM) the output wil be Mon 04-04-2022 12:00.

I would have expected it to be Mon 04-04-2022 10:00, maybe even Ma 04-04-2022 10:00 as per my locale.

In the class formatter page (Formatter (Java SE 11 & JDK 11 )) I have found nothing to suggest another syntax.

Can someone point out to me why this is as it is? How does one get a correct formatted date time format?

I wouldn’t.

There is invisible jiggery-pokery going on when Datetime Items are presented for display; regardless of the stored state zone, they get pre-converted to the ‘local’ zone for display.

It is in fact very difficult to get datetimes displayed in any other zone.

And that is the whole point: why does the internal jiggery-pokery stuff disregard the UTC + 2 hour offset ( I’m on central european summer time and openhab “knows” that)?

Things of relevance here -
What is the raw Item state (see events.log)?
What is your Jave timezone set to? (I cannot remember if time display works off of that or off of openHABs locale - they may be set to different zones)
Whatdo you actually see - you haven’t said yet?

By design, the framework presents all datetimes in the viewers locale. That’s supposed to be for most user’s convenience.

Similar discussion (its from OH2 and sitemaps but applies the same in OH3 I believe)

The raw item state is:
2022-04-07 23:17:19.343 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item 'Automower_NextAutoStart' changed from NULL to 2022-04-08T12:00:00.000+0200

Output of sudo timedatectl:

              Local time: Thu 2022-04-07 23:26:50 CEST
           Universal time: Thu 2022-04-07 21:26:50 UTC
                 RTC time: n/a
                Time zone: Europe/Amsterdam (CEST, +0200)
System clock synchronized: yes
              NTP service: active
          RTC in local TZ: no

I’ve set the java timezone in /etc/default/openhab like so:
EXTRA_JAVA_OPTS="-Xms192m -Xmx320m -XX:+ExitOnOutOfMemoryError -Duser.timezone=Europe/Amsterdam"
I’ve read that the jre is supposed to use the system TZ, but that it can be overridden in the above manner. It does not make a difference, however. I’ve restarted openhab (sudo systemctl restart openhab) and when this did not seem to make a difference, did a reboot.

In karaf I did an env|grep timezone. It gave Europe / Amsterdam back. Is this JAVA TZ or system TZ?

The item in mainUI (administrator settings section, formatted) shows: Fri 08-04-2022 12:00.
This is not right, because the mo-sun schedule for the automower starts at 10:00.

I’m going to remove the extra java option, because it is not set standard.

That is exactly correct. Your Item is loaded with 12:00 (in local +2 time), and gets displayed as 12:00 (in local +2 time)… All working as it should be.

Obviously not what you expected though, so let’s guess Husqvarna is not sending what you expect, 10:00 with zero timezone perhaps? (10:00 +0 being the same instant as 12:00 +2)
Are there any account settings for that? Or at the actual mower?

See also

Thank you for the link:

Looks I am not the only one to run into this problem. Alas, no solution to the question yet.