stash/pkg/utils/date.go
WithoutPants f3c8e7ac9c
Convert career length fields to dates (#6682)
* Convert career start/end to date
* Update UI to accept dates for career length fields
* Fix date filtering
---------
Co-authored-by: Gykes <24581046+Gykes@users.noreply.github.com>
2026-03-17 15:48:30 +11:00

27 lines
501 B
Go

package utils
import (
"fmt"
"time"
)
func ParseDateStringAsTime(dateString string) (time.Time, error) {
// https://stackoverflow.com/a/20234207 WTF?
t, e := time.Parse(time.RFC3339, dateString)
if e == nil {
return t, nil
}
t, e = time.Parse("2006-01-02", dateString)
if e == nil {
return t, nil
}
t, e = time.Parse("2006-01-02 15:04:05", dateString)
if e == nil {
return t, nil
}
return time.Time{}, fmt.Errorf("ParseDateStringAsTime failed: dateString <%s>", dateString)
}