home · contact · privacy
Default calendar date range end to 60 days later.
authorChristian Heller <c.heller@plomlompom.de>
Thu, 30 May 2024 07:05:17 +0000 (09:05 +0200)
committerChristian Heller <c.heller@plomlompom.de>
Thu, 30 May 2024 07:05:17 +0000 (09:05 +0200)
plomtask/dating.py
plomtask/http.py
tests/days.py

index c55d847a1319a3687ac0ac06edc63b79e142ca09..26b3ce3f4c2dae84fb44c8366d4a96882ced76ef 100644 (file)
@@ -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)
index cf7bb0810719674a943ba2f7f8eec45e72befdbf..280b0f5cef64c904e5e64dede0f91b2a7cf800f7 100644 (file)
@@ -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 = {}
index 4727fac743dad82bc5aee56635d253ac9b63c192..d34d7ba794e16476fd2f0c54fa28f39c5e77ea74 100644 (file)
@@ -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'),