Thanks Bob. I agree that custom formatting and parsing would be useful additions. I’ve logged a feature request covering these, together with finite value limits.
One clarification: the current implementation of ToString() already preserves fractional seconds down to tick precision. For example:
Print(250.Milliseconds().ToString()) # 00:00:00.2500000
It omits the fractional part when it’s zero. If you’re seeing fractional seconds disappear from a non-zero value, please share a small example and your Studio version.
The proposed additions would follow Objo’s existing value-type APIs:
ToString(format As String) and ToString(format As String, locale As Locale).
- Shared
Parse() and TryParse() methods, including locale overloads. TryParse() would return a Boolean and write the result through a ByRef parameter.
- Read-only shared
Duration.MinValue and Duration.MaxValue properties representing the finite limits.
For formatting, I’m proposing "c" for the existing invariant representation, "O" as an explicit round-trip alias, "g"/"G" for compact/full representations, and custom duration formats for days, hours, minutes, seconds and fractional seconds. Hours would be the 0–23 component, with days handling longer durations.
For Infinite, I’d keep it printable as "Infinite" and allow parsing that text back to Duration.Infinite. That lets the sentinel round-trip without making ordinary display or logging throw an exception. MaxValue would remain distinct from Infinite.