Did I find the right examples for you? yes no

All Samples(6)  |  Call(4)  |  Derive(0)  |  Import(2)
Validates the birth_day and returns the datetime.date object for
the birth_day.

If the date is an invalid birth day, a ValueError will be raised.

        def validate_id_birthday(gd, fix_coordination_number_day=True):
    """
    Validates the birth_day and returns the datetime.date object for
    the birth_day.

    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

    if gd['century'] is None:

        # The century was not specified, and need to be calculated from todays date
        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

        # If the person is older than 100 years
        if gd['sign'] == '+':
            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
        


src/d/j/django-localflavor-1.0/localflavor/se/forms.py   django-localflavor(Download)
from django.core.validators import EMPTY_VALUES
from .se_counties import COUNTY_CHOICES
from .utils import (id_number_checksum, validate_id_birthday,
                    format_personal_id_number, valid_organisation, format_organisation_number)
 
        # Is this a single properitor (enskild firma)?
        try:
            birth_day = validate_id_birthday(gd, False)
            return format_personal_id_number(birth_day, gd)
        except ValueError:
        # check for valid birthday
        try:
            birth_day = validate_id_birthday(gd)
        except ValueError:
            raise forms.ValidationError(self.error_messages['invalid'])

src/d/j/django-localflavor-HEAD/localflavor/se/forms.py   django-localflavor(Download)
from django.core.validators import EMPTY_VALUES
from .se_counties import COUNTY_CHOICES
from .utils import (id_number_checksum, validate_id_birthday,
                    format_personal_id_number, valid_organisation, format_organisation_number)
 
        # Is this a single properitor (enskild firma)?
        try:
            birth_day = validate_id_birthday(gd, False)
            return format_personal_id_number(birth_day, gd)
        except ValueError:
        # check for valid birthday
        try:
            birth_day = validate_id_birthday(gd)
        except ValueError:
            raise forms.ValidationError(self.error_messages['invalid'])