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

Class _TZStr

Lib/zoneinfo/_zoneinfo.py:425–511  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

423
424
425class _TZStr:
426 __slots__ = (
427 "std",
428 "dst",
429 "start",
430 "end",
431 "get_trans_info",
432 "get_trans_info_fromutc",
433 "dst_diff",
434 )
435
436 def __init__(
437 self, std_abbr, std_offset, dst_abbr, dst_offset, start=None, end=None
438 ):
439 self.dst_diff = dst_offset - std_offset
440 std_offset = _load_timedelta(std_offset)
441 self.std = _ttinfo(
442 utcoff=std_offset, dstoff=_load_timedelta(0), tzname=std_abbr
443 )
444
445 self.start = start
446 self.end = end
447
448 dst_offset = _load_timedelta(dst_offset)
449 delta = _load_timedelta(self.dst_diff)
450 self.dst = _ttinfo(utcoff=dst_offset, dstoff=delta, tzname=dst_abbr)
451
452 # These are assertions because the constructor should only be called
453 # by functions that would fail before passing start or end
454 assert start is not None, "No transition start specified"
455 assert end is not None, "No transition end specified"
456
457 self.get_trans_info = self._get_trans_info
458 self.get_trans_info_fromutc = self._get_trans_info_fromutc
459
460 def transitions(self, year):
461 start = self.start.year_to_epoch(year)
462 end = self.end.year_to_epoch(year)
463 return start, end
464
465 def _get_trans_info(self, ts, year, fold):
466 """Get the information about the current transition - tti"""
467 start, end = self.transitions(year)
468
469 # With fold = 0, the period (denominated in local time) with the
470 # smaller offset starts at the end of the gap and ends at the end of
471 # the fold; with fold = 1, it runs from the start of the gap to the
472 # beginning of the fold.
473 #
474 # So in order to determine the DST boundaries we need to know both
475 # the fold and whether DST is positive or negative (rare), and it
476 # turns out that this boils down to fold XOR is_positive.
477 if fold == (self.dst_diff >= 0):
478 end -= self.dst_diff
479 else:
480 start += self.dst_diff
481
482 if start < end:

Callers 1

_parse_tz_strFunction · 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…