Convert a time string to a time tuple.
426687
def parsedate(data):
    """"""
    t = parsedate_tz(data)
    if isinstance(t, tuple):
        return t[:9]
    else:
        return t
95446
def parse_time(t):
    
    if isinstance(t, (str, unicode)):
        b = re_time.match(t)
        if b:
            v, unit = int(b.group(1)), b.group(2)
            if unit == 's':
                return v*1000
            elif unit == 'm':
                return v*60*1000
            elif unit == 'h':
                return v*60*60*1000
            else:
                return v
        else:
            raise TimeFormatError(t)
    elif isinstance(t, (int, long)):
        return t
    else:
        raise TimeFormatError(t)
523891
def parse_date(date_str: str, pattern=_RE_DATE) -> dt.date:
    """"""

    groups = re.match(pattern, date_str)

    return dt.date(*_date_to_tuple(groups.groupdict()))
302225
def parse_value(self, value):
        """"""
        if value is None:
            return value
        if isinstance(value, datetime.time):
            return value
        return parse(value).timetz()
1344236
def from_str(duration):
    """"""

    if duration in ("0", "+0", "-0"):
        return datetime.timedelta()

    pattern = re.compile('([\d\.]+)([a-zµμ]+)')
    total = 0
    sign = -1 if duration[0] == '-' else 1
    matches = pattern.findall(duration)

    if not len(matches):
        raise Exception("Invalid duration {}".format(duration))

    for (value, unit) in matches:
        if unit not in units:
            raise Exception(
                "Unknown unit {} in duration {}".format(unit, duration))
        try:
            total += float(value) * units[unit]
        except:
            raise Exception(
                "Invalid value {} in duration {}".format(value, duration))

    microseconds = total / _microsecond_size
    return datetime.timedelta(microseconds=sign * microseconds)
814304
def ver_str_to_tuple(ver_str):
    """"""
    out = []
    for x in ver_str.split("."):
        try:
            x = int(x)
        except ValueError:
            pass
        out.append(x)
    return tuple(out)
1247575
def str_to_datetime(dt_str, fmt='%Y-%m-%d %H:%M:%S'):
    
    d_time = datetime.datetime.strptime(dt_str, fmt)
    return d_time
1259011
def _str_to_datetime(self, str_value):
        """"""
        try:
            ldt = [int(f) for f in str_value.split('-')]
            dt = datetime.datetime(*ldt)
        except (ValueError, TypeError):
            return None
        return dt
1161938
def simple_time(value):
    
    if isinstance(value, timedelta):
        return ':'.join(str(value).split(':')[:2])
    return datetime_to_string(value, '%H:%M')
468805
def string_to_data_time(d):
    '''
    
    '''
    if d:
        d = d.replace('/', '-')
        if ' ' in d:
            _datetime = d.split(' ')
            if len(_datetime) == 2:
                _d = _string_to_date(_datetime[0])
                _t = _string_to_time(_datetime[1])
                return _combine_date_time(_d, _t)
        else:
            # no space
            if '-' in d:
                return date_to_datetime(_string_to_date(d))
            elif ':' in d:
                return time_to_datetime(_string_to_time(d))
    return None
17495
def time(value):
    
    if isinstance(value, str):
        value = to_time(value)
    return literal(value, type=dt.time)
431047
def time2string(tstamp, micro=True):
    """"""
    tformat = TIME_FORMAT if micro else TIME_FORMAT[:-len(MICRO)]
    return tstamp.strftime(tformat)
1343856
def time_to_text(time):
    """"""
    
    if time < 0.001:
        return str(round(time * 1000000)) + " µs"
    elif time < 1:
        return str(round(time * 1000)) + " ms"
    elif time < 60:
        return str(round(time, 1)) + " s"
    else:
        return str(round(time / 60, 1)) + " min"
1101116
def parse(input):
    '''
    
    '''
    if isinstance(input, datetime):
        return input
    if isinstance(input, date):
        return date_to_datetime(input)
    if isinstance(input, time):
        return time_to_datetime(input)
    if isinstance(input, (int, float)):
        return timestamp_to_datetime(input)
    if isinstance(input, (str)):
        return string_to_data_time(input)
    return None
15606
def parse_time(time_input):
    
    if isinstance(time_input, datetime.date):
        return time_input.isoformat()  # datetime.date only returns date, datetime.datetime also returns time

    if len(time_input) < 8:
        raise ValueError('Invalid time string {}.\n'
                         'Please specify time in formats YYYY-MM-DD or YYYY-MM-DDTHH:MM:SS'.format(time_input))
    time = dateutil.parser.parse(time_input)
    if len(time_input) <= 10:
        return time.date().isoformat()
    return time.isoformat()
570366
def convert_time(time):
    """"""
    split_time = time.split()
    try:
        # Get rid of period in a.m./p.m.
        am_pm = split_time[1].replace('.', '')
        time_str = '{0} {1}'.format(split_time[0], am_pm)
    except IndexError:
        return time
    try:
        time_obj = datetime.strptime(time_str, '%I:%M %p')
    except ValueError:
        time_obj = datetime.strptime(time_str, '%I %p')

    return time_obj.strftime('%H:%M %p')
855241
def _ts_parse(ts):
    """"""
    dt = datetime.strptime(ts[:19],"%Y-%m-%dT%H:%M:%S")
    if ts[19] == '+':
        dt -= timedelta(hours=int(ts[20:22]),minutes=int(ts[23:]))
    elif ts[19] == '-':
        dt += timedelta(hours=int(ts[20:22]),minutes=int(ts[23:]))
    return dt.replace(tzinfo=pytz.UTC)