35 lines
727 B
Go
35 lines
727 B
Go
package utils
|
|
|
|
import (
|
|
"errors"
|
|
"strings"
|
|
"time"
|
|
)
|
|
|
|
const issuedAtLayout = "02/01/2006, 15:04:05"
|
|
|
|
var knownDateFormats = []string{
|
|
"02.01.2006", // 21.01.2026
|
|
"02.01.06", // 21.01.2026
|
|
"02-01-2006", // 21-01-2026
|
|
"02/01/2006", // 21/01/2026
|
|
"2006/01/02", // 2026/01/21
|
|
"2006-01-02", // 2026-01-21
|
|
"2006.01.02", // 2026.01.21
|
|
}
|
|
|
|
func NormalizeDateToISO(input string) (string, error) {
|
|
input = strings.TrimSpace(input)
|
|
for _, layout := range knownDateFormats {
|
|
if t, err := time.Parse(layout, input); err == nil {
|
|
return t.Format("2006-01-02"), nil
|
|
}
|
|
}
|
|
|
|
return "", errors.New("unsupported date format")
|
|
}
|
|
|
|
func ParseIssuedAt(value string) (time.Time, error) {
|
|
return time.Parse(issuedAtLayout, value)
|
|
}
|