There are comparable functions like withMinute(num), withHour(num), described here, but unfortunately it does not work with withdayOfWeek(num), attributes listed here. I'm trying to get this because I want to create a cut-off date for a task, so I want to compare the time now and check if it's before or after Thursday. I.e., {{now.isBefore(now.withDayOfWeek(4))}} {{now.withDayOfWeek(4)}} {{/}}
Hello @Anthony Roldan
Try this instead.
Use an Advanced compare
now.dayOfWeek will return the current day of the week (i.e. 5 for Friday) and you can compare that to 4 (for Thursday) to determine if the current day of week is before or after Thursday).
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
So I haven't expanded on my use-case for this. I have two due dates, Tuesdays and Thursdays, with a desired cutoff of the day before at 5pm. So anything submitted after 5pm on Mondays will be due Thursday, and anything after 5pm on Wednesdays will be due on Tuesday. The problem is that you have to make multiple comparisons to pull this off, so I separated the function into 3 variables, {{tuesdayCutOff}}, {{thursdayCutOff}}, and {{dateTwo}}.
Here they are defined...
{{tuesdayCutOff}}
{{#if(now.isBefore(now.withNextDayOfWeek("TUE").withHour(21).withMinute(0).withSecond(0).minusDays(1)))}}
{{now.withNextDayOfWeek("TUE")}} {{/}}
{{#if(not(now.isBefore(now.withNextDayOfWeek("TUE").withHour(21).withMinute(0).withSecond(0).minusDays(1))))}}
{{now.withNextDayOfWeek("THU")}} {{/}}
{{thursdayCutOff}}
{{#if(now.isBefore(now.withNextDayOfWeek("THU").withHour(21).withMinute(0).withSecond(0).minusDays(1)))}}
{{now.withNextDayOfWeek("THU")}} {{/}}
{{#if(now.isBefore(not(now.withNextDayOfWeek("THU").withHour(21).withMinute(0).withSecond(0).minusDays(1))))}}
{{now.withNextDayOfWeek("TUE")}} {{/}}
{{dateTwo}}
{{#if(now.withNextDayOfWeek("TUE").isBefore(now.withNextDayOfWeek("THU")))}}
{{tuesdayCutOff}} {{/}}
{{#if(now.withNextDayOfWeek("THU").isBefore(now.withNextDayOfWeek("TUE")))}}
{{thursdayCutOff}} {{/}}
Let's start with the main event, {{dateTwo}}. We do a simple check to see if the following Tuesday will be before the following Thursday. If so, use {{tuesdayCutOff}}. If not, then use {{thursdayCutOff}}.
{{tuesdayCutOff}} and {{thursdayCutOff}} use the same logic, so for brevity's sake, I'll use the former as an example. The only thing that changes between them are the days.
The variable checks to see if {{now}} is before the following Tuesday at 5pm minus 1 day (so Monday 5pm). If so, use {{now.withNextDayOfWeek("TUE")}}. If not, use {{now.withNextDayOfWeek("THU")}}. The variable as a whole serves to check if we made the cutoff time or not, so if we didn't make it before 5pm, then the due date is set for the following Thursday.
I hope this helps someone in the future!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.