Permalink
Browse files

Converted Swedish localflavor tests from doctests to unittests. Thank…

…s, Idan Gazit!

git-svn-id: http://code.djangoproject.com/svn/django/trunk@15057 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
1 parent 2ea93f9 commit 3e00cf1f09b9fe6099f60212aaa1ad6b934f65c8 @jezdez jezdez committed Dec 26, 2010
@@ -12,7 +12,7 @@ def id_number_checksum(gd):
if tmp > 9:
tmp = sum([int(i) for i in str(tmp)])
-
+
s += tmp
n += 1
@@ -28,9 +28,9 @@ def validate_id_birthday(gd, fix_coordination_number_day=True):
If the date is an invalid birth day, a ValueError will be raised.
"""
-
+
today = datetime.date.today()
-
+
day = int(gd['day'])
if fix_coordination_number_day and day > 60:
day -= 60
@@ -40,7 +40,7 @@ def validate_id_birthday(gd, fix_coordination_number_day=True):
# The century was not specified, and need to be calculated from todays date
current_year = today.year
year = int(today.strftime('%Y')) - int(today.strftime('%y')) + int(gd['year'])
-
+
if ('%s%s%02d' % (gd['year'], gd['month'], day)) > today.strftime('%y%m%d'):
year -= 100
@@ -49,19 +49,19 @@ def validate_id_birthday(gd, fix_coordination_number_day=True):
year -= 100
else:
year = int(gd['century'] + gd['year'])
-
+
# Make sure the year is valid
# There are no swedish personal identity numbers where year < 1800
if year < 1800:
raise ValueError
# ValueError will be raise for invalid dates
birth_day = datetime.date(year, int(gd['month']), day)
-
+
# birth_day must not be in the future
if birth_day > today:
raise ValueError
-
+
return birth_day
def format_personal_id_number(birth_day, gd):
Oops, something went wrong. Retry.

0 comments on commit 3e00cf1

Please sign in to comment.