Parsing human-readable recurring dates in Python

Problem. In my Django application, users create tasks for scheduled execution. Users are pretty non-technical, and it would be great if they could write regular human-readable expressions to determine when to perform a specific task, for example:

  • every Monday
  • every fri, wed
  • daily
  • 1, 14, 20 of each month
  • every Fri; every end of the month

It is inspired by Todoist . So far, only dates are needed; no time. I spent a couple of hours searching the library to do this, but no luck. I expect a function, say in_range(expression, date), such that:

>>> in_range('every monday, wednesday', date(2014, 4, 28))
True

>>> in_range('every end of month', date(2014, 5, 12))
False

>>> in_range('every millenium', date(2014, 5, 8))
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ValueError: unknown token "millenium".

Options. What I looked through.

, Python , , -? , . open source, .

+4
1

Recurrent - , . API, , Python datetime.

Github:

  • 1 2010 25 2020 .
  • 3:15

  • .
  • 11
+4

Source: https://habr.com/ru/post/1538197/


All Articles