aboutsummaryrefslogtreecommitdiffstats
path: root/todolist/parser.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/parser.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/parser.go')
-rw-r--r--todolist/parser.go24
1 files changed, 11 insertions, 13 deletions
diff --git a/todolist/parser.go b/todolist/parser.go
index 6cf1967..24a4016 100644
--- a/todolist/parser.go
+++ b/todolist/parser.go
@@ -7,8 +7,6 @@ import (
"strconv"
"strings"
"time"
-
- "github.com/jinzhu/now"
)
type Parser struct{}
@@ -79,9 +77,9 @@ func (p *Parser) Due(input string, day time.Time) string {
case "none":
return ""
case "today", "tod":
- return now.BeginningOfDay().Format("2006-01-02")
+ return bod(time.Now()).Format("2006-01-02")
case "tomorrow", "tom":
- return now.BeginningOfDay().AddDate(0, 0, 1).Format("2006-01-02")
+ return bod(time.Now()).AddDate(0, 0, 1).Format("2006-01-02")
case "monday", "mon":
return p.monday(day)
case "tuesday", "tue":
@@ -97,8 +95,8 @@ func (p *Parser) Due(input string, day time.Time) string {
case "sunday", "sun":
return p.sunday(day)
case "next week":
- n := now.BeginningOfDay()
- return now.New(n).Monday().AddDate(0, 0, 7).Format("2006-01-02")
+ n := bod(time.Now())
+ return getNearestMonday(n).AddDate(0, 0, 7).Format("2006-01-02")
}
return p.parseArbitraryDate(res, time.Now())
}
@@ -137,37 +135,37 @@ func (p *Parser) parseArbitraryDateWithYear(_date string, year int) time.Time {
}
func (p *Parser) monday(day time.Time) string {
- mon := now.New(day).Monday()
+ mon := getNearestMonday(day)
return p.thisOrNextWeek(mon, day)
}
func (p *Parser) tuesday(day time.Time) string {
- tue := now.New(day).Monday().AddDate(0, 0, 1)
+ tue := getNearestMonday(day).AddDate(0, 0, 1)
return p.thisOrNextWeek(tue, day)
}
func (p *Parser) wednesday(day time.Time) string {
- tue := now.New(day).Monday().AddDate(0, 0, 2)
+ tue := getNearestMonday(day).AddDate(0, 0, 2)
return p.thisOrNextWeek(tue, day)
}
func (p *Parser) thursday(day time.Time) string {
- tue := now.New(day).Monday().AddDate(0, 0, 3)
+ tue := getNearestMonday(day).AddDate(0, 0, 3)
return p.thisOrNextWeek(tue, day)
}
func (p *Parser) friday(day time.Time) string {
- tue := now.New(day).Monday().AddDate(0, 0, 4)
+ tue := getNearestMonday(day).AddDate(0, 0, 4)
return p.thisOrNextWeek(tue, day)
}
func (p *Parser) saturday(day time.Time) string {
- tue := now.New(day).Monday().AddDate(0, 0, 5)
+ tue := getNearestMonday(day).AddDate(0, 0, 5)
return p.thisOrNextWeek(tue, day)
}
func (p *Parser) sunday(day time.Time) string {
- tue := now.New(day).Monday().AddDate(0, 0, 6)
+ tue := getNearestMonday(day).AddDate(0, 0, 6)
return p.thisOrNextWeek(tue, day)
}