From 7175fc17d37c2c68d74adaf565dd0c1cfd4fb00b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E3=83=9E=E3=83=AA=E3=82=A6=E3=82=B9?= Date: Thu, 15 Oct 2020 23:52:59 +0100 Subject: [PATCH] Implemented importTyme module --- z/importTyme.go | 49 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 z/importTyme.go diff --git a/z/importTyme.go b/z/importTyme.go new file mode 100644 index 0000000..b8198bb --- /dev/null +++ b/z/importTyme.go @@ -0,0 +1,49 @@ +package z + +import ( + "encoding/json" + // "fmt" + "os" + // "github.com/shopspring/decimal" + // "time" +) + +type TymeEntry struct { + Billing string `json:"billing"` // "UNBILLED", + Category string `json:"category"` // "Client", + Distance string `json:"distance"` // "0", + Duration string `json:"duration"` // "15", + End string `json:"end"` // "2020-09-01T08:57:00+01:00", + Note string `json:"note"` // "", + Project string `json:"project"` // "Project", + Quantity string `json:"quantity"` // "0", + Rate string `json:"rate"` // "140", + RoundingMethod string `json:"rounding_method"` // "NEAREST", + RoundingMinutes int `json:"rounding_minutes"` // 15, + Start string `json:"start"` // "2020-09-01T08:45:00+01:00", + Subtask string `json:"subtask"` // "", + Sum string `json:"sum"` // "35", + Task string `json:"task"` // "Development", + Type string `json:"type"` // "timed", + User string `json:"user"` // "" +} + +type Tyme struct { + Data []TymeEntry `json:"data"` +} + +func (tyme *Tyme) Load(filename string) error { + file, err := os.Open(filename) + if err != nil { + return err + } + defer file.Close() + + decoder := json.NewDecoder(file) + + if err = decoder.Decode(&tyme); err != nil { + return err + } + + return nil +}