accept loop param on task

This commit is contained in:
Bel LaPointe
2021-07-17 10:34:22 -06:00
parent 6abfab229a
commit 81c8743de7
5 changed files with 34 additions and 12 deletions

View File

@@ -60,6 +60,11 @@ func ToStrArr(k string) []string {
return outArr
}
func ToDuration(s string) time.Duration {
d, _ := time.ParseDuration(s)
return d
}
func ToTime(s string) time.Time {
v, err := time.Parse("2006-01-02 15:04:05", s)
if err != nil || v.IsZero() {

View File

@@ -23,6 +23,7 @@ type Task struct {
Complete bool
Note []string
Due time.Time
Loop time.Duration
Index int
}
@@ -42,8 +43,8 @@ func New(r *http.Request) (*Task, error) {
Tags: append(StrList(form.ToStrArr(form.Get(r, "tag"))), StrList(form.ToStrArr(form.Get(r, "tags")))...),
Created: time.Now(),
Edited: time.Now(),
Due: form.ToTime(form.Get(r, "duedate")),
Due: form.ToTime(form.Get(r, "duedate")),
Loop: form.ToDuration(form.Get(r, "loop")),
}
task.SetNote(form.Get(r, "note"))
return task, task.validate()
@@ -73,7 +74,8 @@ func (t *Task) MarshalJSON() ([]byte, error) {
// "dueClass":"",
// "dueStr":"",
// "dueInt":33330000,
// "dueTitle":"Due "}
// "dueTitle":"Due ",
// "loop": "1m"}
// ]}
fullFormat := "02 Jan 2006 03:04 PM"
shortFormat := "02 Jan"
@@ -109,6 +111,7 @@ func (t *Task) MarshalJSON() ([]byte, error) {
"dueStr": t.Due.Format(shortFormat),
"dueInt": t.Due.Unix(),
"dueTitle": "Due ",
"loop": t.Loop.String(),
}
if t.Due.IsZero() {
for k := range m {