"""Collecting Day and date-related items."""
from __future__ import annotations
from datetime import datetime, timedelta
-from plomtask.exceptions import BadFormatException, NotFoundException
+from plomtask.exceptions import BadFormatException
from plomtask.db import DatabaseConnection, BaseModel
DATE_FORMAT = '%Y-%m-%d'
"""Individual days defined by their dates."""
table_name = 'days'
to_save = ['comment']
- id_type = str
def __init__(self, date: str, comment: str = '') -> None:
+ super().__init__(date)
self.id_: str = valid_date(date)
self.datetime = datetime.strptime(self.date, DATE_FORMAT)
self.comment = comment
days = gapless_days
return days
- @classmethod
- def by_id(cls, db_conn: DatabaseConnection,
- date: str, create: bool = False) -> Day:
- """Retrieve Day by date if in DB (prefer cache), else return None."""
- day, _ = super()._by_id(db_conn, date)
- if day:
- return day
- if not create:
- raise NotFoundException(f'Day not found for date: {date}')
- day = cls(date)
- day.cache()
- return day
-
@property
def date(self) -> str:
"""Return self.id_ under the assumption it's a date string."""