infdate 0.2.4__tar.gz → 0.2.5__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.
@@ -12,7 +12,7 @@ include:
12
12
  - component: $CI_SERVER_FQDN/blackstream-x/generic-components/meta-gitlab-security@~latest
13
13
  - component: $CI_SERVER_FQDN/blackstream-x/python-components/meta-uv-pipeline@feature/uv-version
14
14
  inputs:
15
- uv-version: "0.7.13"
15
+ uv-version: "0.7.17"
16
16
  mypy-args: "--exclude tools/"
17
17
  python-version: "3.13"
18
18
  python-variant: "alpine"
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: infdate
3
- Version: 0.2.4
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 valid **RealDate** instance, the following is **True**:
52
+ For any **RealDate** instance, the following is **True**:
53
53
 
54
54
  ``` python
55
- infdate.MIN < infdate.REAL_MIN <= real_date_instance <= infdate.REAL_MAX < infdate.MAX
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(**_`1`, `1`, `1`_**)** → the same date as **datetime.date.min**
65
- * **REAL_MAX** = **RealDate(**_`9999`, `12`, `31`_**)** → the same date as **datetime.date.max**
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
- * infdate module classes have a **.pretty()** method that 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`),
113
- or to apply a custom format to **InfinityDate** classes using the _inf_common_prefix_, _inf_past_suffix_ and _inf_future_suffix_ arguments.
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
@@ -24,10 +24,10 @@ contain the two possible **InfinityDate** instance variations.
24
24
  The module -level constants **REAL_MIN** and **REAL_MAX** are the eqivalents
25
25
  of **datetime.date.min** and **datetime.date.max** as **RealDate** instances.
26
26
 
27
- For any valid **RealDate** instance, the following is **True**:
27
+ For any **RealDate** instance, the following is **True**:
28
28
 
29
29
  ``` python
30
- infdate.MIN < infdate.REAL_MIN <= real_date_instance <= infdate.REAL_MAX < infdate.MAX
30
+ infdate.INFINITE_PAST < infdate.REAL_MIN <= real_date_instance <= infdate.REAL_MAX < infdate.INFINITE_FUTURE
31
31
  ```
32
32
 
33
33
  ### Module-level constants
@@ -36,8 +36,8 @@ infdate.MIN < infdate.REAL_MIN <= real_date_instance <= infdate.REAL_MAX < infda
36
36
  * **INFINITE_FUTURE** = **InfinityDate(**_past_bound_=`False`**)** → infinity after any date
37
37
  * **MIN** = **INFINITE_PAST**
38
38
  * **MAX** = **INFINITE_FUTURE**
39
- * **REAL_MIN** = **RealDate(**_`1`, `1`, `1`_**)** → the same date as **datetime.date.min**
40
- * **REAL_MAX** = **RealDate(**_`9999`, `12`, `31`_**)** → the same date as **datetime.date.max**
39
+ * **REAL_MIN** = **RealDate(**`1`, `1`, `1`**)** → the same date as **datetime.date.min**
40
+ * **REAL_MAX** = **RealDate(**`9999`, `12`, `31`**)** → the same date as **datetime.date.max**
41
41
  * **MIN_ORDINAL** = `1` → the same value as **datetime.date.min.toordinal()**
42
42
  * **MAX_ORDINAL** = `3652059` → the same value as **datetime.date.max.toordinal()**
43
43
  * **RESOLUTION** = `1` → represents the lowest possible date difference: _one day_
@@ -84,8 +84,17 @@ Some notable difference from the **datetime.date** class, mainly due to the desi
84
84
  from an **InfinityDate** or **RealDate**, only **float** or **int**
85
85
  (support for adding and subtracting datetime.timedelta instances might be added in the future, [see the feature request]).
86
86
 
