"""Various utilities for handling dates."""
-from datetime import datetime
+from datetime import datetime, timedelta
from plomtask.exceptions import BadFormatException
DATE_FORMAT = '%Y-%m-%d'
def valid_date(date_str: str) -> str:
- """Validate date against DATE_FORMAT or 'today', return in DATE_FORMAT."""
+ """Validate date against DATE_FORMAT or 'today'/'yesterday'/'tomorrow.
+
+ In any case, returns in DATE_FORMAT.
+ """
if date_str == 'today':
date_str = todays_date()
+ elif date_str == 'yesterday':
+ date = datetime.now() - timedelta(days=1)
+ date_str = date.strftime(DATE_FORMAT)
+ elif date_str == 'tomorrow':
+ date = datetime.now() + timedelta(days=1)
+ date_str = date.strftime(DATE_FORMAT)
try:
dt = datetime.strptime(date_str, DATE_FORMAT)
except (ValueError, TypeError) as e: