MCPcopy Index your code
hub / github.com/python/cpython / _mktime

Method _mktime

Lib/_pydatetime.py:2018–2050  ·  view source on GitHub ↗

Return integer POSIX timestamp.

(self)

Source from the content-addressed store, hash-verified

2016 dst)
2017
2018 def _mktime(self):
2019 """Return integer POSIX timestamp."""
2020 epoch = datetime(1970, 1, 1)
2021 max_fold_seconds = 24 * 3600
2022 t = (self - epoch) // timedelta(0, 1)
2023 def local(u):
2024 y, m, d, hh, mm, ss = _time.localtime(u)[:6]
2025 return (datetime(y, m, d, hh, mm, ss) - epoch) // timedelta(0, 1)
2026
2027 # Our goal is to solve t = local(u) for u.
2028 a = local(t) - t
2029 u1 = t - a
2030 t1 = local(u1)
2031 if t1 == t:
2032 # We found one solution, but it may not be the one we need.
2033 # Look for an earlier solution (if `fold` is 0), or a
2034 # later one (if `fold` is 1).
2035 u2 = u1 + (-max_fold_seconds, max_fold_seconds)[self.fold]
2036 b = local(u2) - u2
2037 if a == b:
2038 return u1
2039 else:
2040 b = t1 - u1
2041 assert a != b
2042 u2 = t - b
2043 t2 = local(u2)
2044 if t2 == t:
2045 return u2
2046 if t1 == t:
2047 return u1
2048 # We have found both offsets a and b, but neither t - a nor t - b is
2049 # a solution. This means t is in the gap.
2050 return (max, min)[self.fold](u1, u2)
2051
2052
2053 def timestamp(self):

Callers 2

timestampMethod · 0.95
_local_timezoneMethod · 0.95

Calls 3

datetimeClass · 0.85
timedeltaClass · 0.85
localClass · 0.85

Tested by

no test coverage detected