Convert SubRipTime instance into a pure datetime.time object
762554
def to_time(self):
        
        return time(self.hours, self.minutes, self.seconds,
                    self.milliseconds * 1000)
487975
def _strptime(self, time_str):
        """"""
        if time_str:
            # Parse UTC string into naive datetime, then add timezone
            dt = datetime.strptime(time_str, __timeformat__)
            return dt.replace(tzinfo=UTC())
        return None
1218597
def _make_datetime(s):
    """
    s = bytearray(s)  # For Python 2
    year, month, day, hour, minute, second, cs = s
    if year < 70:
        year += 100
    return datetime(1900 + year, month, day, hour, minute, second, 10000 * cs)
644112
def timestamp_to_datetime(timestamp):
    """"""
    from datetime import datetime, timedelta
    obj = datetime.fromtimestamp(timestamp[0])
    return obj + timedelta(microseconds=int(timestamp[1]))
354786
def datetime(anon, obj, field, val):
    
    return anon.faker.datetime(field=field)
88016
def to_pydatetime(self):
        
        return datetime.datetime.combine(self._date.to_pydate(), self._time.to_pytime())
192539
def datetime2ole(dt):
    """"""
    delta = dt - OLE_TIME_ZERO
    delta_float = delta / datetime.timedelta(days=1)  # trick from SO
    return delta_float
1285226
def utcnow(cls):
    """"""
    obj = datetime.datetime.utcnow()
    obj = cls(obj, tzinfo=pytz.utc)
    return obj
1036733
def parse_time(s):
    
    result = None

    if "epoch" in s:
        epoch_time = float(s.rstrip().split(' ')[1][:-1])
        result = datetime.datetime.utcfromtimestamp(epoch_time)
    else:
        _, date_part, time_part = s.split(' ')
        year, mon, day = date_part.split('/')
        hour, minute, sec = time_part.split(':')
        result = datetime.datetime(*map(int, (year, mon, day, hour, minute, sec)))

    return result
260784
def round_to_specified_time(self, a_datetime, hour, minute, second, mode="lower"):
        
        mode = mode.lower()
        
        new_datetime = datetime(a_datetime.year, a_datetime.month, a_datetime.day,
                                hour, minute, second)
        if mode == "lower": 
            if new_datetime <= a_datetime:
                return new_datetime
            else:
                return timewrapper.add_days(new_datetime, -1)
        elif mode == "upper":
            if new_datetime >= a_datetime:
                return new_datetime
            else:
                return timewrapper.add_days(new_datetime, 1)
        else:
            raise ValueError("'mode' has to be lower or upper!")
401007
def from_datetime(dt, machine_id=0):
        
        td = dt - Timestamp._EPOCH
        seconds = td.days * 3600 * 24
        seconds += td.seconds
        return Timestamp(seconds, td.microseconds*1000, machine_id)
808562
def ToTimedelta(self):
    """"""
    return timedelta(
        seconds=self.seconds, microseconds=_RoundTowardZero(
            self.nanos, _NANOS_PER_MICROSECOND))
1045962
def asdatetime(self, naive=True):
    
    args = list(self.timetuple()[0:6])+[self.microsecond]
    if not naive:
      args.append(self.tzinfo)
    return datetime.datetime(*args)
1144068
def timestamp_to_datetime(response):
    ""
    if not response:
        return None
    try:
        response = int(response)
    except ValueError:
        return None
    return datetime.datetime.fromtimestamp(response)
1216892
def _convert_time(self, time_str):
        
        dt = datetime.strptime(time_str, "%Y-%m-%dT%H:%M:%SZ")
        return int(time.mktime(dt.utctimetuple()))
569167
def time_to_datetime(x):
    """"""
    if isinstance(x, time):
        return datetime.combine(date(1970, 1, 1), x)
    return x
751708
def clean_time(sltime, in_format='%Y-%m-%dT%H:%M:%S%z', out_format='%Y-%m-%d %H:%M'):
    
    try:
        clean = datetime.datetime.strptime(sltime, in_format)
        return clean.strftime(out_format)
    # The %z option only exists with py3.6+
    except ValueError:
        return sltime