A simple Python library for parsing Schyntax schedule strings, and finding the next scheduled event time.
This is an unofficial Python implementation of Schyntax. See the C# reference implementation. Tested with Python 2.7 and 3.4.
Every 5 minutes:
import schyntax
schedule = schyntax.Schedule("minutes(* % 5)")
print(schedule.next())
Find the next weekday (Monday through Friday) at 16:00 UTC:
schedule = schyntax.Schedule("hours(16), days(mon..fri)")
print(schedule.next())
Accepts an optional after
argument in the form of a datetime
. If no argument is provided, the current time is used.
Returns a datetime
object representing the next timestamp which matches the scheduling criteria. The date will always be greater than, never equal to, after
. If no timestamp could be found which matches the scheduling criteria, a ValidTimeNotFoundException
is raised, which generally indicates conflicting scheduling criteria (explicitly including and excluding the same day or time).
Same as previous()
except that its return value will be less than or equal to the current time or optional at_or_before
argument. This means that if you want to find the last n-previous events, you should subtract at least a millisecond from the result before passing it back to the function.
For complete documentation on the Schyntax domain-specific language, see the Schyntax project.