fix(filters): try parsing invalid dates like 2022-11-1
continuous-integration/drone/push Build is passing Details

This commit is contained in:
kolaente 2022-11-11 11:05:21 +01:00
parent 986129a784
commit 33e27c66a0
Signed by: konrad
GPG Key ID: F40E70337AB24C9B
1 changed files with 21 additions and 0 deletions

View File

@ -64,6 +64,27 @@ func parseTimeFromUserInput(timeString string) (value time.Time, err error) {
if err != nil {
value, err = time.Parse(safariDate, timeString)
}
if err != nil {
// Here we assume a date like 2022-11-1 and try to parse it manually
parts := strings.Split(timeString, "-")
if len(parts) < 3 {
return
}
year, err := strconv.Atoi(parts[0])
if err != nil {
return value, err
}
month, err := strconv.Atoi(parts[1])
if err != nil {
return value, err
}
day, err := strconv.Atoi(parts[2])
if err != nil {
return value, err
}
value = time.Date(year, time.Month(month), day, 0, 0, 0, 0, time.UTC)
return value.In(config.GetTimeZone()), nil
}
return value.In(config.GetTimeZone()), err
}