def time_ago_to_date(value):
today = datetime.date.today()<EOL>if value == '<STR_LIT>':<EOL><INDENT>return today<EOL><DEDENT>elif value == '<STR_LIT>':<EOL><INDENT>return today - datetime.timedelta(days=<NUM_LIT:1>)<EOL><DEDENT>time_ago = re.match(r'<STR_LIT>', value)<EOL>if time_ago:<EOL><INDENT>duration, unit = int(time_ago.group(<NUM_LIT:1>)), time_ago.group(<NUM_LIT:2>)<EOL>if '<STR_LIT>' in unit:<EOL><INDENT>return today - datetime.timedelta(days=duration)<EOL><DEDENT>elif '<STR_LIT>' in unit:<EOL><INDENT>return today - datetime.timedelta(weeks=duration)<EOL><DEDENT>elif '<STR_LIT>' in unit:<EOL><INDENT>return months_ago(today, duration)<EOL><DEDENT>elif '<STR_LIT>' in unit:<EOL><INDENT>return today.replace(year=today.year - duration)<EOL><DEDENT><DEDENT>return datetime.datetime.strptime(value, '<STR_LIT>').date()<EOL>
Parse a date and return it as ``datetime.date`` objects. Examples of valid dates:

    * Relative: 2 days ago, today, yesterday, 1 week ago
    * Absolute: 25.10.2017