-
-
Notifications
You must be signed in to change notification settings - Fork 31
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
toToday doesn't work over DST changes when created from DT Item State #306
Comments
Given that for all other ISO partings the time zone is added, I am in favour of solution 1:
Yes, this is a typo. Not sure why I should have reference such an ISO, so it should be ISO 8601. The only question remaining is, what’s the difference between |
From what I can tell, nothing. Both resolve to I'm not sure why they have the method. As far as I can tell they are the same. See https://js-joda.github.io/js-joda/file/packages/core/src/ZoneIdFactory.js.html#errorLines=199 and https://js-joda.github.io/js-joda/file/packages/core/src/ZoneIdFactory.js.html#errorLines=34,36 I'll submit a PR later today with option 1. Should I fix the typo here or create a separate PR? |
I wonder how I came to the idea to use
👍 |
…et (#307) Fixes #306. During DST changes, any ISO8601 String or Item or DateTimeType or Java ZonedDateTime that is parsed by `time.toZDT()` lack the ZoneId. However, it is this ZoneId which tells Joda when DST changes occur so when `toToday()` is called, the time is not adjusted to account for DST. This defaults to the system timezone if no timezone is explicitely set. ---- Also-by: Florian Hotze <[email protected]> Signed-off-by: Richard Koshak <[email protected]>
Expected Behavior
A ZonedDateTime of HH:MM:SS retains the same HH:MM:SS after DST changes when calling
toToday
on an Item's state.Current Behavior
Given
time.toZDT(i.state).toToday()
, if the state of the Item is before the DST change, the result of the call totoToday
retains the timezone from before the DST change resulting in a time that is one hour off.For example, our DST change was on the 5th of this month. Given the following code:
The result is:
Note that this is only a problem when converting the Item's state to a ZonedDateTime first. If creating the ZonedDateTime myself it works as expected. Given
The result is:
This works, which is probably why this bug has been missed until now.
The difference seems to be the
[SYSTEM]
. I notice that after parsing the state of the DateTime Item the ZDT only has the offset, and doesn't have the zone ID. I strongly suspect this is the root of the problem. Without the zone ID, Joda doesn't know that DST has occurred so it leaves the TZ alone.Possible Solution(s)
I'm not sure of the full implication but the first thing I would try (and will try when I get a chance) is to add the zone ID when parsing the full ISO8601 String we get back from the DateTime Item, changing line 99 of time.js from
(is that a typo? 8160 is a standard having to do with yarn) to
That should give us the ZoneID which will allow
toToday()
to work after parsing the ISO string from the DateTime Item.Alternatively, we could modify
Item
to add "[SYSTEM]" to the ISO8601 String we get from thethis.rawState.toString()
for DateTimeTypes. Kind of the opposite side of the coin from_toOpenhabString()
.I've verified appending "[SYSTEM]" to the ISO8601 string to work.
The least intrusive approach would be to just append the ZoneId to the ZDT inside
toToday()
. But it doesn't feel right to muck around with the ZoneID inside a ZDT that doesn't have a ZoneID. It would be better to append the ZoneID before we get to this point so that there is still the option to have a ZDT without a ZDT and have toToday work.I've also confirmed this to work.
I'll gladly file a PR but would like some advice as to which approach is the preferred. There might be side effects which I do not know.
My inclination would be to fix this as close to the source as possible so that would be either in the ISO8601 parser or the Item.
Steps to Reproduce (for Bugs)
See above
Context
This was reported on my Time State Machine rule template and I experienced the problem myself.
Your Environment
OH 4.1.0 M3
openhab-js 4.6
The text was updated successfully, but these errors were encountered: