Skip to content

Commit

Permalink
Add handling for finnish ssn where min_age and max_age are the sa…
Browse files Browse the repository at this point in the history
…me (#1937)

Co-authored-by: Antti Pakkanen <antti@simplr.fi>
  • Loading branch information
Pakkanen1 and Antti Pakkanen authored Oct 23, 2023
1 parent 468131a commit fc42e6a
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
5 changes: 4 additions & 1 deletion faker/providers/ssn/fi_FI/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,10 @@ def _checksum(hetu):
checksum_characters = "0123456789ABCDEFHJKLMNPRSTUVWXY"
return checksum_characters[int(hetu) % 31]

age = datetime.timedelta(days=self.generator.random.randrange(min_age * 365, max_age * 365))
if min_age == max_age:
age = datetime.timedelta(days=min_age * 365)
else:
age = datetime.timedelta(days=self.generator.random.randrange(min_age * 365, max_age * 365))
birthday = datetime.date.today() - age
hetu_date = "%02d%02d%s" % (
birthday.day,
Expand Down
12 changes: 12 additions & 0 deletions tests/providers/test_ssn.py
Original file line number Diff line number Diff line change
Expand Up @@ -793,6 +793,18 @@ def test_vat_id(self):
for _ in range(100):
assert re.search(r"^FI\d{8}$", self.fake.vat_id())

def test_ssn_without_age_range(self):
current_year = datetime.now().year
age = current_year - 1995
ssn = self.fake.ssn(min_age=age, max_age=age, artificial=True)
assert "95-" in ssn
age = current_year - 2013
ssn = self.fake.ssn(min_age=age, max_age=age, artificial=True)
assert "13A" in ssn
age = current_year - 1898
ssn = self.fake.ssn(min_age=age, max_age=age, artificial=True)
assert "98+" in ssn


class TestFrFR(unittest.TestCase):
def setUp(self):
Expand Down

0 comments on commit fc42e6a

Please sign in to comment.