human_time() - Format Times
- Duration Formatting – Converts raw second values into clean, readable duration strings like
5 ms,45 s,1.50 h, or2 d. - Smart Decimal Precision – Auto-rounds and formats fractional durations cleanly up to 2 decimal places.
- Automatic Unit Escalation – Automatically escalates duration steps across ms, s, m, h, d, and w.
Signature
sizelib.human_time(seconds: int | float) -> strOutput Unit Hierarchy Scale
| Unit | Scale Divisors | Unit Escalation Order |
|---|---|---|
| Duration Units | 1000ms / 60s / 60m / 24h / 7d | ms → s → m → h → d → w |
human_time() - Usage
from sizelib import human_time, time
print(human_time(0.005)) # Output: 5 ms
print(human_time(time.s(45))) # Output: 45 s
print(human_time(time.m(90))) # Output: 1.50 h
print(human_time(time.h(2))) # Output: 2 h
print(human_time(time.d(1))) # Output: 1 d
human_time() - Edge Cases & Exceptions
from sizelib import human_time
# Zero second input
print(human_time(0)) # Output: 0 s
# Negative values raise ValueError
try:
human_time(-5)
except ValueError as e:
print(e) # Output: Time cannot be negative