Created
September 24, 2016 01:27
-
-
Save solson/c28d547b5d3445f2a04cc5ed905dc099 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env perl6 | |
sub format-duration(Int $milliseconds where * >= 0) returns Str { | |
my ($ms, $s, $m, $h, $d) = $milliseconds.polymod(1000, 60, 60, 24); | |
my $ms-hundreds = ($ms / 100).round; | |
if $d { | |
"{$d}d {$h}h {$m}m {$s}s" | |
} elsif $h { | |
"{$h}h {$m}m {$s}s" | |
} elsif $m { | |
"{$m}m {$s}s" | |
} else { | |
"{$s}.{$ms-hundreds}s" | |
} | |
} | |
sub MAIN(Int $milliseconds where * >= 0) { | |
say format-duration($milliseconds); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment