clock-pattern 0.2.0__tar.gz → 0.3.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: clock-pattern
3
- Version: 0.2.0
3
+ Version: 0.3.0
4
4
  Summary: The Clock Pattern is a Python package that turns time into an injectable dependency.
5
5
  Project-URL: Homepage, https://github.com/adriamontoto/clock-pattern
6
6
  Project-URL: Repository, https://github.com/adriamontoto/clock-pattern
@@ -0,0 +1 @@
1
+ __version__ = '0.3.0'
@@ -0,0 +1,3 @@
1
+ from .fixed_clock import FixedClock
2
+
3
+ __all__ = ('FixedClock',)
@@ -0,0 +1,111 @@
1
+ """
2
+ FixedClock module.
3
+ """
4
+
5
+ from sys import version_info
6
+
7
+ if version_info >= (3, 12):
8
+ from typing import override # pragma: no cover
9
+ else:
10
+ from typing_extensions import override # pragma: no cover
11
+
12
+ from datetime import UTC, date, datetime
13
+
14
+ from value_object_pattern.usables.dates import DatetimeValueObject
15
+
16
+ from clock_pattern.models.clock import Clock
17
+
18
+
19
+ class FixedClock(Clock):
20
+ """
21
+ MockModel is responsible for retrieving the date/datetime provided when `FixedClock` initialization. Use `MockClock`
22
+ for better testing features.
23
+
24
+ Example:
25
+ ```python
26
+ from datetime import datetime
27
+
28
+ from clock_pattern.clocks.testing import FixedClock
29
+
30
+ fixed_datetime = datetime(year=1999, month=1, day=1)
31
+ clock = FixedClock(instant=fixed_datetime)
32
+ print(clock.now())
33
+ # >>> 1999-01-01 00:00:00+00:00
34
+ ```
35
+ """
36
+
37
+ _instant: datetime
38
+
39
+ def __init__(self, *, instant: datetime) -> None:
40
+ """
41
+ FixedClock constructor is used to provided which date/datetime `instance` will be retrieved. If the provided
42
+ datetime `instant` has not timezone UTC will be set.
43
+
44
+ Args:
45
+ instant (datetime): The datetime that will be retrieved.
46
+
47
+ Raises:
48
+ ValueError: If `instant` is not of type datetime.
49
+
50
+ Example:
51
+ ```python
52
+ from datetime import datetime
53
+
54
+ from clock_pattern.clocks.testing import FixedClock
55
+
56
+ fixed_datetime = datetime(year=1999, month=1, day=1)
57
+ clock = FixedClock(instant=fixed_datetime)
58
+ print(clock.now())
59
+ # >>> 1999-01-01 00:00:00+00:00
60
+ ```
61
+ """
62
+ DatetimeValueObject(value=instant, title='FixedClock', parameter='instant')
63
+
64
+ if instant.tzinfo is None:
65
+ instant = instant.replace(tzinfo=UTC)
66
+
67
+ self._instant = instant
68
+
69
+ @override
70
+ def now(self) -> datetime:
71
+ """
72
+ Retrieve the current datetime (now).
73
+
74
+ Returns:
75
+ datetime: The current datetime.
76
+
77
+ Example:
78
+ ```python
79
+ from datetime import datetime
80
+
81
+ from clock_pattern.clocks.testing import FixedClock
82
+
83
+ fixed_datetime = datetime(year=1999, month=1, day=1)
84
+ clock = FixedClock(instant=fixed_datetime)
85
+ print(clock.now())
86
+ # >>> 1999-01-01 00:00:00+00:00
87
+ ```
88
+ """
89
+ return self._instant
90
+
91
+ @override
92
+ def today(self) -> date:
93
+ """
94
+ Retrieve the current date (today).
95
+
96
+ Returns:
97
+ date: The current date.
98
+
99
+ Example:
100
+ ```python
101
+ from datetime import datetime
102
+
103
+ from clock_pattern.clocks.testing import FixedClock
104
+
105
+ fixed_datetime = datetime(year=1999, month=1, day=1)
106
+ clock = FixedClock(instant=fixed_datetime)
107
+ print(clock.today())
108
+ # >>> 1999-01-01
109
+ ```
110
+ """
111
+ return self._instant.date()
@@ -1 +0,0 @@
1
- __version__ = '0.2.0'
File without changes
File without changes
File without changes