-
Notifications
You must be signed in to change notification settings - Fork 4
/
model.go
45 lines (38 loc) · 1.01 KB
/
model.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
// Copyright (C) 2014 Constantin Schomburg <me@cschomburg.com>
//
// Use of this source code is governed by an MIT-style
// license that can be found in the LICENSE file.
package scheduler
import (
"fmt"
"time"
"github.com/sarifsystems/sarif/sarif"
)
type Task struct {
Id int64 `json:"-"`
Time time.Time `json:"time,omitempty"`
Location string `json:"location,omitempty"`
Reply sarif.Message `json:"reply,omitempty"`
Finished bool `json:"finished"`
CreatedAt time.Time `json:"-"`
UpdatedAt time.Time `json:"-"`
}
func (t Task) Key() string {
return "scheduler/task/" + t.Time.UTC().Format(time.RFC3339Nano)
}
func (t Task) String() string {
text := t.Reply.Text
if text == "" {
text = t.Reply.Action
}
if t.Reply.Action == "schedule/finished" {
return fmt.Sprintf("Reminder for '%s' on %s set.",
text,
t.Time.Local().Format(time.RFC3339),
)
}
return fmt.Sprintf("Schedule task '%s' on %s.",
text,
t.Time.Local().Format(time.RFC3339),
)
}