fix end sprint calculation
This commit is contained in:
parent
8d708f66ad
commit
ee1aad104b
|
@ -131,14 +131,13 @@ func NewDateFromString(date string) Date {
|
||||||
case "this sprint":
|
case "this sprint":
|
||||||
fallthrough
|
fallthrough
|
||||||
case "deze sprint":
|
case "deze sprint":
|
||||||
aSprintStart := NewDate(2021, 1, 29)
|
tDate := NewDate(2021, 1, 28) // a sprint end
|
||||||
daysToAdd := findDaysToWeekday(Today.Weekday(), time.Thursday)
|
for {
|
||||||
diff := aSprintStart.DaysBetween(Today.AddDays(daysToAdd))
|
if tDate.After(Today) {
|
||||||
if diff%14 != 0 {
|
return tDate
|
||||||
daysToAdd += 7
|
}
|
||||||
|
tDate = tDate.AddDays(14)
|
||||||
}
|
}
|
||||||
|
|
||||||
return Today.AddDays(daysToAdd)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
t, err := time.Parse("2006-01-02", fmt.Sprintf("%.10s", date))
|
t, err := time.Parse("2006-01-02", fmt.Sprintf("%.10s", date))
|
||||||
|
|
|
@ -75,111 +75,180 @@ func TestWeekdaysUnique(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestNewDateFromString(t *testing.T) {
|
func TestNewDateFromString(t *testing.T) {
|
||||||
task.Today = task.NewDate(2021, 1, 30)
|
|
||||||
for _, tc := range []struct {
|
t.Run("no date", func(t *testing.T) {
|
||||||
name string
|
task.Today = task.NewDate(2021, 1, 30)
|
||||||
input string
|
for _, tc := range []struct {
|
||||||
exp task.Date
|
name string
|
||||||
}{
|
input string
|
||||||
{
|
exp task.Date
|
||||||
name: "empty",
|
}{
|
||||||
exp: task.Date{},
|
{
|
||||||
},
|
name: "empty",
|
||||||
{
|
exp: task.Date{},
|
||||||
name: "no date",
|
},
|
||||||
input: "no date",
|
{
|
||||||
exp: task.Date{},
|
name: "no date",
|
||||||
},
|
input: "no date",
|
||||||
{
|
exp: task.Date{},
|
||||||
name: "normal",
|
},
|
||||||
input: "2021-01-30 (saturday)",
|
} {
|
||||||
exp: task.NewDate(2021, 1, 30),
|
t.Run(tc.name, func(t *testing.T) {
|
||||||
},
|
test.Equals(t, tc.exp, task.NewDateFromString(tc.input))
|
||||||
{
|
})
|
||||||
name: "short",
|
}
|
||||||
input: "2021-01-30",
|
})
|
||||||
exp: task.NewDate(2021, 1, 30),
|
|
||||||
},
|
t.Run("digits", func(t *testing.T) {
|
||||||
{
|
task.Today = task.NewDate(2021, 1, 30)
|
||||||
name: "english dayname lowercase",
|
for _, tc := range []struct {
|
||||||
input: "monday",
|
name string
|
||||||
exp: task.NewDate(2021, 2, 1),
|
input string
|
||||||
},
|
exp task.Date
|
||||||
{
|
}{
|
||||||
name: "english dayname capitalized",
|
{
|
||||||
input: "Monday",
|
name: "normal",
|
||||||
exp: task.NewDate(2021, 2, 1),
|
input: "2021-01-30 (saturday)",
|
||||||
},
|
exp: task.NewDate(2021, 1, 30),
|
||||||
{
|
},
|
||||||
name: "dutch dayname lowercase",
|
{
|
||||||
input: "maandag",
|
name: "short",
|
||||||
exp: task.NewDate(2021, 2, 1),
|
input: "2021-01-30",
|
||||||
},
|
exp: task.NewDate(2021, 1, 30),
|
||||||
{
|
},
|
||||||
name: "today english",
|
} {
|
||||||
input: "today",
|
t.Run(tc.name, func(t *testing.T) {
|
||||||
exp: task.NewDate(2021, 1, 30),
|
test.Equals(t, tc.exp, task.NewDateFromString(tc.input))
|
||||||
},
|
|
||||||
{
|
})
|
||||||
name: "today dutch",
|
}
|
||||||
input: "vandaag",
|
})
|
||||||
exp: task.NewDate(2021, 1, 30),
|
|
||||||
},
|
t.Run("day name", func(t *testing.T) {
|
||||||
{
|
task.Today = task.NewDate(2021, 1, 30)
|
||||||
name: "tomorrow english",
|
for _, tc := range []struct {
|
||||||
input: "tomorrow",
|
name string
|
||||||
exp: task.NewDate(2021, 1, 31),
|
input string
|
||||||
},
|
exp task.Date
|
||||||
{
|
}{
|
||||||
name: "tomorrow dutch",
|
{
|
||||||
input: "morgen",
|
name: "english dayname lowercase",
|
||||||
exp: task.NewDate(2021, 1, 31),
|
input: "monday",
|
||||||
},
|
exp: task.NewDate(2021, 2, 1),
|
||||||
{
|
},
|
||||||
name: "day after tomorrow english",
|
{
|
||||||
input: "day after tomorrow",
|
name: "english dayname capitalized",
|
||||||
exp: task.NewDate(2021, 2, 1),
|
input: "Monday",
|
||||||
},
|
exp: task.NewDate(2021, 2, 1),
|
||||||
{
|
},
|
||||||
name: "day after tomorrow dutch",
|
{
|
||||||
input: "overmorgen",
|
name: "dutch dayname lowercase",
|
||||||
exp: task.NewDate(2021, 2, 1),
|
input: "maandag",
|
||||||
},
|
exp: task.NewDate(2021, 2, 1),
|
||||||
{
|
},
|
||||||
name: "this week english",
|
} {
|
||||||
input: "this week",
|
t.Run(tc.name, func(t *testing.T) {
|
||||||
exp: task.NewDate(2021, 2, 5),
|
test.Equals(t, tc.exp, task.NewDateFromString(tc.input))
|
||||||
},
|
})
|
||||||
{
|
}
|
||||||
name: "this week dutch",
|
})
|
||||||
input: "deze week",
|
|
||||||
exp: task.NewDate(2021, 2, 5),
|
t.Run("relative days", func(t *testing.T) {
|
||||||
},
|
task.Today = task.NewDate(2021, 1, 30)
|
||||||
{
|
for _, tc := range []struct {
|
||||||
name: "next week english",
|
name string
|
||||||
input: "next week",
|
input string
|
||||||
exp: task.NewDate(2021, 2, 12),
|
exp task.Date
|
||||||
},
|
}{
|
||||||
{
|
{
|
||||||
name: "next week dutch",
|
name: "today english",
|
||||||
input: "volgende week",
|
input: "today",
|
||||||
exp: task.NewDate(2021, 2, 12),
|
exp: task.NewDate(2021, 1, 30),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "this sprint english",
|
name: "today dutch",
|
||||||
input: "this sprint",
|
input: "vandaag",
|
||||||
exp: task.NewDate(2021, 2, 11),
|
exp: task.NewDate(2021, 1, 30),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "this sprint dutch",
|
name: "tomorrow english",
|
||||||
input: "deze sprint",
|
input: "tomorrow",
|
||||||
exp: task.NewDate(2021, 2, 11),
|
exp: task.NewDate(2021, 1, 31),
|
||||||
},
|
},
|
||||||
} {
|
{
|
||||||
t.Run(tc.name, func(t *testing.T) {
|
name: "tomorrow dutch",
|
||||||
test.Equals(t, tc.exp, task.NewDateFromString(tc.input))
|
input: "morgen",
|
||||||
})
|
exp: task.NewDate(2021, 1, 31),
|
||||||
}
|
},
|
||||||
|
{
|
||||||
|
name: "day after tomorrow english",
|
||||||
|
input: "day after tomorrow",
|
||||||
|
exp: task.NewDate(2021, 2, 1),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
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),
|
||||||
|
},
|
||||||
|
} {
|
||||||
|
t.Run(tc.name, func(t *testing.T) {
|
||||||
|
test.Equals(t, tc.exp, task.NewDateFromString(tc.input))
|
||||||
|
})
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
t.Run("sprint", func(t *testing.T) {
|
||||||
|
for _, tc := range []struct {
|
||||||
|
name string
|
||||||
|
today task.Date
|
||||||
|
input string
|
||||||
|
exp task.Date
|
||||||
|
}{
|
||||||
|
{
|
||||||
|
name: "this sprint english",
|
||||||
|
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",
|
||||||
|
exp: task.NewDate(2021, 2, 11),
|
||||||
|
},
|
||||||
|
} {
|
||||||
|
t.Run(tc.name, func(t *testing.T) {
|
||||||
|
task.Today = tc.today
|
||||||
|
test.Equals(t, tc.exp, task.NewDateFromString(tc.input))
|
||||||
|
})
|
||||||
|
}
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestDateString(t *testing.T) {
|
func TestDateString(t *testing.T) {
|
||||||
|
|
Loading…
Reference in New Issue