Predicates Writing predicates Topic 2 of 3

Writing predicates

Topic 2 of 3

A predicate is a boolean expression built from a few variables, joined with AND, OR, and comparisons. The variables describe the moment the engine is checking: $TIME for the time of day, $DATE for the date, $WEEKDAY for the day of the week.

A predicate that combines a daily time window, a start date, and specific weekdays looks like this:

TRUE AND ($TIME BETWEEN {28800000, 79200000}) OR ($DATE >= 1778889600000) OR ($WEEKDAY IN {0, 1})

Read in plain English, that breaks into three conditions (the opening TRUE AND is only the base the string is built up from):

  • $TIME BETWEEN {28800000, 79200000}: the time of day is between 8 a.m. and 10 p.m., since $TIME counts milliseconds from midnight
  • $DATE >= 1778889600000: the date is on or after 16 May 2026, since $DATE is a full epoch timestamp in milliseconds
  • $WEEKDAY IN {0, 1}: the day of the week is one of the two listed

Joined with OR, the playlist is eligible whenever any one of the three is true.

The numbers are the catch. $TIME and $DATE are in milliseconds, so 8 a.m. is 28800000 and a calendar date is a full epoch timestamp. Working those out by hand is no fun.

That is why predicates are almost always generated, not typed. You compute the values in code and build the string:

def ms(hours):
    return hours * 60 * 60 * 1000

predicate = "TRUE AND ($TIME BETWEEN {%d, %d})" % (ms(8), ms(22))
# TRUE AND ($TIME BETWEEN {28800000, 79200000})

The dashboard does exactly this for you when you pick times and days. You reach for the raw language when you are creating playlists in code, or when you need a rule the dashboard does not expose.