ficsit-cli-flake/ficsit/utils/json.go

27 lines
415 B
Go
Raw Normal View History

2021-12-04 03:42:31 +00:00
package utils
import (
"bytes"
"fmt"
2021-12-04 03:42:31 +00:00
"time"
)
//goland:noinspection GoUnusedExportedFunction
func UnmarshalDateTime(b []byte, v *time.Time) error {
trimmed := bytes.Trim(b, "\"")
if len(trimmed) == 0 {
*v = time.Unix(0, 0)
return nil
}
parsed, err := time.Parse(time.RFC3339, string(trimmed))
if err != nil {
return fmt.Errorf("failed to parse date time: %w", err)
2021-12-04 03:42:31 +00:00
}
*v = parsed
return nil
}