home · contact · privacy
Move VersionedAttributes code into appropriotely named module.
[plomtask] / plomtask / days.py
index 78340e2d13000e7ef49bff1bdc24f27e561993c1..8dd384349bd1419a16b19971ee4d9aa81deff796 100644 (file)
@@ -5,6 +5,8 @@ from plomtask.exceptions import BadFormatException
 from plomtask.db import DatabaseConnection, BaseModel
 
 DATE_FORMAT = '%Y-%m-%d'
+MIN_RANGE_DATE = '2024-01-01'
+MAX_RANGE_DATE = '2030-12-31'
 
 
 def valid_date(date_str: str) -> str:
@@ -30,14 +32,11 @@ class Day(BaseModel[str]):
     to_save = ['comment']
 
     def __init__(self, date: str, comment: str = '') -> None:
-        super().__init__(date)
-        self.id_: str = valid_date(date)
+        id_ = valid_date(date)
+        super().__init__(id_)
         self.datetime = datetime.strptime(self.date, DATE_FORMAT)
         self.comment = comment
 
-    def __eq__(self, other: object) -> bool:
-        return isinstance(other, self.__class__) and self.date == other.date
-
     def __lt__(self, other: Day) -> bool:
         return self.date < other.date
 
@@ -45,7 +44,14 @@ class Day(BaseModel[str]):
     def all(cls, db_conn: DatabaseConnection,
             date_range: tuple[str, str] = ('', ''),
             fill_gaps: bool = False) -> list[Day]:
-        """Return list of Days in database within date_range."""
+        """Return list of Days in database within (open) date_range interval.
+
+        If no range values provided, defaults them to MIN_RANGE_DATE and
+        MAX_RANGE_DATE. Also knows to properly interpret 'today' as value.
+
+        On fill_gaps=True, will instantiate (without saving) Days of all dates
+        within the date range that don't exist yet.
+        """
         min_date = '2024-01-01'
         max_date = '2030-12-31'
         start_date = valid_date(date_range[0] if date_range[0] else min_date)
@@ -69,6 +75,7 @@ class Day(BaseModel[str]):
     @property
     def date(self) -> str:
         """Return self.id_ under the assumption it's a date string."""
+        assert isinstance(self.id_, str)
         return self.id_
 
     @property
@@ -90,4 +97,4 @@ class Day(BaseModel[str]):
 
     def save(self, db_conn: DatabaseConnection) -> None:
         """Add (or re-write) self to DB and cache."""
-        self.save_core(db_conn, update_with_lastrowid=False)
+        self.save_core(db_conn)