diff options
author | Andinus <andinus@nand.sh> | 2021-08-11 15:26:15 +0530 |
---|---|---|
committer | Andinus <andinus@nand.sh> | 2021-08-11 15:26:15 +0530 |
commit | 321825828ac918bad28d0597a8616c6dc9802c3c (patch) | |
tree | 0b8e9cb1012197750eb58e972736319b2a6abac2 /raku/clock/Clock.rakumod | |
parent | 2979ef790ac5b8f58495e0dd08cafd6a3a2e30a5 (diff) | |
download | exercism-321825828ac918bad28d0597a8616c6dc9802c3c.tar.gz |
Add solved exercises
Diffstat (limited to 'raku/clock/Clock.rakumod')
-rw-r--r-- | raku/clock/Clock.rakumod | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/raku/clock/Clock.rakumod b/raku/clock/Clock.rakumod new file mode 100644 index 0000000..cf2b5d4 --- /dev/null +++ b/raku/clock/Clock.rakumod @@ -0,0 +1,27 @@ +unit class Clock; + +has Int $.hour; +has Int $.minute; + +submethod TWEAK() { self.wrap-time; } + +method time { sprintf "%02d:%02d", $!hour, $!minute; } + +method add-minutes(UInt $amount --> Clock) { + $!hour += $amount div 60; + $!minute += $amount % 60; + self.wrap-time; +} + +method subtract-minutes(UInt $amount --> Clock) { + $!hour -= $amount div 60; + $!minute -= $amount % 60; + self.wrap-time; +} + +method wrap-time(--> Clock) { + $!hour += $!minute div 60; + $!minute %= 60; + $!hour %= 24; + return self; +} |