Coverage for /pythoncovmergedfiles/medio/medio/usr/local/lib/python3.8/site-packages/pendulum/tz/zoneinfo/transition.py: 48%
50 statements
« prev ^ index » next coverage.py v7.0.1, created at 2022-12-25 06:11 +0000
« prev ^ index » next coverage.py v7.0.1, created at 2022-12-25 06:11 +0000
1from datetime import timedelta
2from typing import Optional
4from .transition_type import TransitionType
7class Transition:
8 def __init__(
9 self,
10 at, # type: int
11 ttype, # type: TransitionType
12 previous, # type: Optional[Transition]
13 ):
14 self._at = at
16 if previous:
17 self._local = at + previous.ttype.offset
18 else:
19 self._local = at + ttype.offset
21 self._ttype = ttype
22 self._previous = previous
24 if self.previous:
25 self._fix = self._ttype.offset - self.previous.ttype.offset
26 else:
27 self._fix = 0
29 self._to = self._local + self._fix
30 self._to_utc = self._at + self._fix
31 self._utcoffset = timedelta(seconds=ttype.offset)
33 @property
34 def at(self): # type: () -> int
35 return self._at
37 @property
38 def local(self): # type: () -> int
39 return self._local
41 @property
42 def to(self): # type: () -> int
43 return self._to
45 @property
46 def to_utc(self): # type: () -> int
47 return self._to
49 @property
50 def ttype(self): # type: () -> TransitionType
51 return self._ttype
53 @property
54 def previous(self): # type: () -> Optional[Transition]
55 return self._previous
57 @property
58 def fix(self): # type: () -> int
59 return self._fix
61 def is_ambiguous(self, stamp): # type: (int) -> bool
62 return self._to <= stamp < self._local
64 def is_missing(self, stamp): # type: (int) -> bool
65 return self._local <= stamp < self._to
67 def utcoffset(self): # type: () -> timedelta
68 return self._utcoffset
70 def __contains__(self, stamp): # type: (int) -> bool
71 if self.previous is None:
72 return stamp < self.local
74 return self.previous.local <= stamp < self.local
76 def __repr__(self): # type: () -> str
77 return "Transition({} -> {}, {})".format(self._local, self._to, self._ttype)