summaryrefslogtreecommitdiff
path: root/go/clock/clock.go
diff options
context:
space:
mode:
authorDimitri Sokolyuk <demon@dim13.org>2016-08-25 03:13:39 +0200
committerDimitri Sokolyuk <demon@dim13.org>2016-08-25 03:13:39 +0200
commit509c5063d66e8bbef4ec1def1c99c318be51aceb (patch)
treeafc811c4781a4e317043e2a0237499defc168044 /go/clock/clock.go
Initial import
Diffstat (limited to 'go/clock/clock.go')
-rw-r--r--go/clock/clock.go29
1 files changed, 29 insertions, 0 deletions
diff --git a/go/clock/clock.go b/go/clock/clock.go
new file mode 100644
index 0000000..036a69b
--- /dev/null
+++ b/go/clock/clock.go
@@ -0,0 +1,29 @@
+package clock
+
+import "fmt"
+
+const testVersion = 4
+
+type Clock struct {
+ hour, minute int
+}
+
+func New(hour, minute int) Clock {
+ for minute < 0 {
+ minute += 60
+ hour -= 1
+ }
+ hour += minute / 60
+ for hour < 0 {
+ hour += 24
+ }
+ return Clock{hour % 24, minute % 60}
+}
+
+func (c Clock) String() string {
+ return fmt.Sprintf("%02d:%02d", c.hour, c.minute)
+}
+
+func (c Clock) Add(minutes int) Clock {
+ return New(c.hour, c.minute+minutes)
+}