aboutsummaryrefslogtreecommitdiffstats
path: root/todolist/util.go
diff options
context:
space:
mode:
authorDmitriyMV <codeprojtwo@gmail.com>2017-03-02 14:11:09 +0300
committerDmitriyMV <codeprojtwo@gmail.com>2017-03-04 05:29:35 +0300
commitee5353cf832a2fec57eacb77396a443e6d6a5b9e (patch)
treed6d812f982fd8df7afa0a42d16a4ad107dcc3352 /todolist/util.go
parentbe32789ec53ebe0a2141cf4d13696280ef79ee7f (diff)
This commit removes all usages of github.com/jinzhu/now.
github.com/jinzhu/now has numerous errors handling date and time. The example's of them are: 1. Incorrect handling of DST (https://github.com/jinzhu/now/issues/13). 2. 24 Hour long days (https://stackoverflow.com/questions/25254443/return-local-beginning-of-day-time-object-in-go) Chicago has 23, 24, or 25 hours in a day. 3. Incorrect usage of time.Truncate which can return time with a non-zero minute, depending on the time's Location. (https://github.com/golang/go/issues/16647). There are other issues as well, including getting incorrect beginning and end of the month.
Diffstat (limited to 'todolist/util.go')
-rw-r--r--todolist/util.go17
1 files changed, 17 insertions, 0 deletions
diff --git a/todolist/util.go b/todolist/util.go
index bbed216..72d475f 100644
--- a/todolist/util.go
+++ b/todolist/util.go
@@ -1,5 +1,7 @@
package todolist
+import "time"
+
func AddIfNotThere(arr []string, items []string) []string {
for _, item := range items {
there := false
@@ -27,3 +29,18 @@ func AddTodoIfNotThere(arr []*Todo, item *Todo) []*Todo {
}
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 getNearestMonday(t time.Time) time.Time {
+ for {
+ if t.Weekday() != time.Monday {
+ t = t.AddDate(0, 0, -1)
+ } else {
+ return t
+ }
+ }
+}