Skip to main content

Time unit types. For transparency safety and readability.

Project description

PyPI pyversions PyPI version shields.io PyPI license Downloads

TUnit


Time unit types. For transparency, safety and readability.

Examples:

from tunit import Days, Hours, Minutes, Seconds, Milliseconds

# Type annotations:
def timestamp() -> Milliseconds:
    # Time unit conversions:
    return Milliseconds(Seconds(1))  # 1_000 ms

# Converting to smaller units:
assert Hours(Days(1)) == Hours(24) == 24

# Converting to bigger units:
assert Minutes(Seconds(65)) == Minutes(1) == 1

# Converting floats to time units:
assert Seconds(Minutes(0.5)) == Seconds(0) == 0  # Time units hold integers!
assert Seconds.fromRawUnit(Minutes, 0.5) == Seconds(500) == 500  # Better approach when fractions matter!

# Converting time units to floats:
assert float(Seconds(Milliseconds(1_500))) == 1.0  # Loses precision!
assert Milliseconds(1_500).toRawUnit(Seconds) == 1.5  # Converts to float representing different time unit with precision.

License

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

tunit-1.3.2.tar.gz (4.7 kB view details)

Uploaded Source

File details

Details for the file tunit-1.3.2.tar.gz.

File metadata

  • Download URL: tunit-1.3.2.tar.gz
  • Upload date:
  • Size: 4.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.7.16

File hashes

Hashes for tunit-1.3.2.tar.gz
Algorithm Hash digest
SHA256 63e35874d6633f4d8b8efc3daba1f6e2821551468c57b2f694eb6d26c2e543b1
MD5 c5cd15676f58c27b2457147db4535adc
BLAKE2b-256 7e34fb8d0b1b9735eaf1d38985368176db22c1fcf4e49f1ac722545917775fac

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page