From 8916d2fb7f8986e8e26612b4f8be24842c0ae73c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E3=83=9E=E3=83=AA=E3=82=A6=E3=82=B9?= Date: Sun, 11 Oct 2020 15:12:34 +0100 Subject: [PATCH] Implemented Entry --- z/entry.go | 54 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 z/entry.go diff --git a/z/entry.go b/z/entry.go new file mode 100644 index 0000000..f8174b3 --- /dev/null +++ b/z/entry.go @@ -0,0 +1,54 @@ +package z + +import ( + "log" + "time" +) + +type Entry struct { + ID string `json:"-"` + Begin time.Time `json:"begin,omitempty"` + Finish time.Time `json:"finish,omitempty"` + Project string `json:"project,omitempty"` + Task string `json:"task,omitempty"` + User string `json:"user,omitempty"` +} + +func NewEntry( + id string, + begin string, + finish string, + project string, + task string, + user string) (Entry, error) { + var beginTime time.Time + var finishTime time.Time + var err error + + if begin == "" { + beginTime = time.Now() + } else { + beginTime, err = ParseTime(begin) + if err != nil { + log.Fatalln("Could not parse begin time!") + return Entry{}, err + } + } + + if finish != "" { + finishTime, err = ParseTime(finish) + if err != nil { + log.Fatalln("Could not parse finish time!") + return Entry{}, err + } + } + + return Entry{ + id, + beginTime, + finishTime, + project, + task, + user, + }, nil +}