<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def parse_date(datestring):
 """Attepmts to parse an ISO8601 formatted ``datestring``. Returns a ``datetime.datetime`` object. """

    datestring = str(datestring).strip()

    if not datestring[0].isdigit():
        raise ParseError()

    if 'W' in datestring.upper():
        try:
            datestring = datestring[:-1] + str(int(datestring[-1:]) -1)
        except:
            pass

    for regex, pattern in DATE_FORMATS:
        if regex.match(datestring):
            found = regex.search(datestring).groupdict()
            dt = datetime.utcnow().strptime(found['matched'], pattern)

            if 'fraction' in found and found['fraction'] is not None:
                dt = dt.replace(microsecond=int(found['fraction'][1:]))

            if 'timezone' in found and found['timezone'] is not None:
                dt = dt.replace(tzinfo=Timezone(found.get('timezone', '')))

            return dt

    return parse_time(datestring)