python-time-functions 2.1.1__py3-none-any.whl → 2.1.3__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.
- python_time_functions-2.1.3.dist-info/METADATA +47 -0
- python_time_functions-2.1.3.dist-info/RECORD +7 -0
- python_time_functions-2.1.3.dist-info/top_level.txt +1 -0
- {time_fuctions_cornebester → time_functions}/time_functions.py +60 -20
- python_time_functions-2.1.1.dist-info/METADATA +0 -8
- python_time_functions-2.1.1.dist-info/RECORD +0 -7
- python_time_functions-2.1.1.dist-info/top_level.txt +0 -1
- {python_time_functions-2.1.1.dist-info → python_time_functions-2.1.3.dist-info}/WHEEL +0 -0
- {python_time_functions-2.1.1.dist-info → python_time_functions-2.1.3.dist-info}/licenses/LICENSE +0 -0
- {time_fuctions_cornebester → time_functions}/__init__.py +0 -0
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: python_time_functions
|
|
3
|
+
Version: 2.1.3
|
|
4
|
+
Summary: Common Python functions for time handling
|
|
5
|
+
Author-email: Corne Bester <corne.bester@gmail.com>
|
|
6
|
+
Project-URL: Homepage, https://example.com
|
|
7
|
+
Project-URL: Documentation, https://readthedocs.org
|
|
8
|
+
Project-URL: Repository, https://github.com/cornebester/python_time_functions
|
|
9
|
+
Project-URL: Issues, https://github.com/cornebester/python_time_functions/issues
|
|
10
|
+
Project-URL: Changelog, https://github.com/cornebester/python_time_functions/blob/master/CHANGELOG.md
|
|
11
|
+
Description-Content-Type: text/markdown
|
|
12
|
+
License-File: LICENSE
|
|
13
|
+
Requires-Dist: datetime
|
|
14
|
+
Requires-Dist: timezone
|
|
15
|
+
Dynamic: license-file
|
|
16
|
+
|
|
17
|
+
# Readme
|
|
18
|
+
|
|
19
|
+
Common Python functions for time handling
|
|
20
|
+
|
|
21
|
+
```python
|
|
22
|
+
from datetime import datetime, timezone
|
|
23
|
+
|
|
24
|
+
import time_functions
|
|
25
|
+
# OR
|
|
26
|
+
from time_functions import get_timestamp_unix_millis
|
|
27
|
+
|
|
28
|
+
timestamp = datetime.now(timezone.utc)
|
|
29
|
+
unix_millis = get_timestamp_unix_millis(timestamp) # create unix timestamp from obj above
|
|
30
|
+
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
## local dev
|
|
34
|
+
|
|
35
|
+
pip install -r requirements.txt
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
## test
|
|
39
|
+
|
|
40
|
+
pytest
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
### other
|
|
44
|
+
|
|
45
|
+
pip3 freeze > requirements.txt
|
|
46
|
+
|
|
47
|
+
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
python_time_functions-2.1.3.dist-info/licenses/LICENSE,sha256=HrhfyXIkWY2tGFK11kg7vPCqhgh5DcxleloqdhrpyMY,11558
|
|
2
|
+
time_functions/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
3
|
+
time_functions/time_functions.py,sha256=i6ZJkdyvXf-iZiQPLnRtJaWybBY704dx4uKQ82_17_g,14106
|
|
4
|
+
python_time_functions-2.1.3.dist-info/METADATA,sha256=OSLL9Qwt8rtDuyLg2rAkAdEkt1fByHn6QUp1BQtbzd8,1148
|
|
5
|
+
python_time_functions-2.1.3.dist-info/WHEEL,sha256=aeYiig01lYGDzBgS8HxWXOg3uV61G9ijOsup-k9o1sk,91
|
|
6
|
+
python_time_functions-2.1.3.dist-info/top_level.txt,sha256=EEztmW3tTQHD5ZxrHagnKcjGTYwWiIn-QLJiPTIHPGc,15
|
|
7
|
+
python_time_functions-2.1.3.dist-info/RECORD,,
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
time_functions
|
|
@@ -239,58 +239,98 @@ def timestamp_parser_psql_millis(timestamp):
|
|
|
239
239
|
|
|
240
240
|
|
|
241
241
|
def timestamp_sanitizer_psql(input):
|
|
242
|
-
|
|
242
|
+
"""
|
|
243
243
|
Normalize unix timestamps to postgresl friendly float with millisecond decimals. 14 digits
|
|
244
|
-
Attemps to fix/sanitize bad
|
|
245
|
-
|
|
244
|
+
Attemps to fix/sanitize bad timestamp format I dreamed up like
|
|
245
|
+
>>> time_functions.timestamp_sanitizer_psql(1729755232184)
|
|
246
|
+
1729755232.184
|
|
247
|
+
>>> time_functions.timestamp_sanitizer_psql(1729765227856.3)
|
|
248
|
+
1729765227.856
|
|
249
|
+
>>> time_functions.timestamp_sanitizer_psql(1729765228327.051)
|
|
250
|
+
1729765228.327
|
|
251
|
+
handle timestamp as:
|
|
246
252
|
unix micros or millis in decimal format
|
|
247
|
-
unix millis or micros in unix format
|
|
253
|
+
unix millis or micros in unix format
|
|
248
254
|
iso8601
|
|
249
|
-
|
|
255
|
+
"""
|
|
250
256
|
try:
|
|
251
257
|
if isinstance(input, int):
|
|
252
258
|
if len(str(input)) == 10:
|
|
253
259
|
logger.debug("Not millsecond precision: %s", input)
|
|
254
260
|
return input
|
|
255
261
|
elif len(str(input)) == 13:
|
|
256
|
-
normalized = str((input/1000))[:14]
|
|
257
|
-
logger.debug(
|
|
262
|
+
normalized = str((input / 1000))[:14]
|
|
263
|
+
logger.debug(
|
|
264
|
+
"Normalizing timestamp for postgresql from %s to %s",
|
|
265
|
+
input,
|
|
266
|
+
normalized,
|
|
267
|
+
)
|
|
258
268
|
return float(normalized)
|
|
259
269
|
elif len(str(input)) == 16:
|
|
260
|
-
normalized = str(input/1000000)[:14]
|
|
261
|
-
logger.debug(
|
|
270
|
+
normalized = str(input / 1000000)[:14]
|
|
271
|
+
logger.debug(
|
|
272
|
+
"Normalizing timestamp for postgresql from %s to %s",
|
|
273
|
+
input,
|
|
274
|
+
normalized,
|
|
275
|
+
)
|
|
262
276
|
return float(normalized)
|
|
263
277
|
elif isinstance(input, float):
|
|
264
278
|
# elif '.' in str(input):
|
|
265
|
-
decimal_index = str.index(str(input),
|
|
279
|
+
decimal_index = str.index(str(input), ".")
|
|
266
280
|
if decimal_index == 13:
|
|
267
|
-
normalized = str(input/1000)[:14] # remove microsecond precision
|
|
268
|
-
logger.debug(
|
|
281
|
+
normalized = str(input / 1000)[:14] # remove microsecond precision
|
|
282
|
+
logger.debug(
|
|
283
|
+
"Normalizing timestamp for postgresql from %s to %s",
|
|
284
|
+
input,
|
|
285
|
+
normalized,
|
|
286
|
+
)
|
|
269
287
|
return float(normalized)
|
|
270
288
|
elif decimal_index == 10:
|
|
271
289
|
normalized = str(input)[:14] # remove microsecond precision
|
|
272
|
-
logger.debug(
|
|
290
|
+
logger.debug(
|
|
291
|
+
"Normalizing timestamp for postgresql from %s to %s",
|
|
292
|
+
input,
|
|
293
|
+
normalized,
|
|
294
|
+
)
|
|
273
295
|
return float(normalized)
|
|
274
296
|
elif isinstance(input, str):
|
|
275
297
|
if len(input) == 20:
|
|
276
298
|
obj_from_iso = convert_iso_string_to_datetime_obj(input)
|
|
277
|
-
unix_with_subseconds = get_timestamp_unix_subseconds_decimal(
|
|
299
|
+
unix_with_subseconds = get_timestamp_unix_subseconds_decimal(
|
|
300
|
+
obj_from_iso
|
|
301
|
+
)
|
|
278
302
|
normalized = unix_with_subseconds
|
|
279
|
-
logger.debug(
|
|
303
|
+
logger.debug(
|
|
304
|
+
"Normalizing timestamp for postgresql from %s to %s",
|
|
305
|
+
input,
|
|
306
|
+
normalized,
|
|
307
|
+
)
|
|
280
308
|
return float(normalized)
|
|
281
309
|
if len(input) == 24:
|
|
282
310
|
obj_from_iso = convert_iso_string_to_datetime_obj(input)
|
|
283
|
-
unix_with_subseconds = get_timestamp_unix_subseconds_decimal(
|
|
311
|
+
unix_with_subseconds = get_timestamp_unix_subseconds_decimal(
|
|
312
|
+
obj_from_iso
|
|
313
|
+
)
|
|
284
314
|
normalized = unix_with_subseconds
|
|
285
|
-
logger.debug(
|
|
315
|
+
logger.debug(
|
|
316
|
+
"Normalizing timestamp for postgresql from %s to %s",
|
|
317
|
+
input,
|
|
318
|
+
normalized,
|
|
319
|
+
)
|
|
286
320
|
return float(normalized)
|
|
287
321
|
elif len(input) == 27:
|
|
288
322
|
obj_from_iso = convert_iso_string_to_datetime_obj(input)
|
|
289
|
-
unix_with_subseconds = get_timestamp_unix_subseconds_decimal(
|
|
323
|
+
unix_with_subseconds = get_timestamp_unix_subseconds_decimal(
|
|
324
|
+
obj_from_iso
|
|
325
|
+
)
|
|
290
326
|
normalized = str(unix_with_subseconds)[:14]
|
|
291
|
-
logger.debug(
|
|
327
|
+
logger.debug(
|
|
328
|
+
"Normalizing timestamp for postgresql from %s to %s",
|
|
329
|
+
input,
|
|
330
|
+
normalized,
|
|
331
|
+
)
|
|
292
332
|
return float(normalized)
|
|
293
333
|
else:
|
|
294
334
|
logger.error("Unexcpected timestamp format")
|
|
295
335
|
except Exception as msg:
|
|
296
|
-
logger.exception(msg)
|
|
336
|
+
logger.exception(msg)
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
python_time_functions-2.1.1.dist-info/licenses/LICENSE,sha256=HrhfyXIkWY2tGFK11kg7vPCqhgh5DcxleloqdhrpyMY,11558
|
|
2
|
-
time_fuctions_cornebester/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
3
|
-
time_fuctions_cornebester/time_functions.py,sha256=1d5rXRnwOF8DEwk9ftZhFmBTIsGyTSsLjrhsWsm6Gk8,13117
|
|
4
|
-
python_time_functions-2.1.1.dist-info/METADATA,sha256=IOVKwLr9TU3h3pTTwjrk8sPS4t4HlZeS5PK81KrZYnc,244
|
|
5
|
-
python_time_functions-2.1.1.dist-info/WHEEL,sha256=aeYiig01lYGDzBgS8HxWXOg3uV61G9ijOsup-k9o1sk,91
|
|
6
|
-
python_time_functions-2.1.1.dist-info/top_level.txt,sha256=H10NGHYk5nQHSfC08IqJHO3ZcuOLBTf9FOGC2YHPGtY,26
|
|
7
|
-
python_time_functions-2.1.1.dist-info/RECORD,,
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
time_fuctions_cornebester
|
|
File without changes
|
{python_time_functions-2.1.1.dist-info → python_time_functions-2.1.3.dist-info}/licenses/LICENSE
RENAMED
|
File without changes
|
|
File without changes
|