infdate 0.2.3__py3-none-any.whl → 0.2.5__py3-none-any.whl
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.
- infdate/__init__.py +33 -13
- {infdate-0.2.3.dist-info → infdate-0.2.5.dist-info}/METADATA +16 -7
- infdate-0.2.5.dist-info/RECORD +6 -0
- infdate-0.2.3.dist-info/RECORD +0 -6
- {infdate-0.2.3.dist-info → infdate-0.2.5.dist-info}/WHEEL +0 -0
- {infdate-0.2.3.dist-info → infdate-0.2.5.dist-info}/licenses/LICENSE +0 -0
infdate/__init__.py
CHANGED
@@ -152,17 +152,6 @@ class GenericDate:
|
|
152
152
|
"""Return a copy with year, month, and/or date replaced"""
|
153
153
|
raise NotImplementedError
|
154
154
|
|
155
|
-
@overload
|
156
|
-
def pretty(
|
157
|
-
self: _GD,
|
158
|
-
/,
|
159
|
-
*,
|
160
|
-
inf_common_prefix: str,
|
161
|
-
inf_past_suffix: str,
|
162
|
-
inf_future_suffix: str,
|
163
|
-
) -> str: ...
|
164
|
-
@overload
|
165
|
-
def pretty(self: _GD, /, *, fmt: str) -> str: ...
|
166
155
|
def pretty(
|
167
156
|
self: _GD,
|
168
157
|
/,
|
@@ -175,6 +164,16 @@ class GenericDate:
|
|
175
164
|
"""Return the date, pretty printed"""
|
176
165
|
raise NotImplementedError
|
177
166
|
|
167
|
+
def tonative(
|
168
|
+
self: _GD,
|
169
|
+
/,
|
170
|
+
*,
|
171
|
+
exact: bool = False,
|
172
|
+
fmt: str = ISO_DATE_FORMAT,
|
173
|
+
) -> str | float | None:
|
174
|
+
"""Return the native equivalent of the date"""
|
175
|
+
raise NotImplementedError
|
176
|
+
|
178
177
|
|
179
178
|
class InfinityDate(GenericDate):
|
180
179
|
"""Infinity Date object"""
|
@@ -204,7 +203,6 @@ class InfinityDate(GenericDate):
|
|
204
203
|
f"{self.__class__.__name__} instances do not support .replace()"
|
205
204
|
)
|
206
205
|
|
207
|
-
@final
|
208
206
|
def pretty(
|
209
207
|
self,
|
210
208
|
/,
|
@@ -223,6 +221,19 @@ class InfinityDate(GenericDate):
|
|
223
221
|
#
|
224
222
|
return pretty_result or self.isoformat()
|
225
223
|
|
224
|
+
def tonative(
|
225
|
+
self,
|
226
|
+
/,
|
227
|
+
*,
|
228
|
+
exact: bool = False,
|
229
|
+
fmt: str = ISO_DATE_FORMAT,
|
230
|
+
) -> str | float | None:
|
231
|
+
"""Return the native equivalent of the date"""
|
232
|
+
if not exact:
|
233
|
+
return None
|
234
|
+
#
|
235
|
+
return self.toordinal()
|
236
|
+
|
226
237
|
|
227
238
|
# pylint: disable=too-many-instance-attributes
|
228
239
|
class RealDate(GenericDate):
|
@@ -266,7 +277,6 @@ class RealDate(GenericDate):
|
|
266
277
|
)
|
267
278
|
)
|
268
279
|
|
269
|
-
@final
|
270
280
|
def pretty(
|
271
281
|
self,
|
272
282
|
/,
|
@@ -279,6 +289,16 @@ class RealDate(GenericDate):
|
|
279
289
|
"""Return the date, pretty printed"""
|
280
290
|
return self.strftime(fmt)
|
281
291
|
|
292
|
+
def tonative(
|
293
|
+
self,
|
294
|
+
/,
|
295
|
+
*,
|
296
|
+
exact: bool = False,
|
297
|
+
fmt: str = ISO_DATE_FORMAT,
|
298
|
+
) -> str | float | None:
|
299
|
+
"""Return the native equivalent of the date"""
|
300
|
+
return self.strftime(fmt)
|
301
|
+
|
282
302
|
|
283
303
|
# -----------------------------------------------------------------------------
|
284
304
|
# Private module functions
|
@@ -1,6 +1,6 @@
|
|
1
1
|
Metadata-Version: 2.4
|
2
2
|
Name: infdate
|
3
|
-
Version: 0.2.
|
3
|
+
Version: 0.2.5
|
4
4
|
Summary: Date object wrapper supporting infinity
|
5
5
|
Project-URL: Homepage, https://gitlab.com/blackstream-x/infdate
|
6
6
|
Project-URL: CI, https://gitlab.com/blackstream-x/infdate/-/pipelines
|
@@ -49,10 +49,10 @@ contain the two possible **InfinityDate** instance variations.
|
|
49
49
|
The module -level constants **REAL_MIN** and **REAL_MAX** are the eqivalents
|
50
50
|
of **datetime.date.min** and **datetime.date.max** as **RealDate** instances.
|
51
51
|
|
52
|
-
For any
|
52
|
+
For any **RealDate** instance, the following is **True**:
|
53
53
|
|
54
54
|
``` python
|
55
|
-
infdate.
|
55
|
+
infdate.INFINITE_PAST < infdate.REAL_MIN <= real_date_instance <= infdate.REAL_MAX < infdate.INFINITE_FUTURE
|
56
56
|
```
|
57
57
|
|
58
58
|
### Module-level constants
|
@@ -61,8 +61,8 @@ infdate.MIN < infdate.REAL_MIN <= real_date_instance <= infdate.REAL_MAX < infda
|
|
61
61
|
* **INFINITE_FUTURE** = **InfinityDate(**_past_bound_=`False`**)** → infinity after any date
|
62
62
|
* **MIN** = **INFINITE_PAST**
|
63
63
|
* **MAX** = **INFINITE_FUTURE**
|
64
|
-
* **REAL_MIN** = **RealDate(
|
65
|
-
* **REAL_MAX** = **RealDate(
|
64
|
+
* **REAL_MIN** = **RealDate(**`1`, `1`, `1`**)** → the same date as **datetime.date.min**
|
65
|
+
* **REAL_MAX** = **RealDate(**`9999`, `12`, `31`**)** → the same date as **datetime.date.max**
|
66
66
|
* **MIN_ORDINAL** = `1` → the same value as **datetime.date.min.toordinal()**
|
67
67
|
* **MAX_ORDINAL** = `3652059` → the same value as **datetime.date.max.toordinal()**
|
68
68
|
* **RESOLUTION** = `1` → represents the lowest possible date difference: _one day_
|
@@ -109,8 +109,17 @@ Some notable difference from the **datetime.date** class, mainly due to the desi
|
|
109
109
|
from an **InfinityDate** or **RealDate**, only **float** or **int**
|
110
110
|
(support for adding and subtracting datetime.timedelta instances might be added in the future, [see the feature request]).
|
111
111
|
|
112
|
-
|
113
|
-
|
112
|
+
|
113
|
+
### Additional methods
|
114
|
+
|
115
|
+
* **.pretty()** can be used to format **RealDate** instances with a format string like **.strftime()** (provided with the _fmt_ argument that defaults to the ISO format `%Y-%m-%d`),
|
116
|
+
or to apply a custom format to **InfinityDate** classes using the _inf_common_prefix_, _inf_past_suffix_, and _inf_future_suffix_ arguments.
|
117
|
+
|
118
|
+
* **.tonative()** is the inverse function of the **fromnative()** constructor, returning a value tha can be used e.g. as a value for an API.
|
119
|
+
|
120
|
+
For **InfinityDate** instances, it returns the **.toordinal()** result if the _exact_ argument is set `True`, or `None` if it is left at the default (`False`).
|
121
|
+
|
122
|
+
For **RealDate** instances, this method works the same way as **.pretty()**, using the _fmt_ argument with the same default as above.
|
114
123
|
|
115
124
|
|
116
125
|
## Example usage
|
@@ -0,0 +1,6 @@
|
|
1
|
+
infdate/__init__.py,sha256=DlsZLMj4BLRl1VAZR7EYO2hwLsSNU9_3GLtvvioUsj4,14274
|
2
|
+
infdate/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
3
|
+
infdate-0.2.5.dist-info/METADATA,sha256=0UHBEJVBt3ohOH7LiPN2AcwaMhPeQIWETpaSWhi_w6M,7016
|
4
|
+
infdate-0.2.5.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
|
5
|
+
infdate-0.2.5.dist-info/licenses/LICENSE,sha256=867pxriiObx28vCU1JsRtu3H9kUKyl54e0-xl1IIv3Y,913
|
6
|
+
infdate-0.2.5.dist-info/RECORD,,
|
infdate-0.2.3.dist-info/RECORD
DELETED
@@ -1,6 +0,0 @@
|
|
1
|
-
infdate/__init__.py,sha256=9YUvBcztVWjzQYvu6N0ISSrG_OoH6BjusxX3TGNNv5s,13774
|
2
|
-
infdate/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
3
|
-
infdate-0.2.3.dist-info/METADATA,sha256=oX3erUYcGq-4dmRxqqMxyOG_RCHvTivIiFL3WcxaN94,6569
|
4
|
-
infdate-0.2.3.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
|
5
|
-
infdate-0.2.3.dist-info/licenses/LICENSE,sha256=867pxriiObx28vCU1JsRtu3H9kUKyl54e0-xl1IIv3Y,913
|
6
|
-
infdate-0.2.3.dist-info/RECORD,,
|
File without changes
|
File without changes
|