openhab / openhab-js

openHAB JavaScript Library for JavaScript Scripting Automation
https://www.openhab.org/addons/automation/jsscripting/
Eclipse Public License 2.0
38 stars 31 forks source link

Monkeypatch Ephemeris to ZonedDateTime #250

Closed rkoshak closed 1 year ago

rkoshak commented 1 year ago

This is an out there idea so you won't hurt my feelings if you say this is crazy.

Yesterday I was working on recoding one of my rule templates and MainUI offered to autocomplete isBankHoliday on a ZonedDateTime. That took me down a rabbit hole and I've come to the conclusion that this was a mistake in MainUI and this is not implemented (at least I don't see where it could be done in either time.js nor actions.js).

But that would be kind of cool if it was. Instead of reaching out to the OH Actions:

actions.Ephemeris.isWeekend(time.toZDT())

we can use

time.toZDT().isWeekend()

It's just a half baked thought. Obviously on the isX actions that take a ZDT would be included. All the rest would remain accessible in actions.Ephemeris.

florian-h05 commented 1 year ago

MainUI offered to autocomplete isBankHoliday on a ZonedDateTime. That took me down a rabbit hole and I've come to the conclusion that this was a mistake in MainUI and this is not implemented

Hmm, I have checked the definition used for the autocompletion inside the UI and the definition looks good, I cannot see any problem there. I therefore have no idea where this hint comes from and I cannot reproduce it.

But that would be kind of cool if it was. Instead of reaching out to the OH Actions:

Whilst I see the benefit in allowing this, I see it critical to monkey-patch a functionality that depends on openHAB core onto a JS class, because we need to maintain Ephemeris at two places then (however effort is very low). Another point I am concerned about is, that the JS-Joda ZonedDateTime is a JS port of the java.time package and we should try to keep it clean.

Let‘s hear the opinion of @digitaldan.

digitaldan commented 1 year ago

ZonedDateTime is a JS port of the java.time package and we should try to keep it clean.

That is my view as well, I have a high bar for deciding if we extend or modify such a core library.

rkoshak commented 1 year ago

OK, well nothing happens if you don't ask.