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

DateTimeType spec fix #340

Merged
merged 1 commit into from
Sep 17, 2024
Merged

DateTimeType spec fix #340

merged 1 commit into from
Sep 17, 2024

Conversation

jimtng
Copy link
Contributor

@jimtng jimtng commented Sep 16, 2024

The case of DateTimeType.parse("00:00+1000") is parsed by Time.parse in DSL.try_parse_time_like, which takes into account the current time and the system time zone in interpreting the given "time+timezone" string.

This is why it has been intermittent in the past: depending on the time the spec was running, and the system time zone of the machine running the spec, the resulting date could be either today or yesterday whereas the previous spec was pinning the date to today's date.

Here's a demonstration, notice the date in the last example:

irb(main):047> Time.now
=> 2024-09-17 10:16:27.302101 +1000
irb(main):048> Time.now.utc
=> 2024-09-17 00:16:33.278331 UTC
irb(main):049> Time.parse("0:00+00:00")
=> 2024-09-17 00:00:00 +0000
irb(main):050> Time.parse("0:00-00:18")
=> 2024-09-16 00:00:00 -0018

The solution in this PR is to simply compare the result against Time.parse so we should get the exact same result since they're using the same parser (and hence parsing logic) to come up with whatever date it is.

In practice, parsing time+timezone without a date is perhaps a rare case?

@jimtng jimtng force-pushed the datetimetype-spec2 branch 5 times, most recently from 4ae2b0b to c173e4e Compare September 16, 2024 23:50
Signed-off-by: Jimmy Tanagra <[email protected]>
@jimtng jimtng marked this pull request as ready for review September 17, 2024 00:15
@jimtng jimtng requested a review from ccutrer September 17, 2024 00:15
@ccutrer ccutrer merged commit 2b8f34d into openhab:main Sep 17, 2024
20 of 21 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants