spacepaste

  1.  
  2. use MONKEY-TYPING;
  3. augment class Duration {
  4. method in-units(*%wanted-units (Bool :$seconds, Bool :$minutes, Bool :$hours, Bool :$days, Bool :$weeks)) {
  5. my $remaining-seconds = self.Int;
  6. my %units;
  7. for <weeks days hours minutes seconds> Z=> (604800, 86400, 3600, 60, 1) {
  8. if %wanted-units{.key} {
  9. %units{.key} = $remaining-seconds div .value;
  10. $remaining-seconds -= %units{.key} * .value;
  11. }
  12. }
  13. return %units;
  14. }
  15. }
  16. my $d = Duration.new(86400.rand.Int);
  17. say ~($d.in-units(:hours, :minutes)<hours minutes> Z, <hours minutes>)
  18.