mirror of
https://github.com/go-vikunja/vikunja.git
synced 2026-04-24 22:25:15 +00:00
fix(filters): make sure year is always at least 1
Resolves https://vikunja.sentry.io/share/issue/ef81451b0c7b43f1bff2d3a86ba393bb/ Resolves https://github.com/go-vikunja/app/issues/94#issuecomment-2351818484
This commit is contained in:
@@ -276,6 +276,15 @@ func getValueForField(field reflect.StructField, rawValue string, loc *time.Loca
|
||||
} else {
|
||||
value, err = parseTimeFromUserInput(rawValue)
|
||||
}
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
// Mariadb does not support date values where the year is 0. To make this edge-case work,
|
||||
// we're setting the year to 1 in that case.
|
||||
tt := value.(time.Time)
|
||||
if tt.Year() == 0 {
|
||||
value = tt.AddDate(1, 0, 0)
|
||||
}
|
||||
}
|
||||
case reflect.Slice:
|
||||
// If this is a slice of pointers we're dealing with some property which is a relation
|
||||
|
||||
@@ -255,4 +255,12 @@ func TestParseFilter(t *testing.T) {
|
||||
sevenDaysAgo := time.Now().Add(-7 * 24 * time.Hour)
|
||||
assert.Equal(t, sevenDaysAgo.Unix(), result[0].value.(time.Time).Unix())
|
||||
})
|
||||
t.Run("date filter with 0000-01-01", func(t *testing.T) {
|
||||
result, err := getTaskFiltersFromFilterString("due_date > 0000-01-01", "UTC")
|
||||
|
||||
require.NoError(t, err)
|
||||
require.Len(t, result, 1)
|
||||
date := result[0].value.(time.Time)
|
||||
assert.Equal(t, 1, date.Year())
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user