Covert a timestamp string to an epoch number.
    :param str t_str: a timestamp string.
    :return int: epoch number of the timestamp.
355522
def to_epoch(t_str):
    
    try:
        t = float(t_str)
        return t
    except ValueError:
        for format in constants.TIMESTAMP_STR_FORMATS:
            try:
                t = datetime.datetime.strptime(t_str, format)
                return float(time.mktime(t.utctimetuple()) * 1000.0 + t.microsecond / 1000.0)
            except ValueError:
                pass
    raise exceptions.InvalidDataFormat
1295606
def timestamp(self, timestamp):
        
        clone = copy.deepcopy(self)
        clone._timestamp = timestamp
        return clone
138046
def to_timestamp(dt):
    
    if isinstance(dt, int):
        return dt
    return int(total_seconds(dt.replace(tzinfo=None) -
               datetime.datetime(1970, 1, 1)))
1173479
def get_min_from_t(self, timestamp):
        
        if self.is_time_valid(timestamp):
            return timestamp
        t_day_epoch = get_day(timestamp)
        tr_mins = self.get_min_sec_from_morning()
        return t_day_epoch + tr_mins
1223539
def T(t, step=30):
    
    if hasattr(t, 'timestamp'):
        timestamp = t.timestamp()
    else:
        # python 2
        if t.tzinfo is None:
            timestamp = time.mktime(t.timetuple())
        else:
            utc_naive  = t.replace(tzinfo=None) - t.utcoffset()
            timestamp = (utc_naive - datetime.datetime(1970, 1, 1)).total_seconds()

    return int(timestamp) // step
334467
def timestamp(num_params, p_levels, k_choices, N):
    
    string = "_v%s_l%s_gs%s_k%s_N%s_%s.txt" % (num_params,
                                               p_levels,
                                               k_choices,
                                               N,
                                               dt.strftime(dt.now(),
                                                           "%d%m%y%H%M%S"))
    return string
356731
def _str_parser(string):
        
        if not any(c.isalpha() for c in string):
            _string = string[:19]
            _length = len(_string)
            if _length > 10:
                return BaseParser.parse_datetime
            elif 6 <= _length <= 10:
                if ':' in _string:
                    return BaseParser.parse_time
                else:
                    return BaseParser.parse_date
            elif _length < 6:
                return BaseParser.parse_time
            else:
                return BaseParser.parse_special
        else:
            return BaseParser.__parse_not_only_str
312855
def datetime_from_timestamp(n, epoch=datetime.datetime.fromordinal(693594)):
    
    return epoch + datetime.timedelta(n)
425634
def _to_epoch(self, ts):
        

        year = self.year
        tmpts = "%s %s" % (ts, str(self.year))
        new_time = int(calendar.timegm(time.strptime(tmpts, "%b %d %H:%M:%S %Y")))

        # If adding the year puts it in the future, this log must be from last year
        if new_time > int(time.time()):
            year -= 1
            tmpts = "%s %s" % (ts, str(year))
            new_time = int(calendar.timegm(time.strptime(tmpts, "%b %d %H:%M:%S %Y")))

        return new_time
1140593
def date_to_timestamp(date):
    
    date_tuple = date.timetuple()
    timestamp = calendar.timegm(date_tuple) * 1000
    return timestamp
1109880
def version_str2tuple(cls, version_str):
        
        if not isinstance(version_str, str):
            ValueError('version_str invalid instance.')
        version_info_list = re.findall(r'[0-9a-zA-Z]+', version_str)

        def convert_to_int(string):
            value = None
            if re.match(r'^\d+$', string):
                value = int(string)
            else:
                value = string
            return value

        version_info_list = [convert_to_int(s) for s in version_info_list]

        return tuple(version_info_list)
1026100
def _parse_ftp_time(cls, time_text):
        # type: (Text) -> Optional[int]
        
        try:
            tm_year = int(time_text[0:4])
            tm_month = int(time_text[4:6])
            tm_day = int(time_text[6:8])
            tm_hour = int(time_text[8:10])
            tm_min = int(time_text[10:12])
            tm_sec = int(time_text[12:14])
        except ValueError:
            return None
        epoch_time = calendar.timegm(
            (tm_year, tm_month, tm_day, tm_hour, tm_min, tm_sec)
        )
        return epoch_time
861283
def _str_to_datetime(datestr):
    
    # try known string
    try:
        return DATE_STRINGS[str(datestr).lower()]()
    except KeyError:  # any other string
        pass

    # use maya
    try:
        import maya
        return maya.when(datestr).datetime()
    except ImportError:
        pass

    # use dateutil.parse
    with warnings.catch_warnings():
        # don't allow lazy passing of time-zones
        warnings.simplefilter("error", RuntimeWarning)
        try:
            return dateparser.parse(datestr)
        except RuntimeWarning:
            raise ValueError("Cannot parse date string with timezone "
                             "without maya, please install maya")
        except (ValueError, TypeError) as exc:  # improve error reporting
            exc.args = ("Cannot parse date string {0!r}: {1}".format(
                datestr, exc.args[0]),)
            raise
1282467
def session_to_epoch(timestamp):
    
    utc_timetuple = datetime.strptime(timestamp, SYNERGY_SESSION_PATTERN).replace(tzinfo=None).utctimetuple()
    return calendar.timegm(utc_timetuple)
892137
def get_timestamp(cls, time_string: str, fmt: str):
        
        return int(time.mktime(time.strptime(time_string, fmt)))
779310
def pad_timestamp(string, pad_str=PAD_6_UP):
    

    str_len = len(string)
    pad_len = len(pad_str)

    if str_len < pad_len:
        string = string + pad_str[str_len:]

    return string
1061780
def convert_time_string(date_str):
    
    dt, _, _ = date_str.partition(".")
    dt = datetime.strptime(dt, "%Y-%m-%dT%H:%M:%S")
    return dt