-
- use MONKEY-TYPING;
-
- augment class Duration {
- method in-units(*%wanted-units (Bool :$seconds, Bool :$minutes, Bool :$hours, Bool :$days, Bool :$weeks)) {
- my $remaining-seconds = self.Int;
- my %units;
-
- for <weeks days hours minutes seconds> Z=> (604800, 86400, 3600, 60, 1) {
- if %wanted-units{.key} {
- %units{.key} = $remaining-seconds div .value;
- $remaining-seconds -= %units{.key} * .value;
- }
- }
-
- return %units;
- }
- }
-
- my $d = Duration.new(86400.rand.Int);
-
- say ~($d.in-units(:hours, :minutes)<hours minutes> Z, <hours minutes>)
-