In any case, returns in DATE_FORMAT.
"""
if date_str == 'today':
- date_str = todays_date()
+ date_str = date_in_n_days(0)
elif date_str == 'yesterday':
- date = datetime.now() - timedelta(days=1)
- date_str = date.strftime(DATE_FORMAT)
+ date_str = date_in_n_days(-1)
elif date_str == 'tomorrow':
- date = datetime.now() + timedelta(days=1)
- date_str = date.strftime(DATE_FORMAT)
+ date_str = date_in_n_days(1)
try:
dt = datetime.strptime(date_str, DATE_FORMAT)
except (ValueError, TypeError) as e:
return dt.strftime(DATE_FORMAT)
-def todays_date() -> str:
- """Return current date in DATE_FORMAT."""
- return datetime.now().strftime(DATE_FORMAT)
+def date_in_n_days(n: int) -> str:
+ """Return in DATE_FORMAT date from today + n days."""
+ date = datetime.now() + timedelta(days=n)
+ return date.strftime(DATE_FORMAT)
from urllib.parse import urlparse, parse_qs
from os.path import split as path_split
from jinja2 import Environment as JinjaEnv, FileSystemLoader as JinjaFSLoader
-from plomtask.dating import todays_date
+from plomtask.dating import date_in_n_days
from plomtask.days import Day
from plomtask.exceptions import HandledException, BadFormatException, \
NotFoundException
"""Show Days from ?start= to ?end=."""
start = self.params.get_str('start')
end = self.params.get_str('end')
+ if not end:
+ end = date_in_n_days(60)
ret = Day.by_date_range_with_limits(self.conn, (start, end), 'id')
days, start, end = ret
days = Day.with_filled_gaps(days, start, end)
def do_GET_day(self) -> dict[str, object]:
"""Show single Day of ?date=."""
- date = self.params.get_str('date', todays_date())
+ date = self.params.get_str('date', date_in_n_days(0))
todays_todos = Todo.by_date(self.conn, date)
conditions_present = []
enablers_for = {}
from unittest import TestCase
from datetime import datetime
from tests.utils import TestCaseWithDB, TestCaseWithServer
-from plomtask.dating import todays_date
+from plomtask.dating import date_in_n_days
from plomtask.days import Day
from plomtask.exceptions import BadFormatException
[day5, day6, day7])
self.check_storage([day1, day2, day3, day6])
# check 'today' is interpreted as today's date
- today = Day(todays_date())
+ today = Day(date_in_n_days(0))
today.save(self.db_conn)
self.assertEqual(Day.by_date_range_filled(self.db_conn,
'today', 'today'),