-
Notifications
You must be signed in to change notification settings - Fork 0
/
taskformdata.go
52 lines (46 loc) · 982 Bytes
/
taskformdata.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
package tui
import (
"time"
"github.com/araddon/dateparse"
"github.com/csams/doit/pkg/apis"
)
type taskFormData struct {
Description string
Due string
State apis.State
Status apis.Status
Priority apis.Priority
Private bool
}
func (d *taskFormData) ApplyTo(t *apis.Task) error {
var due *time.Time
if d.Due != "" {
if dueDate, err := dateparse.ParseLocal(d.Due); err != nil {
return err
} else {
due = &dueDate
}
}
t.Description = d.Description
t.Due = due
t.State = d.State
t.Status = d.Status
t.Priority = d.Priority
t.Private = d.Private
return nil
}
func formDataFromTask(task *apis.Task) *taskFormData {
fmtString := "2006-01-02 15:04:05 MST"
var due string
if task.Due != nil {
due = task.Due.Format(fmtString)
}
return &taskFormData{
Description: task.Description,
Due: due,
State: task.State,
Status: task.Status,
Priority: task.Priority,
Private: task.Private,
}
}