pub fn parse_duration(
text: &str,
i18n: &I18n,
) -> Result<Duration, DurationError>Expand description
Reads a length of time written by hand, in any language i18n knows.
Three forms are read:
- Numbers with units, in any order, each unit once:
1 h 30 min,1sa30dk,90 dk,2 hours,1,5 sa. The unit words come fromquvyta.duration.hour-words,minute-wordsandsecond-wordsof every language, the active one first; case does not matter, and Turkish dotted and dotless i read alike. A number after a unit with no unit of its own takes the next smaller one:1 h 30is an hour and a half. A decimal point or comma splits a unit (1.5 his 90 minutes), rounded to the second. Minutes and seconds may run past 60 and carry over:1 h 90 minis two hours and a half. - A clock face,
h:mmorh:mm:ss:2:15is two hours and a quarter, never two minutes. Minutes and seconds are one or two digits under 60. - A bare number, read in minutes:
25is 25 minutes, the length of most timers.
ยงErrors
A DurationError naming the first part that could not be read, or
DurationError::TooLarge past 99 hours, 59 minutes and 59 seconds.