All checks were successful
ci/woodpecker/push/build-image Pipeline was successful
31 lines
643 B
Go
31 lines
643 B
Go
package timeparse
|
|
|
|
import (
|
|
"fmt"
|
|
"strings"
|
|
"time"
|
|
|
|
"gitea.maximumdirect.net/ejr/weatherapi/internal/platform/constants"
|
|
)
|
|
|
|
func ParseTimestamp(raw string) (time.Time, error) {
|
|
raw = strings.TrimSpace(raw)
|
|
if raw == "" {
|
|
return time.Time{}, fmt.Errorf("timestamp is required")
|
|
}
|
|
|
|
var lastErr error
|
|
for _, layout := range constants.SupportedTimestampLayouts {
|
|
ts, err := time.Parse(layout, raw)
|
|
if err == nil {
|
|
return ts, nil
|
|
}
|
|
lastErr = err
|
|
}
|
|
|
|
if lastErr == nil {
|
|
lastErr = fmt.Errorf("invalid timestamp")
|
|
}
|
|
return time.Time{}, fmt.Errorf("timestamp must be RFC3339 (example: 2026-03-17T12:30:00Z): %w", lastErr)
|
|
}
|