Time unit types. For transparency safety and readability.
Project description
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)) == 0 # Time units hold integers!
assert Seconds.fromRawUnit(Minutes, 0.5) == 500 # Better approach when fractions matter!
License
MIT
Project details
Release history Release notifications | RSS feed
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.1.0.tar.gz
(4.2 kB
view hashes)