AddWeeks and addDays broken partially: possible DST change issue?


#1

If you use the expression

‘Thanksgiving is on ‘ addWeeks(date(’11/1/2018’),4)

It will return the date for wed November 28,2018. However if you change the date to 11/5/2018 it works as expected mon, November 26, 2018.

From testing it seems that if the beginning of the month starts before Sunday it gets hung up on Sunday, and evaluates it twice. Thus making date off by one day. If you try this for 2019, it errors the same. However 2020 works correctly since 11/1 is on a Sunday.

Same thing happens if you try to add 21 days to the date.

This only seems to be happening for November, from my limited testing. Is this because of DAilight savings time change on nov 4th?

Any suggestions on to work around or fix?


#2

That’s because you’re doing it wrong. If you just want the date and not the date time, you want the date on the outside. Your expression should be date(addWeeks(date,add))

Just tried that using the $now variable and it worked perfect. Also, i wouldn’t type the date in like you have. I would set a date/time variable and use that inside your expression. Less chance of screwing up your syntax. Also, remember, your expression is always going to return an epoch date/time combo (if you’re looking at the raw response). So you might want to use the expression to set another variable if you want to see it in the correct format.


#3

Ok, I get that. Try this for me. 11/1/2018 is a Thursday, it is befor Sunday the 4th, which is daylight savings time end and clocks switch back an hour here. Try adding 3 weeks to 11/1/2018. It will return Wednesday 11/20/2018 instead of Thursday 11/22/2018

I found a different way to do it, but the bug remains the same using that method.

4now works the way you say because it is not being affected by Daylight savings time end


#4

Are you just plugging 11/1/2018 into the expression? Cause that definitely won’t work. Can you provide a screenshot of your piston?
4 weeks is definitely being affected by DST ending. Because it is ending between now and when your end date is. Also, you have to take into account are you doing the math in GMT or local time? How you input it into WebCore will affect the outcome greatly.


#5

I got it worked out thanks. What I did is use a repeat loop starting at Nov 22 and Check if date was a Thursday then set that date to Thanksgiving


#6

But why? I don’t understand. Thanksgiving is only one day. Why not just set a variable to the date for Thanksgiving by hand. Boom…done. 2 seconds work. LOL


#7

I am building a piston that adds al the major holidays to my google calendar for the year on the 1st day of January. From there I use gcal to create a virtual device that webcore can use to trigger pistons based on holidays. Ie, lighting, routines etc. yes I could enter each of them manually. But why when I can have it just happen.


#8

Google have tools for this already:

https://support.google.com/calendar/answer/6084659?co=GENIE.Platform%3DAndroid&hl=en


#9

I have been doing many of those already, however I don’t need every religious hl]oliday filled in, my calendar is full enough with all my daughters school actives and schedule. I only really need the core 8 holidays. The rest are fluff and mess up my Gcal pistons by incorporation holidays that i really don’t need to concern with. Then blocking Gcal from seeing them until the extra holiday closes and then sees the next.

With all that being said, thanks @Robin and @Ryan780. I will share the piston later for those that my find interest or use in it. It is really chunky, of which the Easter calculation is the bulk of the piston.


#10

It seems like that would be easier to set up as a repeating event on your google calendar. Like New Years repeats yearly on Jan 1st. Thanksgiving repeats on the 4th Thursday in Nov. I wouldn’t take the time to iron out a WebCore piston for 8 events a year. How do you know if it will be right? LOL


#11

Good point on the static date holidays, it Jan 1, July 4, dec 25, and oct 31. However the variable date holidays cant be set up as repeat in google calendar that I see, no option for 4th Thursday in Nov, for example.


#12

Okay…but how many of the holidays you want are like that? 3? to me it would be easier to set them manually than to go through the trouble of making a WebCore piston to set them. Plus, how are you setting the event on your google calendar from ST? is that going to be reliable enough?