Problem with "now.isAfter"

Hello,

I have a problem, I want to do some stuff between 2 time periods.

when
        Item XXXX received update ON
then
		if (now.isAfter(now.withTimeAtStartOfDay.plusHours(19).plusMinutes(30)) && now.isBefore(now.withTimeAtStartOfDay.plusHours(20).plusMinutes(55)) {		
			sendCommand(YYYY, ON)
		}
 end

this isn’t working but this is:

when
        Item XXXX received update ON
then
		if (now.isAfter(now.withTimeAtStartOfDay.plusHours(19).plusMinutes(30)) {		
			sendCommand(YYYY, ON)
		}
 end

what am I doing wrong with the and function?

I would try it with and extra ( ) around the complete if statement, like:

when
        Item XXXX received update ON
then
		if ((now.isAfter(now.withTimeAtStartOfDay.plusHours(19).plusMinutes(30)) && now.isBefore(now.withTimeAtStartOfDay.plusHours(20).plusMinutes(55))) {		
			sendCommand(YYYY, ON)
		}
 end

thanks for helping me, but the extra () isn’t working, i don’t know what i’m doing wrong.

You’re missing the closing ) on the if statements on both rules.

if (now.isAfter(now.withTimeAtStartOfDay.plusHours(19).plusMinutes(30))) {


if (now.isAfter(now.withTimeAtStartOfDay.plusHours(19).plusMinutes(30)) && now.isBefore(now.withTimeAtStartOfDay.plusHours(20).plusMinutes(55))) {

No, thats also not the problem.
The strange thing is…

When I only do this, it work:
if (now.isAfter(now.withTimeAtStartOfDay.plusHours(21).plusMinutes(10))) {

When I only do this, it don’t work:
if (now.isBefore(now.withTimeAtStartOfDay.plusHours(21).plusMinutes(50))) {

The issue is in the “now.isBefore” part.

Try adding the .millis inside isAfter and isBefore

if (now.isAfter(now.withTimeAtStartOfDay.plusHours(19).plusMinutes(30).millis)) {

if (now.isAfter(now.withTimeAtStartOfDay.plusHours(19).plusMinutes(30).millis) && now.isBefore(now.withTimeAtStartOfDay.plusHours(20).plusMinutes(55).millis)) {

I can confirm that isBefore does not work as expected - at least today… because today daylight saving was switched off…
I had to add one hour when testing the behavior.
It was about 11:25 pm when I tested .isBefore(), and it did not work with

if (now.isBefore(now.withTimeAtStartOfDay.plusHours(23).plusMinutes(30)))

but adding another hour worked!

if (now.isBefore(now.withTimeAtStartOfDay.plusHours(24).plusMinutes(30)))

So maybe this is a temporary error. I will try the same tomorrow…

In fact, the behavior is correct, because the actual day has 25 hours!!!

In question of the time span to test, I would prefer

if(now.getMinuteOfDay > 19 * 60 + 30 && now.getMinuteOfDay < 20 * 60 + 55)

at least for time spans after 3:00 am…

It was indeed the daylight saving that was bullying me.
I just start to implement this on the wrong day.
Yesterday all was working fine!

thanks guys!