def parse_date(self, date_str):
    """Try to parse date from string."""
    date = None
    try:
      if len(date_str) == 4:
        date = datetime.datetime.strptime(date_str, '%Y')
      elif len(date_str) == 6:
        date = datetime.datetime.strptime(date_str, '%Y%m')
      elif len(date_str) == 8:
        date = datetime.datetime.strptime(date_str, '%Y%m%d')
    except ValueError:
      pass
    if date is not None and date.year > 2100:
      # Likely an error
      date = None
    return date
Try to parse date from string.
language/templama/sling2facts.py