Checking time in rule script in OH3

Ok, another script problem in OH3. I have the following if clause in OH2:

  if(now.isBefore(new DateTime(now.getYear(), now.getMonthOfYear(), now.getDayOfMonth(), 20, 0, 0))) {

…which checks if the current time is before 20:00. How would I do that in OH3?

I don’t really know, where would I search for documentation about how date/time works in OH3? I know things are different, just don’t really where to find exactly what is different :slight_smile:

There is a hint at the bottom of this post…

if (now.isBefore(now.withHour(20).withMinute(0).withSecond(0).withNano(0))) {

Read through the methods of ZonedDateTime…

On second thought, this could be simplified using…

if (now.getHour() < 20) {

I though the time provider changed in OH3.

1 Like

Isn’t that for OH2?

The post was intended for OH2, to prepare for OH3 by using ZonedDateTime instead of Joda Time. It will also work in OH3. See my last update though… using getHour() is simpler.

2 Likes

Thanks for sharing information. Please keep sharing this type of post ahead.

krogerfeed