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

Enhance DateTimeType to parse ZonedDateTime with time-zone ID #4516

Merged
merged 1 commit into from
Dec 29, 2024

Conversation

jlaur
Copy link
Contributor

@jlaur jlaur commented Dec 22, 2024

This DSL rule:

rule "Test"
when
    Item Test changed to ON
then
    var zoned = ZonedDateTime.parse("2024-12-22T16:29+01:00")
    logInfo("zoned to item", zoned.toString)
    TestDateTime.postUpdate(zoned.toString)

    zoned = (TestDateTime.state as DateTimeType).getZonedDateTime()
    logInfo("zoned from item", zoned.toString)

    TestDateTime.postUpdate(zoned.toString)
end

generates the following output in 4.3:

2024-12-23 00:27:00.168 [INFO ] [nhab.core.model.script.zoned to item] - 2024-12-22T16:29+01:00
2024-12-23 00:27:00.169 [INFO ] [ab.core.model.script.zoned from item] - 2024-12-22T16:29+01:00[Europe/Copenhagen]
2024-12-23 00:27:00.170 [WARN ] [b.core.model.script.actions.BusEvent] - Cannot convert '2024-12-22T16:29+01:00[Europe/Copenhagen]' to a state type which item 'TestDateTime' accepts: [DateTimeType, UnDefType].

Until 4.2 this rule worked, because getZonedDateTime() returned the same ZonedDateTime as provided when creating the DateTimeType. Since it didn't necessarily contain time-zone ID but only offset (e.g. "2024-12-22T16:29+01:00"), DateTimeType.parse would then be able to parse it in some scenarios. Now, it contains the time-zone ID (e.g. "2024-12-22T16:29+01:00[Europe/Copenhagen]") always, which DateTimeType.parse is not able to parse (and never was).

To make this rule compatible I would propose to add support for parsing a full ZonedDateTime string that includes time-zone ID. If this is accepted, I think it should also be cherry-picked into 4.3.x for immediate value. i.e. to fix rules that might have been broken by 4.3. By the time we reach 5.0, users would otherwise have been forced to refactor their rules already.

See https://community.openhab.org/t/datetime-conversion-after-update-to-4-3-0/161053/1

Regression of #3583

Signed-off-by: Jacob Laursen <jacob-github@vindvejr.dk>
@jlaur jlaur requested a review from a team as a code owner December 22, 2024 23:40
@openhab-bot
Copy link
Collaborator

This pull request has been mentioned on openHAB Community. There might be relevant details there:

https://community.openhab.org/t/datetime-conversion-after-update-to-4-3-0/161053/5

Copy link
Member

@kaikreuzer kaikreuzer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm, thanks!

@kaikreuzer kaikreuzer merged commit 1a91ef2 into openhab:main Dec 29, 2024
3 checks passed
@kaikreuzer kaikreuzer added the bug An unexpected problem or unintended behavior of the Core label Dec 29, 2024
kaikreuzer pushed a commit to kaikreuzer/openhab-core that referenced this pull request Dec 29, 2024
…b#4516)

Signed-off-by: Jacob Laursen <jacob-github@vindvejr.dk>
@kaikreuzer kaikreuzer added the patch A PR that has been cherry-picked to a patch release branch label Dec 29, 2024
@kaikreuzer
Copy link
Member

Backported to 4.3.x.

@jlaur jlaur deleted the datetimetype-parse-zoneddatetime branch December 29, 2024 11:44
kaikreuzer pushed a commit that referenced this pull request Dec 30, 2024
Signed-off-by: Jacob Laursen <jacob-github@vindvejr.dk>
@holgerfriedrich holgerfriedrich added this to the 5.0 milestone Dec 31, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug An unexpected problem or unintended behavior of the Core patch A PR that has been cherry-picked to a patch release branch
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants