This snippet does what $duration should do and converts a string like 2w4d10h3m2s into seconds. Usage is $lduration(string) where string should be formatted as above. Accepted time measures are the same as for $duration and include w, d, h, m, and s. Poorly formatted strings, such as 5m2h4m, are okay (the previous example would be evaluated the same as 2h9m).
alias lduration {
if ( $regex($1,/[^wdhms\d]/) || $regex($1,/[wdhms]{2}/) || $1 isnum || $1 isalpha || $right($1,1) isnum ) {
return $null
}
var %str = $1,%tot = 0,%x = 1
while ( %str ) {
.echo -q $regsub(%x,%str,/(\d+[a-z])/i,$null,%str)
inc %tot $duration($regml(%x,1))
inc %x
}
return %tot
}