boc-tothefuture / openhab-jruby

JRuby Libraries for Openhab
Eclipse Public License 2.0
6 stars 9 forks source link

fix(zoneddatetime): make ZonedDateTime available on OpenHAB 3.2 #568

Closed jimtng closed 2 years ago

jimtng commented 2 years ago

Move the java_import for ZonedDateTime to the top of dsl.rb so it's available for user scripts. Remove instances of java_import java.time.ZonedDateTime in other places

This makes it no longer necessary to import ZonedDateTime within user scripts even on openhab 3.2. This also deduplicates the multiple imports in submodules.

By "importing", I mean re-assigning the ZonedDateTime constant to the Ruby class version. I'm not sure how "expensive" this operation is, but I suspect it's very "cheap" / fast to execute.

boc-tothefuture commented 2 years ago

What is the reason for using ZDT instead of the ruby time/date objects and converting to ZDT where necessary?

jimtng commented 2 years ago

Sometimes using ZDT is unavoidable, other times, zdt has nicer methods that Ruby Time doesn't have. For example, plus_minutes, plus_hours, etc without having to do maths. It also naturally uses java Duration for deltas.

boc-tothefuture commented 2 years ago

Sometimes using ZDT is unavoidable, other times, zdt has nicer methods that Ruby Time doesn't have. For example, plus_minutes, plus_hours, etc without having to do maths. It also naturally uses java Duration for deltas.

Makes sense.

jimtng commented 2 years ago

This was a bit epic to fix. I had to re-import in rule executions and also in timer executions. I wonder if it's worth doing. Is the performance impact acceptable?

I added a guard in the import method to avoid importing if ZDT is already correct.

github-actions[bot] commented 2 years ago

:tada: This PR is included in version 4.37.0 :tada:

The release is available on:

Your semantic-release bot :package::rocket: