mentortools/libs/: time-tools-abm-2.0.75950 metadata and description

Simple index

Tools to organise consistent and fail proof time-based logic

author Mike Orlov
author_email m.orlov@technokert.ru
classifiers
  • Programming Language :: Python :: 3
  • Programming Language :: Python :: 3.11
description_content_type text/markdown
requires_python >=3.11,<4.0
File Tox results History
time_tools_abm-2.0.75950-py3-none-any.whl
Size
6 KB
Type
Python Wheel
Python
3
time_tools_abm-2.0.75950.tar.gz
Size
4 KB
Type
Source

Time tools

Tools to organise consistent and fail proof time-based logic

Minimal usage example

import datetime
from time_tools import TimestampSec, Timerange
utc = datetime.timezone.utc

# Timestamp
some_client_timestamp_sec = 1234567890
other_client_timestamp_ms = 1234567890000
assert TimestampSec(some_client_timestamp_sec) == TimestampSec(other_client_timestamp_ms)

# TimeRange
allowed_timerange = Timerange(
    datetime.datetime(2024, 1, 1, tzinfo=utc),
    datetime.datetime(2024, 2, 1, tzinfo=utc)
)
desired_timerange = Timerange(
    datetime.datetime(2024, 1, 15, tzinfo=utc),
    datetime.datetime(2024, 2, 15, tzinfo=utc)
)
target_timerange = desired_timerange.intersection(allowed_timerange)
print(target_timerange.to_date_str())
assert target_timerange == Timerange(
    datetime.datetime(2024, 1, 15, tzinfo=utc),
    datetime.datetime(2024, 2, 1, tzinfo=utc)
)