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

Class LocalTimezone

Doc/includes/tzinfo_examples.py:22–55  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

20
21
22class LocalTimezone(dt.tzinfo):
23
24 def fromutc(self, when):
25 assert when.tzinfo is self
26 stamp = (when - dt.datetime(1970, 1, 1, tzinfo=self)) // SECOND
27 args = time.localtime(stamp)[:6]
28 dst_diff = DSTDIFF // SECOND
29 # Detect fold
30 fold = (args == time.localtime(stamp - dst_diff))
31 return dt.datetime(*args, microsecond=when.microsecond,
32 tzinfo=self, fold=fold)
33
34 def utcoffset(self, when):
35 if self._isdst(when):
36 return DSTOFFSET
37 else:
38 return STDOFFSET
39
40 def dst(self, when):
41 if self._isdst(when):
42 return DSTDIFF
43 else:
44 return ZERO
45
46 def tzname(self, when):
47 return time.tzname[self._isdst(when)]
48
49 def _isdst(self, when):
50 tt = (when.year, when.month, when.day,
51 when.hour, when.minute, when.second,
52 when.weekday(), 0, 0)
53 stamp = time.mktime(tt)
54 tt = time.localtime(stamp)
55 return tt.tm_isdst > 0
56
57
58Local = LocalTimezone()

Callers 1

tzinfo_examples.pyFile · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…