How do Time Groups actually work under the hood?

I’m trying to clean up the time groups on several PBX’s, with the goal of making them more readable (feature requests: give me a comment field in a time group definition, and let me re-order entries within a time group).

That’s exposed a gap in my understanding: do time group entries define a contiguous block of time bounded by the specified start/finish, or do they create a series of AND/OR conditions?

For example, say I’m usually open Monday through Saturday, but I want to be closed for Labor Day weekend of 2025. Labor Day was on Sept 1, which means the preceding Saturday was August 30th.

If I add to my “holidays” time group:

Month Day Start : 30
Month Day Finish: 1
Month Start: August
Month Finish: September

Does this translate as “match August 30th through September 1st”, or as

if ((month = 8 OR month = 9) AND (day = 30 OR day = 31 OR day = 1)){
match
}
else{no match}

To rephrase, do time groups define an contiguous block of time bounded by the specified start/finish, or do they create a series of OR’s within AND’s?

The second case would result in being closed on both August 1st and September 30th, which is obviously not the goal.

On the other hand, usually I define Labor Day with:

Week Day Start: Monday
Week Day Finish: Monday
Month Day Start: 1
Month Day Finish: 7
Month Start: September
Month Finish: September

which actually relies on the second case being true, but for 2025 alone would also need matching entries for “last Saturday in August” and “last Sunday in August”, and is way less readable at a glance (not to mention the other entries required if Labor Day falls on any other day of September!).

Different question that might make it easier to understand what I’m asking– what happens if we do:

Month Day Start: 30
Month Day Finish: 2
Month Start: August
Month Finish: October

Does this match “all days between August 30th and October 2nd”, or does it match August 1st, 2nd, 30th, and 31st; September 1st, 2nd, and 30th (and the mythical 31st); and October 1st, 2nd, 30th, and 31st?

Do day-of-week/day-of-month/month definitions even wrap from high to low?

Practically, I know the answer is that we just need to re-define our holidays each year, because it’s either impossible or very complicated to have an eternally-robust definition of “Labor Day Weekend”, but I’d like to avoid having to do this on hundreds of PBX’s. I’m hoping someone knows something that can help me out.

(ignore the syntax highlight languages; I just wanted to make it pretty for y’all)

TL;DR: Do time groups ever define an contiguous block of time bounded by the specified start/finish, or do they always create a series of OR’s within AND’s?

Assuming that FreePBX simply uses Asterisk time conditions, it is the second case; each condition is checked separately and all must be true for a match. This logic is similar to cron in Linux and Unix.

1 Like

This is my suggestion…

Sat | Sun  | Mon
----------------
 30 |  31  | 01
 31 |  01  | 02
 01 |  02  | 03
 02 |  03  | 04
 03 |  04  | 05
 04 |  05  | 06
 05 |  06  | 07
----------------

My module will not reorder the database but it will display in order regardless of how they are entered.
Wrapping days and months will not work. (Aug 28 - Sep 1 or Dec 31 - Jan 2)
Day of week and hours can wrap. (Thu - Mon or 2200 - 0200)

1 Like