Replacement for now.toDateMidnight in OH3?

After migration to OH3 a rule which used now.toDateMidnight stoped working:

val max = TE_AAUS_M3.maximumSince(now.toDateMidnight)

Although I searched a lot I could not find an equivalent replacement for this with ZonedDateTime. So far my best running solution is:

val max = TE_AAUS_M3.maximumSince(now.minusHours(24))

But this is obviously not the same. Is there any equivalent to get start time of the actual day?
Thank you for any help!

EDIT: I am using Rules DSL

Ok, I meanwhile figured it out by myself. It seems to work with:

val max = TE_AAUS_M3.maximumSince(now.withHour(0))
1 Like

To get exactly midnight, now.withHour(0).withMinute(0).withSecond(0).withNano(0).

I was wondering about exactly that…does ZonedDateTime clear “the rest” (minutes, seconds etc.) if I only specify withHour(0) or do i have to write such a verbose command to really come back to midnight exactly…
From the Java docs I would have chosen the truncatedTo​ method, but this seems not to be available in Rules DSL…

I used now.with(LocalTime.MIN)


Yes, you need to set all of them.

Wow, thank you very much, that’s what I was looking for! I did not find it myself, but you are right, in the docs I find:

That seems to me the best replacement for now.toDateMidnight

1 Like