infdate 0.2.4__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 -2
- {infdate-0.2.4.dist-info → infdate-0.2.5.dist-info}/METADATA +16 -7
- infdate-0.2.5.dist-info/RECORD +6 -0
- infdate-0.2.4.dist-info/RECORD +0 -6
- {infdate-0.2.4.dist-info → infdate-0.2.5.dist-info}/WHEEL +0 -0
- {infdate-0.2.4.dist-info → infdate-0.2.5.dist-info}/licenses/LICENSE +0 -0
infdate/__init__.py
CHANGED
@@ -164,6 +164,16 @@ class GenericDate:
|
|
164
164
|
"""Return the date, pretty printed"""
|
165
165
|
raise NotImplementedError
|
166
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
|
+
|
167
177
|
|
168
178
|
class InfinityDate(GenericDate):
|
169
179
|
"""Infinity Date object"""
|
@@ -193,7 +203,6 @@ class InfinityDate(GenericDate):
|
|
193
203
|
f"{self.__class__.__name__} instances do not support .replace()"
|
194
204
|
)
|
195
205
|
|
196
|
-
@final
|
197
206
|
def pretty(
|
198
207
|
self,
|
199
208
|
/,
|
@@ -212,6 +221,19 @@ class InfinityDate(GenericDate):
|
|
212
221
|
#
|
213
222
|
return pretty_result or self.isoformat()
|
214
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
|
+
|
215
237
|
|
216
238
|
# pylint: disable=too-many-instance-attributes
|
217
239
|
class RealDate(GenericDate):
|
@@ -255,7 +277,6 @@ class RealDate(GenericDate):
|
|
255
277
|
)
|
256
278
|
)
|
257
279
|
|
258
|
-
@final
|
259
280
|
def pretty(
|
260
281
|
self,
|
261
282
|
/,
|
@@ -268,6 +289,16 @@ class RealDate(GenericDate):
|
|
268
289
|
"""Return the date, pretty printed"""
|
269
290
|
return self.strftime(fmt)
|
270
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
|
+
|
271
302
|
|
272
303
|
# -----------------------------------------------------------------------------
|
273
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.4.dist-info/RECORD
DELETED
@@ -1,6 +0,0 @@
|
|
1
|
-
infdate/__init__.py,sha256=IIJ8ZoTGNoBeFTt86_ysMCUVBj36r8vcqpReJa6EiUM,13523
|
2
|
-
infdate/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
3
|
-
infdate-0.2.4.dist-info/METADATA,sha256=O22fG8KKeSgLV2hDAN8pkM2JmKh4i-_yCX_glIlTGp8,6569
|
4
|
-
infdate-0.2.4.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
|
5
|
-
infdate-0.2.4.dist-info/licenses/LICENSE,sha256=867pxriiObx28vCU1JsRtu3H9kUKyl54e0-xl1IIv3Y,913
|
6
|
-
infdate-0.2.4.dist-info/RECORD,,
|
File without changes
|
File without changes
|