From 1b02f78eee5b3ae7f1416d0f13a92d1fbca48ec2 Mon Sep 17 00:00:00 2001 From: kolaente Date: Tue, 7 Oct 2025 10:55:13 +0200 Subject: [PATCH] fix(filter): check date boundary after timezone conversion Resolves https://github.com/go-vikunja/vikunja/issues/1605 --- pkg/models/task_collection_filter.go | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/pkg/models/task_collection_filter.go b/pkg/models/task_collection_filter.go index 6d00f38df..8237b9281 100644 --- a/pkg/models/task_collection_filter.go +++ b/pkg/models/task_collection_filter.go @@ -89,9 +89,14 @@ func parseTimeFromUserInput(timeString string, loc *time.Location) (value time.T return value, err } value = time.Date(year, time.Month(month), day, 0, 0, 0, 0, loc) - return value.In(config.GetTimeZone()), nil } - return value.In(config.GetTimeZone()), err + value = value.In(config.GetTimeZone()) + // Mysql/Mariadb does not support date values where the year < 1. To make this edge-case work, + // we're setting the year to 1 in that case. This must be done after timezone conversion. + if db.GetDialect() == builder.MYSQL && value.Year() < 1 { + value = value.AddDate(1-value.Year(), 0, 0) + } + return value, err } func parseFilterFromExpression(f fexpr.ExprGroup, loc *time.Location) (filter *taskFilter, err error) { @@ -292,17 +297,17 @@ func getValueForField(field reflect.StructField, rawValue string, loc *time.Loca t, err = datemath.Parse(rawValue) if err == nil { tt = t.Time(datemath.WithLocation(loc)).In(config.GetTimeZone()) + // Mysql/Mariadb does not support date values where the year < 1. To make this edge-case work, + // we're setting the year to 1 in that case. This must be done after timezone conversion. + if db.GetDialect() == builder.MYSQL && tt.Year() < 1 { + tt = tt.AddDate(1-tt.Year(), 0, 0) + } } else { tt, err = parseTimeFromUserInput(rawValue, loc) } if err != nil { return } - // Mysql/Mariadb does not support date values where the year < 1. To make this edge-case work, - // we're setting the year to 1 in that case. - if db.GetDialect() == builder.MYSQL && tt.Year() < 1 { - tt = tt.AddDate(1-tt.Year(), 0, 0) - } value = tt } case reflect.Slice: