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":
|
||||
fallthrough
|
||||
case "deze sprint":
|
||||
aSprintStart := NewDate(2021, 1, 29)
|
||||
daysToAdd := findDaysToWeekday(Today.Weekday(), time.Thursday)
|
||||
diff := aSprintStart.DaysBetween(Today.AddDays(daysToAdd))
|
||||
if diff%14 != 0 {
|
||||
daysToAdd += 7
|
||||
tDate := NewDate(2021, 1, 28) // a sprint end
|
||||
for {
|
||||
if tDate.After(Today) {
|
||||
return tDate
|
||||
}
|
||||
tDate = tDate.AddDays(14)
|
||||
}
|
||||
|
||||
return Today.AddDays(daysToAdd)
|
||||
}
|
||||
|
||||
t, err := time.Parse("2006-01-02", fmt.Sprintf("%.10s", date))
|
||||
|
|
|
@ -75,6 +75,8 @@ func TestWeekdaysUnique(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestNewDateFromString(t *testing.T) {
|
||||
|
||||
t.Run("no date", func(t *testing.T) {
|
||||
task.Today = task.NewDate(2021, 1, 30)
|
||||
for _, tc := range []struct {
|
||||
name string
|
||||
|
@ -90,6 +92,20 @@ func TestNewDateFromString(t *testing.T) {
|
|||
input: "no date",
|
||||
exp: task.Date{},
|
||||
},
|
||||
} {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
test.Equals(t, tc.exp, task.NewDateFromString(tc.input))
|
||||
})
|
||||
}
|
||||
})
|
||||
|
||||
t.Run("digits", func(t *testing.T) {
|
||||
task.Today = task.NewDate(2021, 1, 30)
|
||||
for _, tc := range []struct {
|
||||
name string
|
||||
input string
|
||||
exp task.Date
|
||||
}{
|
||||
{
|
||||
name: "normal",
|
||||
input: "2021-01-30 (saturday)",
|
||||
|
@ -100,6 +116,21 @@ func TestNewDateFromString(t *testing.T) {
|
|||
input: "2021-01-30",
|
||||
exp: task.NewDate(2021, 1, 30),
|
||||
},
|
||||
} {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
test.Equals(t, tc.exp, task.NewDateFromString(tc.input))
|
||||
|
||||
})
|
||||
}
|
||||
})
|
||||
|
||||
t.Run("day name", func(t *testing.T) {
|
||||
task.Today = task.NewDate(2021, 1, 30)
|
||||
for _, tc := range []struct {
|
||||
name string
|
||||
input string
|
||||
exp task.Date
|
||||
}{
|
||||
{
|
||||
name: "english dayname lowercase",
|
||||
input: "monday",
|
||||
|
@ -115,6 +146,20 @@ func TestNewDateFromString(t *testing.T) {
|
|||
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))
|
||||
})
|
||||
}
|
||||
})
|
||||
|
||||
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: "today english",
|
||||
input: "today",
|
||||
|
@ -165,21 +210,45 @@ func TestNewDateFromString(t *testing.T) {
|
|||
input: "volgende week",
|
||||
exp: task.NewDate(2021, 2, 12),
|
||||
},
|
||||
{
|
||||
name: "this sprint english",
|
||||
input: "this sprint",
|
||||
exp: task.NewDate(2021, 2, 11),
|
||||
},
|
||||
{
|
||||
name: "this sprint dutch",
|
||||
input: "deze sprint",
|
||||
exp: task.NewDate(2021, 2, 11),
|
||||
},
|
||||
} {
|
||||
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) {
|
||||
|
|
Loading…
Reference in New Issue