diff options
| author | Grant Ammons <gammons@gmail.com> | 2016-05-06 17:40:04 -0400 |
|---|---|---|
| committer | Grant Ammons <gammons@gmail.com> | 2016-05-06 17:40:04 -0400 |
| commit | 8bb8317f1f29a7dd1b910931ebd12c739a5fa1cc (patch) | |
| tree | c1ed847774f1da14c068e8d7a6d2f10097383aac /todolist/parser_test.go | |
| parent | 8e77e4e86bbcffc1ca30b25ba26b0225a578df90 (diff) | |
Parse out arbitrary dates
This will parse out dates in the format of "mon dd", the month being a 3
letter month, and the date being just the day.
due mar 10
due sep 25
due oct 2
it will also "intelligently" guess the year, based upon which is the
shorter duration from time.Now(). for instance, if today's date is dec
25 and you schedule an event for jan 2, it will schedule it for the
following year.
Diffstat (limited to 'todolist/parser_test.go')
| -rw-r--r-- | todolist/parser_test.go | 32 |
1 files changed, 25 insertions, 7 deletions
diff --git a/todolist/parser_test.go b/todolist/parser_test.go index 9a2732c..2134a86 100644 --- a/todolist/parser_test.go +++ b/todolist/parser_test.go @@ -104,10 +104,28 @@ func TestTuesdayOnWednesday(t *testing.T) { assert.Equal("2016-05-03", parser.tuesday(now)) } -//func TestDueNextWeek(t *testing.T) { -// parser := &Parser{} -// -// fmt.Println("about to parse") -// todo := parser.Parse("do this thing with @bob and @mary due next week") -// fmt.Println(todo.Due) -//} +func TestDueOnSpecificDate(t *testing.T) { + assert := assert.New(t) + parser := &Parser{} + assert.Equal("2016-05-02", parser.Due("due may 2", time.Now())) +} + +func TestDueOnSpecificDateEuropean(t *testing.T) { + assert := assert.New(t) + parser := &Parser{} + assert.Equal("2016-05-02", parser.Due("due 2 may", time.Now())) +} + +func TestDueIntelligentlyChoosesCorrectYear(t *testing.T) { + assert := assert.New(t) + parser := &Parser{} + marchTime, _ := time.Parse("2006-01-02", "2016-03-25") + januaryTime, _ := time.Parse("2006-01-02", "2016-01-05") + septemberTime, _ := time.Parse("2006-01-02", "2016-09-25") + decemberTime, _ := time.Parse("2006-01-02", "2016-12-25") + + assert.Equal("2016-01-10", parser.parseArbitraryDate("jan 10", januaryTime)) + assert.Equal("2016-01-10", parser.parseArbitraryDate("jan 10", marchTime)) + assert.Equal("2017-01-10", parser.parseArbitraryDate("jan 10", septemberTime)) + assert.Equal("2017-01-10", parser.parseArbitraryDate("jan 10", decemberTime)) +} |
