How can I use correct daylight saving time in rule processing?

  • Platform information:
    • Hardware: Raspi 4B, 4GB, 128 GB
    • OS: raspbian
    • Java Runtime Environment: openjdk version “1.8.0_222”
      OpenJDK Runtime Environment (Zulu8.40.0.178-CA-linux_aarch32hf) (build 1.8.0_222-b178)
      OpenJDK Client VM (Zulu8.40.0.178-CA-linux_aarch32hf) (build 25.222-b178, mixed mode, Evaluation)
    • openHAB version:
  • Issue of the topic: DateTime item is obviously mapped in sitemap to display correct daylight saving time. But if I use the same item in rule processing to concat two time strings (sun rise and sun set) I get the wrong time output.
  • Please post configurations (if applicable):
    • Items: DateTime Sonnenaufgang_Zeit “Sonnenaufgang [%1$tH:%1$tM]” (gSonne) {channel=“astro:sun:local:rise#start”}
    • Sitemap: Frame label=“Sonne und Mond” {
      Group item=SummarySun label=“Sonne [%s]” icon=“sunrise” {
      Text item=Sonnenaufgang_Zeit label=“Sonnenaufgang” icon=“sunrise”
      Text item=Sonnenuntergang_Zeit label=“Sonnenuntergang” icon=“sunset”
    • Rules: var String auf = Sonnenaufgang_Zeit.state.format("%1$tH:%1$tM").toString
      var String unter = Sonnenuntergang_Zeit.state.format("%1$tH:%1$tM").toString
      logWarn(“sunmoon.rules”,"++++++Ausgabe "+auf)
      SummarySun.postUpdate(auf + " - " + unter)
    • Log: 2020-03-21 14:07:29.464 [WARN ] [smarthome.model.script.sunmoon.rules] - ++++++Ausgabe 04:56

Sitemap displays 05:56 for the item Sonnenaufgang_Zeit which is correct
The item created by the rule (SummarySun) shows 04:56 which is wrong

How can I fix this problem?

regards, Gerald

If you inspect the complete DateTime state, there should be a time zone element which you are not currently taking into account.

The easiest way would be to convert the Item state to a datetime variable, and use zoned methods. See the excellent thread on datetime conversions. There is quite a lot to this stuff.

Thanks for the hint. Is solved it using conversion to Epoch and back to DateTime. Strange that items use a differnt class system than rules for date/time.

var Number AufEpoch = (Sonnenaufgang_Zeit.state as DateTimeType).calendar.timeInMillis

var DateTimeType MyDateTimeTypeFromEpochAuf = new DateTimeType(new DateTime(AufEpoch).toString)

var Number UnterEpoch = (Sonnenuntergang_Zeit.state as DateTimeType).calendar.timeInMillis
var DateTimeType MyDateTimeTypeFromEpochUnter = new DateTimeType(new DateTime(UnterEpoch).toString)

var String auf = (MyDateTimeTypeFromEpochAuf as DateTimeType).format("%1$tH:%1$tM").toString
var String unter = (MyDateTimeTypeFromEpochUnter as DateTimeType).format("%1$tH:%1$tM").toString