Skip to content

Commit

Permalink
Validate leap year dates correctly
Browse files Browse the repository at this point in the history
  • Loading branch information
dannyhajj committed Nov 8, 2023
1 parent 85154b7 commit 7ea1ab3
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions personnummer/personnummer.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,11 @@ def is_male(self):
return int(gender_digit) % 2 != 0

def is_coordination_number(self):
return test_date(int(self.parts['year']), int(self.parts['month']), int(self.parts['day']) - 60)
return test_date(
int(self.parts['century'] + self.parts['year']),
int(self.parts['month']),
int(self.parts['day']) - 60,
)

@staticmethod
def get_parts(ssn):
Expand Down Expand Up @@ -133,6 +137,7 @@ def valid(self):
:return:
"""

century = self.parts['century']
year = self.parts['year']
month = self.parts['month']
day = self.parts['day']
Expand All @@ -144,10 +149,10 @@ def valid(self):

is_valid = luhn(year + month + day + num) == int(check)

if is_valid and test_date(int(year), int(month), int(day)):
if is_valid and test_date(int(century + year), int(month), int(day)):
return True

return is_valid and test_date(int(year), int(month), int(day) - 60)
return is_valid and test_date(int(century + year), int(month), int(day) - 60)


def luhn(data):
Expand Down

0 comments on commit 7ea1ab3

Please sign in to comment.