larzduration
Parse compact duration strings, and back.
Parses "1d2h3m4s"-style strings (any subset of the units, in order) into whole seconds, and format() does the reverse - the compact, no-spaces form, so parse(format(n)) round-trips exactly. The spaced-out reading form ("1d 2h 3m") is time.humanize()'s job; this one is built to round-trip.
larzscript pkg install duration
What you get
- Parses any subset/order of d/h/m/s units
- format() is the exact inverse - round-trips
- Throws a clear error on malformed input
- Compact form, unlike time's spaced humanize()
Try it
import "duration" as duration
print(duration.parse("1d2h3m4s"))
print(duration.parse("90s"))
print(duration.format(93784))Output
93784 90 1d2h3m4s
Why it's in the Larz Stack
larzduration is a real Larzscript package (larzscript pkg install duration) - money-native, zero dependencies, the same language as the rest of the estate, not a separate Python runtime. It composes with the rest of the Larz Stack and the Larz framework.