'Read time from a single string, using a set of possible formats.'

def parse_string(self, timestr, subfmts):

    components = (u'year', u'mon', u'mday', u'hour', u'min', u'sec')
    defaults = (None, 1, 1, 0, 0, 0)
    try:
        idot = timestr.rindex(u'.')
    except Exception:
        fracsec = 0.0
    else:
        (timestr, fracsec) = (timestr[:idot], timestr[idot:])
        fracsec = float(fracsec)
    for (_, strptime_fmt_or_regex, _) in subfmts:
        if isinstance(strptime_fmt_or_regex, six.string_types):
            try:
                tm = time.strptime(timestr, strptime_fmt_or_regex)
            except ValueError:
                continue
            else:
                vals = [getattr(tm, (u'tm_' + component)) for component in components]
        else:
            tm = re.match(strptime_fmt_or_regex, timestr)
            if (tm is None):
                continue
            tm = tm.groupdict()
            vals = [int(tm.get(component, default)) for (component, default) in zip(components, defaults)]
        vals[(-1)] = (vals[(-1)] + fracsec)
        return vals
    else:
        raise ValueError(u'Time    {0}    does    not    match    {1}    format'.format(timestr, self.name))
