blob: 7c6b2f70c008cb9d801f127ae4785a7146392abf (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
|
from datetime import timedelta
from typing import Optional
from .transition_type import TransitionType
class Transition:
def __init__(
self,
at, # type: int
ttype, # type: TransitionType
previous, # type: Optional[Transition]
):
self._at = at
if previous:
self._local = at + previous.ttype.offset
else:
self._local = at + ttype.offset
self._ttype = ttype
self._previous = previous
if self.previous:
self._fix = self._ttype.offset - self.previous.ttype.offset
else:
self._fix = 0
self._to = self._local + self._fix
self._to_utc = self._at + self._fix
self._utcoffset = timedelta(seconds=ttype.offset)
@property
def at(self): # type: () -> int
return self._at
@property
def local(self): # type: () -> int
return self._local
@property
def to(self): # type: () -> int
return self._to
@property
def to_utc(self): # type: () -> int
return self._to
@property
def ttype(self): # type: () -> TransitionType
return self._ttype
@property
def previous(self): # type: () -> Optional[Transition]
return self._previous
@property
def fix(self): # type: () -> int
return self._fix
def is_ambiguous(self, stamp): # type: (int) -> bool
return self._to <= stamp < self._local
def is_missing(self, stamp): # type: (int) -> bool
return self._local <= stamp < self._to
def utcoffset(self): # type: () -> timedelta
return self._utcoffset
def __contains__(self, stamp): # type: (int) -> bool
if self.previous is None:
return stamp < self.local
return self.previous.local <= stamp < self.local
def __repr__(self): # type: () -> str
return "Transition({} -> {}, {})".format(self._local, self._to, self._ttype)
|