Skip to content

Commit

Permalink
add timer
Browse files Browse the repository at this point in the history
  • Loading branch information
tamada committed Jun 7, 2021
1 parent 6ac6c77 commit 93adc82
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions timer.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package main

import "time"

type timer struct {
number int64
unit string
}

func (t *timer) Duration() time.Duration {
switch t.unit {
case "min":
return time.Duration(t.number) * time.Minute
case "nsec":
return time.Duration(t.number) * time.Nanosecond
case "usec": // micro seconds
return time.Duration(t.number) * time.Nanosecond * time.Duration(1000)
case "msec":
return time.Duration(t.number) * time.Nanosecond * time.Duration(1000000)
case "hour":
return time.Duration(t.number) * time.Hour
case "sec":
return time.Duration(t.number) * time.Second
default:
return time.Second
}
}

0 comments on commit 93adc82

Please sign in to comment.