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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
|
package todolist
import "time"
func AddIfNotThere(arr []string, items []string) []string {
for _, item := range items {
there := false
for _, arrItem := range arr {
if item == arrItem {
there = true
}
}
if !there {
arr = append(arr, item)
}
}
return arr
}
func AddTodoIfNotThere(arr []*Todo, item *Todo) []*Todo {
there := false
for _, arrItem := range arr {
if item.Id == arrItem.Id {
there = true
}
}
if !there {
arr = append(arr, item)
}
return arr
}
func bod(t time.Time) time.Time {
year, month, day := t.Date()
return time.Date(year, month, day, 0, 0, 0, 0, t.Location())
}
func timestamp(t time.Time) time.Time {
year, month, day := t.Date()
hour, min, sec := t.Clock()
return time.Date(year, month, day, hour, min, sec, 0, t.Location())
}
func getNearestMonday(t time.Time) time.Time {
for {
if t.Weekday() != time.Monday {
t = t.AddDate(0, 0, -1)
} else {
return t
}
}
}
func pluralize(count int, singular, plural string) string {
if count > 1 {
return plural
}
return singular
}
func isToday(t time.Time) bool {
nowYear, nowMonth, nowDay := time.Now().Date()
timeYear, timeMonth, timeDay := t.Date()
return nowYear == timeYear &&
nowMonth == timeMonth &&
nowDay == timeDay
}
func isTomorrow(t time.Time) bool {
nowYear, nowMonth, nowDay := time.Now().AddDate(0, 0, 1).Date()
timeYear, timeMonth, timeDay := t.Date()
return nowYear == timeYear &&
nowMonth == timeMonth &&
nowDay == timeDay
}
func isPastDue(t time.Time) bool {
return time.Now().After(t)
}
|