ISO 8601 durations¶
HMSTime.from_iso8601() and to_iso8601() support full ISO 8601 duration syntax.
Time only¶
from hmscalc import HMSTime
HMSTime.from_iso8601("PT1H30M15S") # "1:30:15"
HMSTime.from_iso8601("PT30M") # "0:30:00"
Date components¶
HMSTime.from_iso8601("P1D") # 24:00:00
HMSTime.from_iso8601("P1W") # 168:00:00 (1 week)
HMSTime.from_iso8601("P1DT2H") # 26:00:00
Nominal months and years¶
Calendar months/years are converted using fixed nominal lengths:
| Component | Seconds |
|---|---|
P1M |
30 days |
P1Y |
365 days |
This matches hmscalc's second-based duration model. For calendar-accurate month arithmetic, combine with hmscalc.dates instead.
Output¶
HMSTime("24:00:00").to_iso8601() # "P1D"
HMSTime("168:00:00").to_iso8601() # "P1W"
HMSTime("26:00:00").to_iso8601() # "P1DT2H"
Limitations¶
P1Wcannot be combined with other date/time components (ISO 8601 rule).P1MbeforeTis a month;PT1MafterTis a minute.