From: Christian Heller Date: Wed, 29 Jan 2025 02:41:56 +0000 (+0100) Subject: Fix handling of erroneous date fields. X-Git-Url: https://plomlompom.com/repos/%7B%7Bdb.prefix%7D%7D/%7B%7B%20web_path%20%7D%7D/static/%7B%7Bprefix%7D%7D/error?a=commitdiff_plain;p=plomledger Fix handling of erroneous date fields. --- diff --git a/ledger.py b/ledger.py index 0c6ed5e..ebb188f 100755 --- a/ledger.py +++ b/ledger.py @@ -144,23 +144,17 @@ class IntroLine(BookingLine): def __init__(self, booking: 'Booking', code: str) -> None: super().__init__(booking) - self.date = '#' - self.target = '' if code[0].isspace(): self.errors += ['intro line indented'] toks = code.lstrip().split(maxsplit=1) - if len(toks) != 2: + self.date = toks[0] + self.target = toks[1] if len(toks) > 1 else '' + if len(toks) == 1: self.errors += ['illegal number of tokens'] - elif len(toks) < 1: - return - else: - self.target = toks[1] try: - dt_date.fromisoformat(toks[0]) + dt_date.fromisoformat(self.date) except ValueError: - self.errors += [f'not properly formatted legal date: {toks[0]}'] - else: - self.date = toks[0] + self.errors += [f'not properly formatted legal date: {self.date}'] @property def as_dict(self) -> dict: