blob: cf2b5d418a7a0a3091a023e72c301e50ee6ab989 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
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;
}
|