1
0
Fork 0
mirror of https://github.com/gocsaf/csaf.git synced 2025-12-22 05:40:11 +01:00

go-flag needs its own Unmarshaler.

This commit is contained in:
Sascha L. Teichmann 2023-07-26 12:06:16 +02:00
parent 1d892ff681
commit 125028773f

View file

@ -47,8 +47,13 @@ func guessDate(s string) (time.Time, bool) {
// UnmarshalText implements [encoding/text.TextUnmarshaler].
func (tr *TimeRange) UnmarshalText(text []byte) error {
return tr.UnmarshalFlag(string(text))
}
// UnmarshalFlag implements [go-flags/Unmarshaler].
func (tr *TimeRange) UnmarshalFlag(s string) error {
s = strings.TrimSpace(s)
s := strings.TrimSpace(string(text))
// Handle relative case first.
if duration, err := time.ParseDuration(s); err == nil {
now := time.Now()