Next XX day of week

I’m trying to calculate values like “next monday” using day_of_week or similar. Unfortunately, without success.
In https://developer.bigfix.com/relevance/reference I was not able to get a good idea. I also had a look at https://bigfix.me/analysis/details/29 to maybe adapt it but also got stuck here.

Any better ideas?

If you only need the day of the month, this should do it -

q: (current date +  it * day) whose (day_of_week of it = Monday) of integers in (1,7)
A: Mon, 03 Apr 2023
T: 0.363 ms

With that day range, you should get the next Monday (but not today, if today is a Monday). If you want to include today, then change the day range from (1, 7) to (0, 6).

If you’re using this for a maintenance window, and need to set a specific time of day, you can do that using either the client’s local time zone, or UTC time, as

q:  (it & "04:30:00" as local zoned time_of_day) of (current date +  it * day) whose (day_of_week of it = Monday) of integers in (1,7)
A: Mon, 03 Apr 2023 04:30:00 -0500
T: 7.360 ms
I: plural time

(Monday, 04:30 UTC will occur for me on Sunday at 23:30 local time)

q:  (it & "04:30:00" as universal zoned time_of_day) of (current date +  it * day) whose (day_of_week of it = Monday) of integers in (1,7)
A: Sun, 02 Apr 2023 23:30:00 -0500
T: 7.313 ms
I: plural time

I also went down a path with a pretty bad edge case. Considering you might want a maintenance window to start at a specific time on either this week or next (if Today matches your day), I started by expanding the day range to (0, 7) potentially checking both today and next week, and taking the lesser of the two that is greater than “now”.

q:  ((it & "04:30:00" as local zoned time_of_day) of (current date +  it * day) whose (day_of_week of it = Tuesday) of integers in (1,7)) whose ( it > now)
A: Tue, 04 Apr 2023 04:30:00 -0500
T: 7.260 ms
I: plural time

The problem with that comes when the time arrives. When the current time is “Tue, 04 Apr 2023 04:20:00 -0500”, the result will be the next instance of 04:30 (at A: Tue, 28 Mar 2023 04:30:00 -0500) - but once 4:30 comes around, that time becomes less than “now” and the result changes to “Tue, 04 Apr 2023 04:30:00 -0500”. If you’re going to compare that time to “now” to return a True/False value, you could give a range like “now is less than four hours after the given start time” as in

q:  minimum of ((it & "04:30:00" as local zoned time_of_day) of (current date +  it * day) whose (day_of_week of it = Tuesday) of integers in (0,7)) whose ( it < now + 4 * hour)
A: Tue, 28 Mar 2023 04:30:00 -0500
2 Likes

Thanks for your fast reply @JasonWalker and for the detailed examples. I will play around and have a look.

Actual we import maint window based on ucmdb data by textfile on client. As we maybe try to use Bigfix internal maint wndows in the future I’m actual thinking about creating a custom analyse similar to “Maintenance Window Analysis” and import our own maintenance times in compatible way.
My idea behind is to have a “supported” relevance to calculate maintenance times and be better prepared for the future.