vossivossi
(vossivossi)
December 3, 2020, 3:15pm
1
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
vossivossi
(vossivossi)
December 3, 2020, 3:54pm
2
Ok, I meanwhile figured it out by myself. It seems to work with:
val max = TE_AAUS_M3.maximumSince(now.withHour(0))
1 Like
5iver
(Scott Rushworth)
December 3, 2020, 5:54pm
3
To get exactly midnight, now.withHour(0).withMinute(0).withSecond(0).withNano(0)
.
vossivossi
(vossivossi)
December 3, 2020, 9:38pm
4
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…
MikeJMajor
(Mike Major)
December 3, 2020, 9:55pm
5
I used now.with(LocalTime.MIN)
3 Likes
5iver
(Scott Rushworth)
December 3, 2020, 10:00pm
6
Yes, you need to set all of them.
vossivossi
(vossivossi)
December 3, 2020, 10:03pm
7
MikeJMajor:
LocalTime
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