We're coding a system that parses time based events, and we'd like to implement a suppression system for these events where we can give cron-like syntax for matching against.
e.g. suppress if...
- .. the event occurs on the last Friday of the month
- .. the event occurs between 4pm and 5pm weekdays
- .. the event occurs on a Sunday
and so on.
We're using Python so I was hoping there may be a module for doing this type of thing, but my search skills are letting me down (lots of results about scheduling events, whereas I want the opposite - does the current time match a defined schedule).
Alternatively I'm happy writing one from scratch if anyone has any suggestions for the best way of storing and comparing a time against a schedule.
Edit:
To clarify, the suppression schedules are not set in stone so I cannot simply code a function to handle specific cases. The schedules need to be stored in a database, and tied to an event, so I can do roughly:
sql_rows = ..... "SELECT * FROM suppressions WHERE event_id = ?"
for row in sql_rows:
if matchesSchedule(current_time,row):
print "This should be suppressed"
So I need to represent the schedule in a format that I can store in a table, and then match columns against the current time components.