summary refs log tree commit diff stats
path: root/raku/clock/Clock.rakumod
diff options
context:
space:
mode:
Diffstat (limited to 'raku/clock/Clock.rakumod')
-rw-r--r--raku/clock/Clock.rakumod27
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;
+}