Function goose::util::parse_timespan [−][src]
Expand description
Parse a string representing a time span and return the number of seconds.
Can be specified as an integer, indicating seconds. Or can use integers together with one or more of “h”, “m”, and “s”, in that order, indicating “hours”, “minutes”, and “seconds”.
Valid formats include: 20, 20s, 3m, 2h, 1h20m, 3h30m10s, etc.
Example
use goose::util;
// 1 hour 2 minutes and 3 seconds is 3,723 seconds.
assert_eq!(util::parse_timespan("1h2m3s"), 3_723);
// 45 seconds is 45 seconds.
assert_eq!(util::parse_timespan("45"), 45);
// Invalid value is 0 seconds.
assert_eq!(util::parse_timespan("foo"), 0);