~ewintr/gte

93ac14f539941ffd1e954a853b79069e3706c9c6 — Erik Winter a month ago 9557525 master
date parsing without spaces
2 files changed, 21 insertions(+), 67 deletions(-)

M internal/task/date.go
M internal/task/date_test.go
M internal/task/date.go => internal/task/date.go +5 -9
@@ 98,39 98,35 @@ func NewDateFromString(date string) Date {
	switch date {
	case "":
		fallthrough
	case "no-date":
		fallthrough
	case "no date":
		return Date{}

	case "today":
		fallthrough
	case "vandaag":
		return Today

	case "tomorrow":
		fallthrough
	case "morgen":
		return Today.AddDays(1)

	case "day after tomorrow":
		fallthrough
	case "overmorgen":
	case "day-after-tomorrow":
		return Today.AddDays(2)

	case "this week":
		fallthrough
	case "deze week":
	case "this-week":
		daysToAdd := findDaysToWeekday(Today.Weekday(), time.Friday)
		return Today.Add(daysToAdd)

	case "next week":
		fallthrough
	case "volgende week":
	case "next-week":
		daysToAdd := findDaysToWeekday(Today.Weekday(), time.Friday) + 7
		return Today.Add(daysToAdd)

	case "this sprint":
		fallthrough
	case "deze sprint":
		tDate := NewDate(2021, 1, 28) // a sprint end
		for {
			if tDate.After(Today) {

M internal/task/date_test.go => internal/task/date_test.go +16 -58
@@ 131,20 131,15 @@ func TestNewDateFromString(t *testing.T) {
			exp   task.Date
		}{
			{
				name:  "english dayname lowercase",
				name:  "dayname lowercase",
				input: "monday",
				exp:   task.NewDate(2021, 2, 1),
			},
			{
				name:  "english dayname capitalized",
				name:  "dayname capitalized",
				input: "Monday",
				exp:   task.NewDate(2021, 2, 1),
			},
			{
				name:  "dutch dayname lowercase",
				input: "maandag",
				exp:   task.NewDate(2021, 2, 1),
			},
		} {
			t.Run(tc.name, func(t *testing.T) {
				test.Equals(t, tc.exp, task.NewDateFromString(tc.input))


@@ 155,63 150,32 @@ func TestNewDateFromString(t *testing.T) {
	t.Run("relative days", func(t *testing.T) {
		task.Today = task.NewDate(2021, 1, 30)
		for _, tc := range []struct {
			name  string
			input string
			exp   task.Date
			name string
			exp  task.Date
		}{
			{
				name:  "today english",
				input: "today",
				exp:   task.NewDate(2021, 1, 30),
				name: "today",
				exp:  task.NewDate(2021, 1, 30),
			},
			{
				name:  "today dutch",
				input: "vandaag",
				exp:   task.NewDate(2021, 1, 30),
			},
			{
				name:  "tomorrow english",
				input: "tomorrow",
				exp:   task.NewDate(2021, 1, 31),
				name: "tomorrow",
				exp:  task.NewDate(2021, 1, 31),
			},
			{
				name:  "tomorrow dutch",
				input: "morgen",
				exp:   task.NewDate(2021, 1, 31),
				name: "day after tomorrow",
				exp:  task.NewDate(2021, 2, 1),
			},
			{
				name:  "day after tomorrow english",
				input: "day after tomorrow",
				exp:   task.NewDate(2021, 2, 1),
				name: "this week",
				exp:  task.NewDate(2021, 2, 5),
			},
			{
				name:  "day after tomorrow dutch",
				input: "overmorgen",
				exp:   task.NewDate(2021, 2, 1),
			},
			{
				name:  "this week english",
				input: "this week",
				exp:   task.NewDate(2021, 2, 5),
			},
			{
				name:  "this week dutch",
				input: "deze week",
				exp:   task.NewDate(2021, 2, 5),
			},
			{
				name:  "next week english",
				input: "next week",
				exp:   task.NewDate(2021, 2, 12),
			},
			{
				name:  "next week dutch",
				input: "volgende week",
				exp:   task.NewDate(2021, 2, 12),
				name: "next week",
				exp:  task.NewDate(2021, 2, 12),
			},
		} {
			t.Run(tc.name, func(t *testing.T) {
				test.Equals(t, tc.exp, task.NewDateFromString(tc.input))
				test.Equals(t, tc.exp, task.NewDateFromString(tc.name))
			})
		}
	})


@@ 224,18 188,12 @@ func TestNewDateFromString(t *testing.T) {
			exp   task.Date
		}{
			{
				name:  "this sprint english",
				name:  "this sprint",
				today: task.NewDate(2021, 1, 30),
				input: "this sprint",
				exp:   task.NewDate(2021, 2, 11),
			},
			{
				name:  "this sprint dutch",
				today: task.NewDate(2021, 1, 30),
				input: "deze sprint",
				exp:   task.NewDate(2021, 2, 11),
			},
			{
				name:  "jump week",
				today: task.NewDate(2021, 2, 5),
				input: "this sprint",