diff options
Diffstat (limited to 'model.go')
-rw-r--r-- | model.go | 23 |
1 files changed, 22 insertions, 1 deletions
@@ -2,13 +2,14 @@ package main import ( "errors" + "log" "regexp" "time" ) type Entry struct { Id int - Date time.Time + Date Date From *Time To *Time Tag *string @@ -34,6 +35,18 @@ var ( ErrInvalidDate = errors.New("Invalid date string") ) +func NewEntry(date Date) *Entry { + return &Entry{ + Id: -1, + From: nil, + Date: date, + To: nil, + Tag: nil, + Comment: "", + } + +} + func TimeFromStd(time time.Time) Time { return Time(time.Format("15:04")) } @@ -67,3 +80,11 @@ func DateFromString(str string) (*Date, error) { date := Date(str) return &date, nil } + +func (d Date) ToStd() time.Time { + t, err := time.Parse("2006-01-02", string(d)) + if err != nil { + log.Fatal(err) + } + return t +} |