Coverage for scheduler/trigger/core.py: 100%
50 statements
« prev ^ index » next coverage.py v7.6.10, created at 2026-02-11 03:21 +0000
« prev ^ index » next coverage.py v7.6.10, created at 2026-02-11 03:21 +0000
1"""
2Trigger implementations.
4Author: Jendrik A. Potyka, Fabian A. Preiss
5"""
7import datetime as dt
8from abc import ABC, abstractmethod
9from typing import Union
12class Weekday(ABC):
13 """
14 |Weekday| object with time.
16 Parameters
17 ----------
18 time : datetime.time
19 Time on the clock at the specific |Weekday|.
20 """
22 __value: int
23 __time: dt.time
25 @abstractmethod
26 def __init__(self, time: dt.time, value: int) -> None:
27 """|Weekday| object with time."""
28 self.__time = time
29 self.__value = value
31 def __repr__(self) -> str:
32 return f"{self.__class__.__qualname__}(time={self.time!r})"
34 @property
35 def time(self) -> dt.time:
36 """
37 Return time of the |Weekday|.
39 Returns
40 -------
41 datetime.time
42 Time on the clock at the specific |Weekday|.
43 """
44 return self.__time
46 @property
47 def value(self) -> int:
48 """
49 Return value of the given |Weekday|.
51 Notes
52 -----
53 Enumeration analogous to datetime library (0: Monday, ... 6: Sunday).
55 Returns
56 -------
57 int
58 Value
59 """
60 return self.__value
63# NOTE: pylint missing-class-docstring is just silly here, given functionality and usuage of parent
64class Monday(Weekday): # pylint: disable=missing-class-docstring # noqa: D101
65 __doc__ = Weekday.__doc__
67 def __init__(self, time: dt.time = dt.time()) -> None:
68 super().__init__(time, 0)
71class Tuesday(Weekday): # pylint: disable=missing-class-docstring # noqa: D101
72 __doc__ = Weekday.__doc__
74 def __init__(self, time: dt.time = dt.time()) -> None:
75 super().__init__(time, 1)
78class Wednesday(Weekday): # pylint: disable=missing-class-docstring # noqa: D101
79 __doc__ = Weekday.__doc__
81 def __init__(self, time: dt.time = dt.time()) -> None:
82 super().__init__(time, 2)
85class Thursday(Weekday): # pylint: disable=missing-class-docstring # noqa: D101
86 __doc__ = Weekday.__doc__
88 def __init__(self, time: dt.time = dt.time()) -> None:
89 super().__init__(time, 3)
92class Friday(Weekday): # pylint: disable=missing-class-docstring # noqa: D101
93 __doc__ = Weekday.__doc__
95 def __init__(self, time: dt.time = dt.time()) -> None:
96 super().__init__(time, 4)
99class Saturday(Weekday): # pylint: disable=missing-class-docstring # noqa: D101
100 __doc__ = Weekday.__doc__
102 def __init__(self, time: dt.time = dt.time()) -> None:
103 super().__init__(time, 5)
106class Sunday(Weekday): # pylint: disable=missing-class-docstring # noqa: D101
107 __doc__ = Weekday.__doc__
109 def __init__(self, time: dt.time = dt.time()) -> None:
110 super().__init__(time, 6)
113_Weekday = Union[Monday, Tuesday, Wednesday, Thursday, Friday, Saturday, Sunday]
115_weekday_mapping: dict[int, type[_Weekday]] = {
116 0: Monday,
117 1: Tuesday,
118 2: Wednesday,
119 3: Thursday,
120 4: Friday,
121 5: Saturday,
122 6: Sunday,
123}
126def weekday(value: int, time: dt.time = dt.time()) -> Weekday:
127 """
128 Return |Weekday| from given value with optional time.
130 Notes
131 -----
132 Enumeration analogous to datetime library (0: Monday, ... 6: Sunday).
134 Parameters
135 ----------
136 value : int
137 Integer representation of |Weekday|
138 time : datetime.time
139 Time on the clock at the specific weekday.
141 Returns
142 -------
143 Weekday
144 |Weekday| object with given time.
145 """
146 weekday_cls: type[_Weekday] = _weekday_mapping[value]
147 weekday_instance = weekday_cls(time)
148 return weekday_instance