Open OnkelMato opened 2 years ago
Not that easy to find, dates are not my favorite objects to work with in Java. But i did some digging and have found some key aspects that might relate to this issue. Maybe @soenkekueper has some time to spare, maybe he also has some thoughts on this.
Notes to self: Here is a ZonedDateTime created with system timezone, would have expected openHAB TimeZone https://github.com/openhab/openhab-addons/blob/099dc692c87405a2e6d59e56c55cbc9d68ce2afb/bundles/org.openhab.binding.deutschebahn/src/main/java/org/openhab/binding/deutschebahn/internal/EventAttribute.java#L300
Here is a Date
created that is used all over de binding. If i understand correct, Date is like instant a point in time UTC and independent from the system locale.
https://github.com/openhab/openhab-addons/blob/099dc692c87405a2e6d59e56c55cbc9d68ce2afb/bundles/org.openhab.binding.deutschebahn/src/main/java/org/openhab/binding/deutschebahn/internal/DeutscheBahnHandlerFactory.java#L53
These to SimpleDateFormatters
are used to format the Date
for API-calls. I expect these to take the system timezone into account.
https://github.com/openhab/openhab-addons/blob/099dc692c87405a2e6d59e56c55cbc9d68ce2afb/bundles/org.openhab.binding.deutschebahn/src/main/java/org/openhab/binding/deutschebahn/internal/timetable/TimetablesV1Impl.java#L78-L79
Forcing the timezone in the constructor might also fix this.
// unfortunately the SimpleDateFormat does not have a constructor with timezone, set it in TimetablesV1Impl constructor
DATE_FORMAT.setTimeZone(TimeZone.getTimeZone("Europ/Berlin"));
HOUR_FORMAT.setTimeZone(TimeZone.getTimeZone("Europ/Berlin"));
Expected Behavior
The Deutsche Bahn widget should show the next 4 upcoming trains.
Current Behavior
The thing, model, and items were created as described in the documentation. After adding the widget, it shows the next/last trains from the previous hour. At my favourite station are exactly 4 trains per hour, so it shows exactly the trains from the last 60 minutes.
Possible Solution
Make the binding aware of timezones and query the REST service with local time, not UTC.
Steps to Reproduce (for Bugs)
1 Install a Ubuntu-based system with NTP enabled and set the timezone to Europe/Berlin. 2 UTC is one hour behind the local time 3 Create widget according to documentation 4 Widget shows wrong training (next four trains one hour ago)
To verify the bug
5 Turn off NTP
timedatectl set-ntp false
6 Set time to "local time"timedatectl set-time 14:33
Open UI and verify, it shows the correct next four trains.
Context
Your Environment