2020-10-11 14:12:34 +00:00
|
|
|
package z
|
|
|
|
|
|
|
|
import (
|
2020-10-11 20:14:22 +00:00
|
|
|
"errors"
|
2020-10-11 14:12:34 +00:00
|
|
|
"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 {
|
|
|
|
return Entry{}, err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if finish != "" {
|
|
|
|
finishTime, err = ParseTime(finish)
|
|
|
|
if err != nil {
|
|
|
|
return Entry{}, err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-10-11 20:14:36 +00:00
|
|
|
if finishTime.Before(beginTime) && finishTime.IsZero() == false {
|
|
|
|
return Entry{}, errors.New("Beginning time of tracking cannot be after the finish time!")
|
|
|
|
}
|
|
|
|
|
2020-10-11 14:12:34 +00:00
|
|
|
return Entry{
|
|
|
|
id,
|
|
|
|
beginTime,
|
|
|
|
finishTime,
|
|
|
|
project,
|
|
|
|
task,
|
|
|
|
user,
|
|
|
|
}, nil
|
|
|
|
}
|