87
- * infdate module classes have a **.pretty()** method that 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`),
88
- or to apply a custom format to **InfinityDate** classes using the _inf_common_prefix_, _inf_past_suffix_ and _inf_future_suffix_ arguments.
87
+
88
+ ### Additional methods
89
+
90
+ * **.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`),
91
+ or to apply a custom format to **InfinityDate** classes using the _inf_common_prefix_, _inf_past_suffix_, and _inf_future_suffix_ arguments.
92
+
93
+ * **.tonative()** is the inverse function of the **fromnative()** constructor, returning a value tha can be used e.g. as a value for an API.
94
+
95
+ 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`).
96
+
97
+ For **RealDate** instances, this method works the same way as **.pretty()**, using the _fmt_ argument with the same default as above.
89
98
 
90
99
 
91
100
  ## Example usage
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "infdate"
3
- version = "0.2.4"
3
+ version = "0.2.5"
4
4
  description = "Date object wrapper supporting infinity"
5
5
  readme = "README.md"
6
6
  authors = [
@@ -0,0 +1,8 @@
1
+ {
2
+ "ci_pipeline_created_at": "2025-07-01T05:16:16Z",
3
+ "ci_pipeline_id": "1899192252",
4
+ "ci_pipeline_url": "https://gitlab.com/blackstream-x/infdate/-/pipelines/1899192252",
5
+ "ci_project_title": "infdate",
6
+ "ci_project_url": "https://gitlab.com/blackstream-x/infdate",
7
+ "ci_commit_sha": "1a7174f522c13a615675c5760cb5d4707696cc1b"
8
+ }
@@ -4,6 +4,6 @@ _provided by [glsr-present](https://pypi.org/project/glsr-present/) 0.3.6_
4
4
 
5
5
  [infdate](https://gitlab.com/blackstream-x/infdate)
6
6
  built with pipeline
7
- [1898767076](https://gitlab.com/blackstream-x/infdate/-/pipelines/1898767076)
8
- (build started 2025-06-30T21:43:23Z)
7
+ [1899192252](https://gitlab.com/blackstream-x/infdate/-/pipelines/1899192252)
8
+ (build started 2025-07-01T05:16:16Z)
9
9
 
@@ -0,0 +1 @@
1
+ <?xml version="1.0" encoding="utf-8"?><testsuites name="pytest tests"><testsuite name="pytest" errors="0" failures="0" skipped="0" tests="48" time="1.173" timestamp="2025-07-01T05:16:48.730103+00:00" hostname="runner-j1aldqxs-project-71015407-concurrent-0"><testcase classname="tests.test_dates.GenericDateBase" name="test_bool" time="0.003" /><testcase classname="tests.test_dates.GenericDateBase" name="test_eq" time="0.002" /><testcase classname="tests.test_dates.GenericDateBase" name="test_ge" time="0.056" /><testcase classname="tests.test_dates.GenericDateBase" name="test_gt" time="0.046" /><testcase classname="tests.test_dates.GenericDateBase" name="test_hash" time="0.001" /><testcase classname="tests.test_dates.GenericDateBase" name="test_isoformat" time="0.002" /><testcase classname="tests.test_dates.GenericDateBase" name="test_le" time="0.056" /><testcase classname="tests.test_dates.GenericDateBase" name="test_lt" time="0.046" /><testcase classname="tests.test_dates.GenericDateBase" name="test_nan_not_allowed" time="0.001" /><testcase classname="tests.test_dates.GenericDateBase" name="test_ne" time="0.047" /><testcase classname="tests.test_dates.GenericDateBase" name="test_pretty" time="0.001" /><testcase classname="tests.test_dates.GenericDateBase" name="test_replace" time="0.001" /><testcase classname="tests.test_dates.GenericDateBase" name="test_repr" time="0.001" /><testcase classname="tests.test_dates.GenericDateBase" name="test_str" time="0.001" /><testcase classname="tests.test_dates.GenericDateBase" name="test_strftime" time="0.001" /><testcase classname="tests.test_dates.GenericDateBase" name="test_tonative" time="0.001" /><testcase classname="tests.test_dates.GenericDateBase" name="test_toordinal" time="0.001" /><testcase classname="tests.test_dates.GenericDateArithmetics" name="test_add_and_radd" time="0.007" /><testcase classname="tests.test_dates.GenericDateArithmetics" name="test_add_days" time="0.004" /><testcase classname="tests.test_dates.GenericDateArithmetics" name="test_rsub_stdlib_date" time="0.001" /><testcase classname="tests.test_dates.GenericDateArithmetics" name="test_sub_date" time="0.001" /><testcase classname="tests.test_dates.GenericDateArithmetics" name="test_sub_number" time="0.004" /><testcase classname="tests.test_dates.GenericDateArithmetics" name="test_sub_stdlib_date" time="0.001" /><testcase classname="tests.test_dates.InfinityDate" name="test_pretty" time="0.001" /><testcase classname="tests.test_dates.InfinityDate" name="test_replace" time="0.001" /><testcase classname="tests.test_dates.InfinityDate" name="test_repr" time="0.001" /><testcase classname="tests.test_dates.InfinityDate" name="test_strftime" time="0.001" /><testcase classname="tests.test_dates.InfinityDate" name="test_tonative" time="0.001" /><testcase classname="tests.test_dates.RealDate" name="test_attributes" time="0.002" /><testcase classname="tests.test_dates.RealDate" name="test_bool" time="0.001" /><testcase classname="tests.test_dates.RealDate" name="test_pretty" time="0.001" /><testcase classname="tests.test_dates.RealDate" name="test_proxied_methods" time="0.001" /><testcase classname="tests.test_dates.RealDate" name="test_random_date_within_limits" time="0.295" /><testcase classname="tests.test_dates.RealDate" name="test_replace" time="0.002" /><testcase classname="tests.test_dates.RealDate" name="test_repr" time="0.001" /><testcase classname="tests.test_dates.RealDate" name="test_strftime" time="0.003" /><testcase classname="tests.test_dates.RealDate" name="test_tonative" time="0.001" /><testcase classname="tests.test_factories.FactoryFunctions" name="test_deprecated_from_datetime_object" time="0.003" /><testcase classname="tests.test_factories.FactoryFunctions" name="test_deprecated_from_native_type" time="0.005" /><testcase classname="tests.test_factories.FactoryFunctions" name="test_fromisocalendar" time="0.002" /><testcase classname="tests.test_factories.FactoryFunctions" name="test_fromisoformat" time="0.002" /><testcase classname="tests.test_factories.FactoryFunctions" name="test_fromnative" time="0.004" /><testcase classname="tests.test_factories.FactoryFunctions" name="test_fromordinal" time="0.002" /><testcase classname="tests.test_factories.FactoryFunctions" name="test_fromtimestamp" time="0.003" /><testcase classname="tests.test_factories.FactoryFunctions" name="test_fromtimestamp_errors" time="0.001" /><testcase classname="tests.test_factories.FactoryFunctions" name="test_private__from_datetime_object" time="0.002" /><testcase classname="tests.test_factories.FactoryFunctions" name="test_today" time="0.002" /><testcase classname="tests.test_factories.FactoryFunctions" name="testdatetime" time="0.002" /></testsuite></testsuites>
@@ -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
@@ -236,6 +236,11 @@ class GenericDateBase(tb.VerboseTestCase):
236
236
  gd = infdate.GenericDate(inf)
237
237
  self.assertRaises(NotImplementedError, gd.pretty)
238
238
 
239
+ def test_tonative(self):
240
+ """.tonative() method"""
241
+ gd = infdate.GenericDate(inf)
242
+ self.assertRaises(NotImplementedError, gd.tonative)
243
+
239
244
 
240
245
  class GenericDateArithmetics(tb.VerboseTestCase):
241
246
  """GenericDate objects - arithmetics"""
@@ -540,6 +545,34 @@ class InfinityDate(tb.VerboseTestCase):
540
545
  #
541
546
  #
542
547
 
548
+ def test_tonative(self):
549
+ """.tonative() method"""
550
+ infinite_past = infdate.InfinityDate(past_bound=True)
551
+ infinite_future = infdate.InfinityDate()
552
+ for exact, infinite_past_result, infinite_future_result in (
553
+ (True, -inf, inf),
554
+ (False, None, None),
555
+ ):
556
+ with self.subTest(
557
+ "infinite past", exact=exact, infinite_past_result=infinite_past_result
558
+ ):
559
+ self.assertEqual(
560
+ infinite_past.tonative(exact=exact), infinite_past_result
561
+ )
562
+ #
563
+ #
564
+ with self.subTest(
565
+ "infinite furture",
566
+ exact=exact,
567
+ infinite_future_result=infinite_future_result,
568
+ ):
569
+ self.assertEqual(
570
+ infinite_future.tonative(exact=exact), infinite_future_result
571
+ )
572
+ #
573
+ #
574
+ #
575
+
543
576
 
544
577
  class RealDate(tb.VerboseTestCase):
545
578
  """RealDate class"""
@@ -710,6 +743,20 @@ class RealDate(tb.VerboseTestCase):
710
743
  #
711
744
  #
712
745
 
746
+ def test_tonative(self):
747
+ """.tonative() method"""
748
+ for year, month, day, fmt, expected_result in (
749
+ (1996, 6, 25, "%d.%m.%Y", "25.06.1996"),
750
+ (1, 2, 3, "%m/%d/%y", "02/03/01"),
751
+ (9999, 12, 31, "%Y-%m", "9999-12"),
752
+ (2025, 6, 25, "", "2025-06-25"),
753
+ ):
754
+ rd = infdate.RealDate(year, month, day)
755
+ with self.subTest("result value", fmt=fmt, expected_result=expected_result):
756
+ self.assertEqual(rd.tonative(fmt=fmt), expected_result)
757
+ #
758
+ #
759
+
713
760
  def test_random_date_within_limits(self):
714
761
  """The following relation
715
762
  infdate.INFINITE_PAST < infdate.REAL_MIN <= real_date_instance <= …
@@ -1,8 +0,0 @@
1
- {
2
- "ci_pipeline_created_at": "2025-06-30T21:43:23Z",
3
- "ci_pipeline_id": "1898767076",
4
- "ci_pipeline_url": "https://gitlab.com/blackstream-x/infdate/-/pipelines/1898767076",
5
- "ci_project_title": "infdate",
6
- "ci_project_url": "https://gitlab.com/blackstream-x/infdate",
7
- "ci_commit_sha": "f9583fe4843bff2787558b26ed227473639049c5"
8
- }
@@ -1 +0,0 @@
1
- <?xml version="1.0" encoding="utf-8"?><testsuites name="pytest tests"><testsuite name="pytest" errors="0" failures="0" skipped="0" tests="45" time="1.183" timestamp="2025-06-30T21:43:54.387222+00:00" hostname="runner-zxwgkjap-project-71015407-concurrent-0"><testcase classname="tests.test_dates.GenericDateBase" name="test_bool" time="0.003" /><testcase classname="tests.test_dates.GenericDateBase" name="test_eq" time="0.001" /><testcase classname="tests.test_dates.GenericDateBase" name="test_ge" time="0.055" /><testcase classname="tests.test_dates.GenericDateBase" name="test_gt" time="0.046" /><testcase classname="tests.test_dates.GenericDateBase" name="test_hash" time="0.001" /><testcase classname="tests.test_dates.GenericDateBase" name="test_isoformat" time="0.002" /><testcase classname="tests.test_dates.GenericDateBase" name="test_le" time="0.056" /><testcase classname="tests.test_dates.GenericDateBase" name="test_lt" time="0.046" /><testcase classname="tests.test_dates.GenericDateBase" name="test_nan_not_allowed" time="0.002" /><testcase classname="tests.test_dates.GenericDateBase" name="test_ne" time="0.046" /><testcase classname="tests.test_dates.GenericDateBase" name="test_pretty" time="0.001" /><testcase classname="tests.test_dates.GenericDateBase" name="test_replace" time="0.001" /><testcase classname="tests.test_dates.GenericDateBase" name="test_repr" time="0.001" /><testcase classname="tests.test_dates.GenericDateBase" name="test_str" time="0.001" /><testcase classname="tests.test_dates.GenericDateBase" name="test_strftime" time="0.001" /><testcase classname="tests.test_dates.GenericDateBase" name="test_toordinal" time="0.001" /><testcase classname="tests.test_dates.GenericDateArithmetics" name="test_add_and_radd" time="0.007" /><testcase classname="tests.test_dates.GenericDateArithmetics" name="test_add_days" time="0.005" /><testcase classname="tests.test_dates.GenericDateArithmetics" name="test_rsub_stdlib_date" time="0.001" /><testcase classname="tests.test_dates.GenericDateArithmetics" name="test_sub_date" time="0.001" /><testcase classname="tests.test_dates.GenericDateArithmetics" name="test_sub_number" time="0.004" /><testcase classname="tests.test_dates.GenericDateArithmetics" name="test_sub_stdlib_date" time="0.001" /><testcase classname="tests.test_dates.InfinityDate" name="test_pretty" time="0.001" /><testcase classname="tests.test_dates.InfinityDate" name="test_replace" time="0.001" /><testcase classname="tests.test_dates.InfinityDate" name="test_repr" time="0.001" /><testcase classname="tests.test_dates.InfinityDate" name="test_strftime" time="0.001" /><testcase classname="tests.test_dates.RealDate" name="test_attributes" time="0.001" /><testcase classname="tests.test_dates.RealDate" name="test_bool" time="0.001" /><testcase classname="tests.test_dates.RealDate" name="test_pretty" time="0.001" /><testcase classname="tests.test_dates.RealDate" name="test_proxied_methods" time="0.001" /><testcase classname="tests.test_dates.RealDate" name="test_random_date_within_limits" time="0.291" /><testcase classname="tests.test_dates.RealDate" name="test_replace" time="0.002" /><testcase classname="tests.test_dates.RealDate" name="test_repr" time="0.001" /><testcase classname="tests.test_dates.RealDate" name="test_strftime" time="0.003" /><testcase classname="tests.test_factories.FactoryFunctions" name="test_deprecated_from_datetime_object" time="0.003" /><testcase classname="tests.test_factories.FactoryFunctions" name="test_deprecated_from_native_type" time="0.005" /><testcase classname="tests.test_factories.FactoryFunctions" name="test_fromisocalendar" time="0.002" /><testcase classname="tests.test_factories.FactoryFunctions" name="test_fromisoformat" time="0.002" /><testcase classname="tests.test_factories.FactoryFunctions" name="test_fromnative" time="0.004" /><testcase classname="tests.test_factories.FactoryFunctions" name="test_fromordinal" time="0.002" /><testcase classname="tests.test_factories.FactoryFunctions" name="test_fromtimestamp" time="0.003" /><testcase classname="tests.test_factories.FactoryFunctions" name="test_fromtimestamp_errors" time="0.001" /><testcase classname="tests.test_factories.FactoryFunctions" name="test_private__from_datetime_object" time="0.002" /><testcase classname="tests.test_factories.FactoryFunctions" name="test_today" time="0.002" /><testcase classname="tests.test_factories.FactoryFunctions" name="testdatetime" time="0.002" /></testsuite></testsuites>
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes