diff options
| -rw-r--r-- | todolist/formatter.go | 4 | ||||
| -rw-r--r-- | todolist/parser.go | 14 |
2 files changed, 14 insertions, 4 deletions
diff --git a/todolist/formatter.go b/todolist/formatter.go index b259f6a..db4aa4b 100644 --- a/todolist/formatter.go +++ b/todolist/formatter.go @@ -62,7 +62,9 @@ func (f *Formatter) formatDue(due string) string { dueTime, err := time.Parse("2006-01-02", due) if err != nil { - panic(err) + fmt.Println(err) + fmt.Println("This may due to the corruption of .todos.json file.") + os.Exit(-1) } if isToday(dueTime) { diff --git a/todolist/parser.go b/todolist/parser.go index 767785b..b16dccb 100644 --- a/todolist/parser.go +++ b/todolist/parser.go @@ -2,6 +2,7 @@ package todolist import ( "fmt" + "os" "regexp" "strconv" "strings" @@ -109,14 +110,21 @@ func (p *Parser) parseArbitraryDate(_date string, pivot time.Time) string { func (p *Parser) parseArbitraryDateWithYear(_date string, year int) time.Time { res := strings.Join([]string{_date, strconv.Itoa(year)}, " ") - if date, err := time.Parse("Jan 2 2006", res); err == nil { + var date time.Time + var err1 error + var err2 error + if date, err1 = time.Parse("Jan 2 2006", res); err1 == nil { return date } - if date, err := time.Parse("2 Jan 2006", res); err == nil { + if date, err2 = time.Parse("2 Jan 2006", res); err2 == nil { return date } - panic(fmt.Errorf("Could not parse the date you gave me: '%s'", _date)) + fmt.Printf("Could not parse the date you gave me: %s\n", _date) + fmt.Println(err1) + fmt.Println(err2) + os.Exit(-1) + return time.Now() } func (p *Parser) monday(day time.Time) string { |
