From 6cdd02af0684500b5376d4d4a08feb796fdaf889 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julian=20J=C3=B8rgensen?= Date: Fri, 24 May 2024 23:33:49 +0200 Subject: Add date stuff --- model.go | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) (limited to 'model.go') diff --git a/model.go b/model.go index 96be9e4..b8d174c 100644 --- a/model.go +++ b/model.go @@ -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 +} -- cgit v1.2.3