# Path: athlib/uka/agegroups.py
# def calc_uka_age_group(birth_date,
#                        match_date,
#                        category,
#                        vets=True,
#                        underage=False):
#     """Return UKA age group"""
#     if category == 'TF':
#         return rule107_agegroups_trackandfield(birth_date,
#                                                match_date,
#                                                vets=vets,
#                                                underage=underage)
#     elif category in ['ROAD', 'XC']:
#         return rule507_agegroups_crosscountry(birth_date,
#                                               match_date,
#                                               vets=vets,
#                                               underage=underage)
#     elif category == 'ESAA':
#         # Apparently the English Schools has its own rule, but we haven't done
#         # this yet. If still here, raise an exception
#         raise NotImplementedError
#     else:
#         raise ValueError("category must be one of:  TF, ROAD, XC, ESAA")
# 
# def prior_date(match_date, cutoff_month, cutoff_day):
#     """
#     Count back to relevant date.
#     e.g. find the 31st August prior to match date
#     """
#     y = match_date.year
#     m = match_date.month
#     d = match_date.day
#     x = date(y, cutoff_month, cutoff_day)
#     if x > match_date:
#         x = date(y - 1, cutoff_month, cutoff_day)
#     return x


from dateutil.parser import parse as parse_date
from datetime import date
from unittest import TestCase, main
from athlib.uka.agegroups import calc_uka_age_group, prior_date
            1/1/2004    14/2/2015   U13
            31/8/2004   14/2/2015   U13
            1/9/2004    14/2/2015   U11
            30/9/2004   14/2/2015   U11
            1/10/2004   14/2/2015   U11
            31/12/2004  14/2/2015   U11

            1/1/2005    14/2/2015   U11
            31/8/2005   14/2/2015   U11
            1/9/2005    14/2/2015   U11
            30/9/2005   14/2/2015   U11
            1/10/2005   14/2/2015   U11
            31/12/2005  14/2/2015   U11
            """
        failures = 0
        messages = []

        for line in samples.strip().split('\n'):
            trimmed = line.strip()

            if not trimmed:
                continue

            if trimmed.startswith('#'):
                continue

            txtdob, txtmatch, expected = trimmed.split()
            date_of_birth = parse_date(txtdob, dayfirst=True).date()
            match_date = parse_date(txtmatch, dayfirst=True).date()


# Path: athlib/uka/agegroups.py
# def calc_uka_age_group(birth_date,
#                        match_date,
#                        category,
#                        vets=True,
#                        underage=False):
#     """Return UKA age group"""
#     if category == 'TF':
#         return rule107_agegroups_trackandfield(birth_date,
#                                                match_date,
#                                                vets=vets,
#                                                underage=underage)
#     elif category in ['ROAD', 'XC']:
#         return rule507_agegroups_crosscountry(birth_date,
#                                               match_date,
#                                               vets=vets,
#                                               underage=underage)
#     elif category == 'ESAA':
#         # Apparently the English Schools has its own rule, but we haven't done
#         # this yet. If still here, raise an exception
#         raise NotImplementedError
#     else:
#         raise ValueError("category must be one of:  TF, ROAD, XC, ESAA")
# 
# def prior_date(match_date, cutoff_month, cutoff_day):
#     """
#     Count back to relevant date.
#     e.g. find the 31st August prior to match date
#     """
#     y = match_date.year
#     m = match_date.month
#     d = match_date.day
#     x = date(y, cutoff_month, cutoff_day)
#     if x > match_date:
#         x = date(y - 1, cutoff_month, cutoff_day)
#     return x


# Path: tests/test_agegroups.py
from dateutil.parser import parse as parse_date
from datetime import date
from unittest import TestCase, main
from athlib.uka.agegroups import calc_uka_age_group, prior_date

            1/1/2004    14/2/2015   U13
            31/8/2004   14/2/2015   U13
            1/9/2004    14/2/2015   U11
            30/9/2004   14/2/2015   U11
            1/10/2004   14/2/2015   U11
            31/12/2004  14/2/2015   U11

            1/1/2005    14/2/2015   U11
            31/8/2005   14/2/2015   U11
            1/9/2005    14/2/2015   U11
            30/9/2005   14/2/2015   U11
            1/10/2005   14/2/2015   U11
            31/12/2005  14/2/2015   U11
            """
        failures = 0
        messages = []

        for line in samples.strip().split('\n'):
            trimmed = line.strip()

            if not trimmed:
                continue

            if trimmed.startswith('#'):
                continue

            txtdob, txtmatch, expected = trimmed.split()
            date_of_birth = parse_date(txtdob, dayfirst=True).date()
            match_date = parse_date(txtmatch, dayfirst=True).date()


            ag = calc_uka_age_group(date_of_birth, match_date, "TF")