Schedule algebra

How can we think more formally about our schedule? A schedule covers every minute of the day from midnight to the last minute before midnight 24 hours later.

00:00                                23:59
|....................................|

Such a day has always at least one event which then needs to stretch across the full day, or it can have multiple events scattered around the day. In any case every minute of the day needs to be covered by some event.

00:00     09:00   12:00              23:59
|.........|.......|..................|

Each event k has a start time (the first minute of the event) ak and an end time bk (the last minute of the event) which together we can write as k:[ak,bk].

For the whole schedule S we have a couple events for which the following invariant holds:

S:k[ak,bk],akbk,ak=bk1+1,a0=00:00,bkmax=23:59

To add a new event [x,y] means rewriting the sequence of events. For each existing event [a, b]] we rewrite with the following logic:

condition on x on y replace [a,b] with
x>b   [a,b]]
x=b   [a,x1][x,y]
a<x<b y<b [a,x1][x,y][y+1,b]
  yb [a,x1][x,y]
a=x y<b [x,y][y+1,b]
  yb [x,y]
a>x y<a [a,b]
  y=a [x,y][y+1,b]
  b>y>a [x,y][y+1,b]
  by [x,y]

Squinting a bit this looks like it could be further simplified. But that’s for another time.