Skip to content

Commit

Permalink
Fixed parsing ICS PDF statements on leap year
Browse files Browse the repository at this point in the history
It was crashing due to "29 feb".
  • Loading branch information
denilsonsa committed Jun 9, 2024
1 parent 11b5be3 commit 9fa47a5
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions src/abnamroparser/icspdfparser.py
Original file line number Diff line number Diff line change
Expand Up @@ -381,13 +381,34 @@ def convert_date(self, text):
datetime.date(2023, 4, 8)
>>> page.convert_date("8 apr")
datetime.date(2023, 4, 8)
# Leap year
>>> page = Page(1)
>>> page.date = datetime.date(2024, 1, 1)
>>> page.convert_date("29 feb")
datetime.date(2024, 2, 29)
# Leap year
>>> page = Page(1)
>>> page.date = datetime.date(2024, 4, 1)
>>> page.convert_date("29 feb")
datetime.date(2024, 2, 29)
"""
dd, mmm = text.split()
d = int(dd)
m = MONTHS_SHORT[mmm]

y1 = self.date.year
y2 = self.date.year - 1

# Leap year
if d == 29 and m == 2:
for y in [y1, y2]:
try:
return datetime.date(y, m, d)
except ValueError:
pass

dt1 = datetime.date(y1, m, d)
dt2 = datetime.date(y2, m, d)

Expand Down

0 comments on commit 9fa47a5

Please # to comment.