Skip to content
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

Adjust use of deprecated DateTimeType::getZonedDateTime method in time::toZDT #404

Closed
florian-h05 opened this issue Dec 11, 2024 · 3 comments · Fixed by #408
Closed

Adjust use of deprecated DateTimeType::getZonedDateTime method in time::toZDT #404

florian-h05 opened this issue Dec 11, 2024 · 3 comments · Fixed by #408
Labels
enhancement New feature or request

Comments

@florian-h05
Copy link
Contributor

Due to openhab/openhab-core#3583,
it is required to adjust

return javaZDTToJsZDT(rawState.getZonedDateTime());

and

return javaZDTToJsZDT(when.getZonedDateTime());

to DateTimeType.getZonedDateTime(zoneId).

This however cannot be done without breaking backwards compatibility with openHAB < 4.3, so we have to postpone this change to the next breaking openhab-js release.

@florian-h05 florian-h05 added the breaking change API breaking changes label Dec 11, 2024
@jlaur
Copy link
Contributor

jlaur commented Dec 11, 2024

@florian-h05 - actually there is one thing we can do without breaking anything. getZonedDateTime(ZoneId) is just a convenience method:

https://github.com/openhab/openhab-core/blob/241e55f15756a0346069f23ff4b5da57a893cced/bundles/org.openhab.core/src/main/java/org/openhab/core/library/types/DateTimeType.java#L156-L164

so we could do something like (probably I'm mixing Java and JavaScript, but you get the idea):

    return javaZDTToJsZDT(rawState.getInstant().atZone(time.ZoneId.systemDefault()));

Preferably using time-zone from TimeZoneProvider, if possible. Using that would not only get rid of the deprecated method, but actually improve the handling compared to 4.2.

WDYT?

@florian-h05
Copy link
Contributor Author

If getInstant is available long enough, this is a good solution 👍

Just noting that we need to use the time zone from the timeZoneProvider because we are dealing with Java ZDT here.
Fortunately timeZoneProvider is already available in time.js, so if you want you can create a PR.

@jlaur
Copy link
Contributor

jlaur commented Dec 18, 2024

If getInstant is available long enough, this is a good solution 👍

It was introduced in openhab/openhab-core#3287 and is there to stay. 🙂

Just noting that we need to use the time zone from the timeZoneProvider because we are dealing with Java ZDT here.
Fortunately timeZoneProvider is already available in time.js, so if you want you can create a PR.

Sure, I will give it a go. 👍

Side comment: I plan to also have a look if we can provide more Instant functionality like we have time.toZDT. I seem to find more and more cases in rules where working with ZonedDateTime is not needed. I will probably create a new issue with some concrete suggestions, so we can discuss it before writing any code.

jlaur added a commit to jlaur/openhab-js that referenced this issue Dec 18, 2024
jlaur added a commit to jlaur/openhab-js that referenced this issue Dec 18, 2024
@florian-h05 florian-h05 changed the title [next breaking release] Adjust use of deprecated DateTimeType::getZonedDateTime method in time::toZDT Adjust use of deprecated DateTimeType::getZonedDateTime method in time::toZDT Dec 23, 2024
@florian-h05 florian-h05 added enhancement New feature or request and removed breaking change API breaking changes labels Dec 23, 2024
florian-h05 pushed a commit that referenced this issue Dec 23, 2024
…Time` (#408)

Related to openhab/openhab-core#3583.
Resolves #404.

This removes usages of the deprecated `DateTimeType` method 
[getZonedDateTime()](https://www.openhab.org/javadoc/latest/org/openhab/core/library/types/datetimetype#getZonedDateTime())
and instead applies the time-zone configured in openHAB.

Signed-off-by: Jacob Laursen <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants