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

28 lines
431 B
Go
Raw Normal View History

2021-12-04 03:42:31 +00:00
package utils
import (
"bytes"
"time"
2021-12-04 03:48:15 +00:00
"github.com/pkg/errors"
2021-12-04 03:42:31 +00:00
)
//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 {
2021-12-04 03:48:15 +00:00
return errors.Wrap(err, "failed to parse date time")
2021-12-04 03:42:31 +00:00
}
*v = parsed
return nil
}