(iso_string, strict=False)
parse datetime string in iso format with or without microseconds,
    always with both date and time
    and always with the 'Z' UTC timezone suffix

    return an offset-naive datetime representing UTC


    >>> iso_string_to_datetime('2015-04-07T19:07:55Z')
    datetime.datetime(2015, 4, 7, 19, 7, 55)
    >>> iso_string_to_datetime('2015-04-07T19:07:55.437086Z')
    datetime.datetime(2015, 4, 7, 19, 7, 55, 437086)
parse datetime string in iso format with or without microseconds,
    always with both date and time
    and always with the 'Z' UTC timezone suffix
parse datetime string in iso format with or without microseconds always with both date and time and always with the Z UTC timezone suffix
def iso_string_to_datetime(iso_string, strict=False):
    """
    parse datetime string in iso format with or without microseconds,
    always with both date and time
    and always with the 'Z' UTC timezone suffix

    return an offset-naive datetime representing UTC


    >>> iso_string_to_datetime('2015-04-07T19:07:55Z')
    datetime.datetime(2015, 4, 7, 19, 7, 55)
    >>> iso_string_to_datetime('2015-04-07T19:07:55.437086Z')
    datetime.datetime(2015, 4, 7, 19, 7, 55, 437086)

    """
    for fmt in ['%Y-%m-%dT%H:%M:%SZ', ISO_DATETIME_FORMAT]:
        try:
            return datetime.datetime.strptime(iso_string, fmt)
        except ValueError:
            pass

    if strict:
        raise ValueError('iso_string_to_datetime input not in expected format: {}'.format(iso_string))
    else:
        from dimagi.utils.parsing import string_to_utc_datetime
        return string_to_utc_datetime(iso_string)
def iso_string_to_datetime ( iso_string , strict = False ) : for fmt in [ '%Y-%m-%dT%H:%M:%SZ' , ISO_DATETIME_FORMAT ] : try : return datetime . datetime . strptime ( iso_string , fmt ) except ValueError : pass if strict : raise ValueError ( 'iso_string_to_datetime input not in expected format: {}' . format ( iso_string ) ) else : from dimagi . utils . parsing import string_to_utc_datetime return string_to_utc_datetime ( iso_string )