From: Christian Heller Date: Thu, 30 May 2024 07:05:17 +0000 (+0200) Subject: Default calendar date range end to 60 days later. X-Git-Url: https://plomlompom.com/repos/%7B%7B%20web_path%20%7D%7D/%7B%7Bprefix%7D%7D/%7B%7Bdb.prefix%7D%7D/todo?a=commitdiff_plain;h=f1795f22a6ea2409fc1c7c0ea921dc530e7625c2;p=plomtask Default calendar date range end to 60 days later. --- diff --git a/plomtask/dating.py b/plomtask/dating.py index c55d847..26b3ce3 100644 --- a/plomtask/dating.py +++ b/plomtask/dating.py @@ -11,13 +11,11 @@ def valid_date(date_str: str) -> str: 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: @@ -26,6 +24,7 @@ def valid_date(date_str: str) -> str: 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) diff --git a/plomtask/http.py b/plomtask/http.py index cf7bb08..280b0f5 100644 --- a/plomtask/http.py +++ b/plomtask/http.py @@ -5,7 +5,7 @@ from http.server import HTTPServer 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 @@ -113,6 +113,8 @@ class TaskHandler(BaseHTTPRequestHandler): """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) @@ -122,7 +124,7 @@ class TaskHandler(BaseHTTPRequestHandler): 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 = {} diff --git a/tests/days.py b/tests/days.py index 4727fac..d34d7ba 100644 --- a/tests/days.py +++ b/tests/days.py @@ -2,7 +2,7 @@ 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 @@ -87,7 +87,7 @@ class TestsWithDB(TestCaseWithDB): [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'),