Skip to content

Instantly share code, notes, and snippets.

@pstuifzand
Last active August 26, 2017 22:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pstuifzand/a832320ae506a51fec55ebabd3363512 to your computer and use it in GitHub Desktop.
Save pstuifzand/a832320ae506a51fec55ebabd3363512 to your computer and use it in GitHub Desktop.
Format duration in Perl6
sub format-duration(Duration:D $d --> Str) {
join "", reverse ($d.Rat.polymod(60, 60, 24) Z <s m h d>).grep:{$_[0] != 0} or "0s"
}
sub format-duration2(Duration:D $d --> Str) {
($d.Rat.polymod(60, 60, 24) Z <s m h d>).grep({$_[0] != 0}).reverse.flat.join("") or "0s";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment