First, It’s a long shot but var vacMoOn = 05
might be the problem with the int version. I’m not sure what Rules DSL does with that leading zero.
This is really become an XY Problem I think.
In general, I hate this type of code. It’s why I created the Time of Day design pattern and rule template, the Alarm Clock rule template, and added all those time utils to the JS Scripting helper library. Directly working with date times is really complex.
A really simple way to replace this whole mess would be as follows:
-
Create a String Item, call it “Season” or something else appropriate.
-
Create a rule with a cron trigger for May 15th and command Season with “SUMMER”
-
Create similar rules for all the other dates/seasons you care about (e.g. one for August 15th that sets “Season” to “AUTUM” and o on.
-
Now in your rule it’s as simple as
if(Season.state == “SUMMER”) {
Easy peasy with out needing to mess with Date Times at all. You don’t even need to write code for the rules since these are simple enough to use simple UI rules to implement. The code that uses it is also way easier to read and understand.
If you want to follow the seasons of the year exactly there is even a Channel in the Astro Binding you can use. You don’t even need the rules.
Notice that we don’t mess with the year. That’s because we don’t want to have to change the code every new year to keep this code working.
In an openHAB context, I’ve never seen the utility of using LocalDate, LocalTime, or LocalDateTime. Everything that needs to interact with OH will need a ZonedDateTime anyway so I find it easier to deal with ZonedDateTimes in those rare cases where I need to mess with the actual date times directly. So if I wanted to see if now was between two dates and I didn’t want to set up a state machine for that (i.e. that Season Item from above) I would do the following.
if(now.isAfter(now.withMonth(5).withDay(15)) && now.isBefore(now.withMonth(8).withDay(15))) {
We don’t mess with the year because we want it to work next year too. In Rules DSL we already have ZonedDateTime.now()
“aliased” to just now
so why add all that extra stuff just to work with Local
?
In JS Scripting that would look something like
if(time.toZDT().isBetweenTimes(time.toZDT().withMonth(5).withDay(15), time.toZDT().withMonth(8).withDay(15)) {
But even that pails in the simplicity and understandability of
if(Season.state == "SUMMER"){