summaryrefslogtreecommitdiff
path: root/model.go
diff options
context:
space:
mode:
authorJulian Jørgensen <julian@jtle.dk>2024-05-24 23:33:49 +0200
committerJulian Jørgensen <julian@jtle.dk>2024-05-24 23:33:49 +0200
commit6cdd02af0684500b5376d4d4a08feb796fdaf889 (patch)
tree7ffb2ded2251fef175f2c0ce6dfbea978152e063 /model.go
parenteabd0e769c2bfef7a7aa748d794675d3ff7a920b (diff)
Add date stuff
Diffstat (limited to 'model.go')
-rw-r--r--model.go23
1 files changed, 22 insertions, 1 deletions
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
+}