Vladimir Ignatev
Vladimir Ignatev

Reputation: 2176

How to implement customizeable rules for time table scheduling?

I'm working on implementation of the library that serves one single purpose: making flexible scheduling for repeating events.

For example, one user wants to schedule a Notification to be sent "on Tuesday at 7 PM every even week of October in leap year". Another one wants it to be sent "on 13-th day every odd month at 6 AM" or "at 7 AM every Monday, Tuesday and Wednesday".

My question is very general, or abstract, and probably relates to some field of discreet math / computer science. Can we express schedules from example above using simple arithmetic over integer timestamps? What operations are enough to create a flexible language powerful enough to express almost any recurring events?

Upvotes: 1

Views: 52

Answers (1)

IVO GELOV
IVO GELOV

Reputation: 14259

I believe that you will need to support the calculation of simple boolean expressions - those which use a predefined list of predicates (e.g. isLeapYear, isMonday, isEvenWeek, etc.) combining them with the logical operators AND, OR, NOT (and allow for braces to change the precedence). Once you have a piece of code which is able to calculate boolean expressions - the rest is just to define a suitable amount of predicates.

The predicates may have argument(s) - e.g. isDayOfMonth(x) or isHour(14).

In the database you will most probably store the AST (abstract syntax tree) of the expression - but it is also possible to store the expression as string, purely your choice.

Upvotes: 1

Related Questions