home · contact · privacy
Fix handling of erroneous date fields. master
authorChristian Heller <c.heller@plomlompom.de>
Wed, 29 Jan 2025 02:41:56 +0000 (03:41 +0100)
committerChristian Heller <c.heller@plomlompom.de>
Wed, 29 Jan 2025 02:41:56 +0000 (03:41 +0100)
ledger.py

index 0c6ed5eccd78541a3808b74c113a489a8b15fe35..ebb188f0c040a30dec11aaae34b5e95dbdc77060 100755 (executable)
--- a/ledger.py
+++ b/ledger.py
@@ -144,23 +144,17 @@ class IntroLine(BookingLine):
 
     def __init__(self, booking: 'Booking', code: str) -> None:
         super().__init__(booking)
 
     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 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']
             self.errors += ['illegal number of tokens']
-        elif len(toks) < 1:
-            return
-        else:
-            self.target = toks[1]
         try:
         try:
-            dt_date.fromisoformat(toks[0])
+            dt_date.fromisoformat(self.date)
         except ValueError:
         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:
 
     @property
     def as_dict(self) -> dict: