-
Notifications
You must be signed in to change notification settings - Fork 0
/
kizami.go
41 lines (37 loc) · 915 Bytes
/
kizami.go
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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
package kokizami
import (
"time"
)
// Kizami represents a task
type Kizami struct {
ID int
Desc string
StartedAt time.Time
StoppedAt time.Time
}
// Elapsed returns kizami's elapsed time
func (k *Kizami) Elapsed() time.Duration {
var elapsed time.Duration
if k.StoppedAt.Unix() == 0 {
// this Kizami is on going. Show elapsed time until now.
now := time.Now().UTC()
elapsed = now.Sub(k.StartedAt)
} else {
elapsed = k.StoppedAt.Sub(k.StartedAt)
if elapsed < 0 {
elapsed = 0
}
}
return elapsed
}
// KizamiRepository is an interface to fetch Kizami from repository
type KizamiRepository interface {
FindAll() ([]*Kizami, error)
Insert(desc string) (*Kizami, error)
Update(k *Kizami) error
Delete(k *Kizami) error
FindByID(id int) (*Kizami, error)
FindByStoppedAt(t time.Time) ([]*Kizami, error)
Tagging(kizamiID int, tagIDs []int) error
Untagging(kizamiID int) error
}