Specific hour of current day for rules DSL

Dear all,

on OH 3 I would like to have a rule that calculated the DateTime of a pre-defined time for the current day, e.g. at any time I trigger the rule, I want to have the DateTime of today at 20:00.
Any idea how to get that done? Any good docu to check my self for learning?

Thanks!

Yes this can easily be done with blockly. See here:

Edit: Did not see that you need it for DSL rules.
For this I don’t have an idea.

1 Like

There are several ways

One is:

now.withHour(20).withMinute(0).withSecond(0).withNano(0)

Another is to truncate now to midnight .truncatedTo(ChronoUnit::DAYS) then add a 20hr duration, or add 20 hours plusHours(20)

See ZonedDateTime (Java SE 12 & JDK 12 )

2 Likes

Thanks, great!

Need to check it but best is probably helping to find documentation to learn and improve!

Blockly not used yet, let’s see…

Thanks!

Another way:
ZonedDateTime.now.with(LocalTime.of(20, 0, 0, 0))

2 Likes

Comment ; using a “with hour of 20” type method will reliably give you clock time 20:00. Using a “midnight plus 20 hours” method may give you clock 19:00 or 21:00 on odd days when summertime changes, but still a genuine elapsed 20 hours… Be sure to choose the method you actually want.

1 Like

Just to provide one more way using JS Scripting:

time.toZDT("20:00")

Great - thanks to the many ideas!