iker-python-common 1.0.47__py3-none-any.whl → 1.0.49__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.
@@ -22,6 +22,8 @@ __all__ = [
22
22
  "dt_utc_infinity",
23
23
  "dt_utc_now",
24
24
  "dt_utc",
25
+ "td_to_us",
26
+ "td_from_us",
25
27
  "dt_to_ts",
26
28
  "dt_to_ts_us",
27
29
  "dt_from_ts",
@@ -44,16 +46,16 @@ def basic_date_format() -> str:
44
46
 
45
47
 
46
48
  @memorized
47
- def basic_time_format(with_ms: bool = False, with_tz: bool = False) -> str:
49
+ def basic_time_format(with_us: bool = False, with_tz: bool = False) -> str:
48
50
  """
49
- Returns the basic time format string, with optional milliseconds and timezone.
51
+ Returns the basic time format string, with optional microseconds and timezone.
50
52
 
51
- :param with_ms: If ``True``, include milliseconds in the format.
53
+ :param with_us: If ``True``, include microseconds in the format.
52
54
  :param with_tz: If ``True``, include timezone in the format.
53
55
  :return: The basic time format string.
54
56
  """
55
57
  fmt_str = "T%H%M%S"
56
- if with_ms:
58
+ if with_us:
57
59
  fmt_str = fmt_str + ".%f"
58
60
  if with_tz:
59
61
  fmt_str = fmt_str + "%z"
@@ -61,15 +63,15 @@ def basic_time_format(with_ms: bool = False, with_tz: bool = False) -> str:
61
63
 
62
64
 
63
65
  @memorized
64
- def basic_format(with_ms: bool = False, with_tz: bool = False) -> str:
66
+ def basic_format(with_us: bool = False, with_tz: bool = False) -> str:
65
67
  """
66
- Returns the basic combined date and time format string, with optional milliseconds and timezone.
68
+ Returns the basic combined date and time format string, with optional microseconds and timezone.
67
69
 
68
- :param with_ms: If ``True``, include milliseconds in the time format.
70
+ :param with_us: If ``True``, include microseconds in the time format.
69
71
  :param with_tz: If ``True``, include timezone in the time format.
70
72
  :return: The basic combined date and time format string.
71
73
  """
72
- return basic_date_format() + basic_time_format(with_ms, with_tz)
74
+ return basic_date_format() + basic_time_format(with_us, with_tz)
73
75
 
74
76
 
75
77
  @singleton
@@ -83,16 +85,16 @@ def extended_date_format() -> str:
83
85
 
84
86
 
85
87
  @memorized
86
- def extended_time_format(with_ms: bool = False, with_tz: bool = False) -> str:
88
+ def extended_time_format(with_us: bool = False, with_tz: bool = False) -> str:
87
89
  """
88
- Returns the extended time format string, with optional milliseconds and timezone.
90
+ Returns the extended time format string, with optional microseconds and timezone.
89
91
 
90
- :param with_ms: If ``True``, include milliseconds in the format.
92
+ :param with_us: If ``True``, include microseconds in the format.
91
93
  :param with_tz: If ``True``, include timezone in the format.
92
94
  :return: The extended time format string.
93
95
  """
94
96
  fmt_str = "T%H:%M:%S"
95
- if with_ms:
97
+ if with_us:
96
98
  fmt_str = fmt_str + ".%f"
97
99
  if with_tz:
98
100
  fmt_str = fmt_str + "%:z"
@@ -100,15 +102,15 @@ def extended_time_format(with_ms: bool = False, with_tz: bool = False) -> str:
100
102
 
101
103
 
102
104
  @memorized
103
- def extended_format(with_ms: bool = False, with_tz: bool = False) -> str:
105
+ def extended_format(with_us: bool = False, with_tz: bool = False) -> str:
104
106
  """
105
- Returns the extended combined date and time format string, with optional milliseconds and timezone.
107
+ Returns the extended combined date and time format string, with optional microseconds and timezone.
106
108
 
107
- :param with_ms: If ``True``, include milliseconds in the time format.
109
+ :param with_us: If ``True``, include microseconds in the time format.
108
110
  :param with_tz: If ``True``, include timezone in the time format.
109
111
  :return: The extended combined date and time format string.
110
112
  """
111
- return extended_date_format() + extended_time_format(with_ms, with_tz)
113
+ return extended_date_format() + extended_time_format(with_us, with_tz)
112
114
 
113
115
 
114
116
  iso_date_format = extended_date_format
@@ -120,7 +122,7 @@ iso_format = extended_format
120
122
  def iso_formats() -> list[str]:
121
123
  """
122
124
  Returns a list of supported ISO 8601 date and time format strings, including both basic and extended forms, with
123
- optional milliseconds and timezone.
125
+ optional microseconds and timezone.
124
126
 
125
127
  :return: A list of ISO 8601 format strings.
126
128
  """
@@ -207,6 +209,26 @@ def dt_utc(
207
209
  return datetime.datetime(year, month, day, hour, minute, second, microsecond, tzinfo=datetime.timezone.utc)
208
210
 
209
211
 
212
+ def td_to_us(td: datetime.timedelta) -> int:
213
+ """
214
+ Returns the total number of microseconds in the given ``timedelta``.
215
+
216
+ :param td: The ``timedelta`` to convert.
217
+ :return: The total number of microseconds in ``td``.
218
+ """
219
+ return (td.days * 86400 + td.seconds) * 1000000 + td.microseconds
220
+
221
+
222
+ def td_from_us(us: int) -> datetime.timedelta:
223
+ """
224
+ Returns a ``timedelta`` representing the given number of microseconds.
225
+
226
+ :param us: The number of microseconds.
227
+ :return: The corresponding ``timedelta``.
228
+ """
229
+ return datetime.timedelta(microseconds=us)
230
+
231
+
210
232
  def dt_to_td(dt: datetime.datetime) -> datetime.timedelta:
211
233
  """
212
234
  Returns the ``timedelta`` between the given ``datetime`` and the POSIX epoch.
@@ -234,8 +256,7 @@ def dt_to_ts_us(dt: datetime.datetime) -> int:
234
256
  :param dt: The ``datetime`` to convert.
235
257
  :return: The timestamp in microseconds from the POSIX epoch.
236
258
  """
237
- td = dt_to_td(dt)
238
- return (td.days * 86400 + td.seconds) * 1000000 + td.microseconds
259
+ return td_to_us(dt_to_td(dt))
239
260
 
240
261
 
241
262
  def dt_from_td(td: datetime.timedelta) -> datetime.datetime:
@@ -265,7 +286,7 @@ def dt_from_ts_us(ts: int) -> datetime.datetime:
265
286
  :param ts: Timestamp in microseconds from the POSIX epoch.
266
287
  :return: The corresponding UTC datetime.
267
288
  """
268
- return dt_from_td(datetime.timedelta(microseconds=ts))
289
+ return dt_from_td(td_from_us(ts))
269
290
 
270
291
 
271
292
  basic_date_regex: re.Pattern[str] = re.compile(r"(\d{4})(\d{2})(\d{2})")
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: iker-python-common
3
- Version: 1.0.47
3
+ Version: 1.0.49
4
4
  Classifier: Programming Language :: Python :: 3
5
5
  Classifier: Programming Language :: Python :: 3.11
6
6
  Classifier: Programming Language :: Python :: 3.12
@@ -5,7 +5,7 @@ iker/common/utils/config.py,sha256=z8rLqli961A-qAV9EaELp-pKuhNUNaq1Btdv-uwG7_I,4
5
5
  iker/common/utils/csv.py,sha256=_V9OUrKcojec2L-hWagEIVnL2uvGjyJAFTrD7tHNr48,7573
6
6
  iker/common/utils/dbutils.py,sha256=lUcYKP26y4FGygMPs8SlW-PjDSZcvZO0e-cOkT2XqCY,11076
7
7
  iker/common/utils/dockerutils.py,sha256=n2WuzXaZB6_WocSljvPOnfExSIjIHRUbuWp2oBbaPKQ,8004
8
- iker/common/utils/dtutils.py,sha256=SFaBDXv0HAs8kSQqeyE6BfH9V6_LWPXzPhLh-4GKRQ8,11367
8
+ iker/common/utils/dtutils.py,sha256=fY7nVb0UBX5f4P8s_dHBv3vL0hTDbr3jlV3OjU89sxs,11908
9
9
  iker/common/utils/funcutils.py,sha256=A08f5wjoLgLQKyRJcYeWJnqVm2QcerIx0l-Se2600bc,5869
10
10
  iker/common/utils/jsonutils.py,sha256=xYKimWtsqQKiQDQr3EMIhpGrmWSNPzgZR1Sdz60CxSo,16536
11
11
  iker/common/utils/logger.py,sha256=FJaai6Sbchy4wKHcUMUCrrkBcXvIxq4qByERZ_TJBps,3881
@@ -19,7 +19,7 @@ iker/common/utils/span.py,sha256=yiXqk86cLKxkMdkO3pAHEfU5bUvHsGo3p--pAWo_yfM,599
19
19
  iker/common/utils/strutils.py,sha256=Tu_qFeH3K-SfwvMxdrZAc9iLPV8ZmtX4ntyyFGNslf8,5094
20
20
  iker/common/utils/testutils.py,sha256=60c3DAZxj0D6EKOhDRQdcBiqV4kMBJGXFpbnyKkfgvg,5554
21
21
  iker/common/utils/typeutils.py,sha256=RVkYkFRgDrx77OHFH7PavMV0AIB0S8ly40rs4g7JWE4,8220
22
- iker_python_common-1.0.47.dist-info/METADATA,sha256=gHgD7cbGPthAhGsQvtZ_VZy74fRP9RSUOhApTC7UCyQ,1001
23
- iker_python_common-1.0.47.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
24
- iker_python_common-1.0.47.dist-info/top_level.txt,sha256=4_B8Prfc_lxFafFYTQThIU1ZqOYQ4pHHHnJ_fQ_oHs8,5
25
- iker_python_common-1.0.47.dist-info/RECORD,,
22
+ iker_python_common-1.0.49.dist-info/METADATA,sha256=2UvkILO7DuIVXXS-pLIHJmeHOZ-ZcxZc892J8jNUO5k,1001
23
+ iker_python_common-1.0.49.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
24
+ iker_python_common-1.0.49.dist-info/top_level.txt,sha256=4_B8Prfc_lxFafFYTQThIU1ZqOYQ4pHHHnJ_fQ_oHs8,5
25
+ iker_python_common-1.0.49.dist-info/RECORD,,