ficsit-cli-flake/ficsit/utils/json.go
Vilsol 25f544b8fe
refactor: zerolog -> slog, errors.Wrap -> fmt.Error (#49)
* refactor: zerolog -> slog, errors.Wrap -> fmt.Error

* chore: lint

* fix: correctly handle errors

* fix: use parsed level

* fix: use parsed level, log json to file
2023-12-16 16:19:53 +02:00

26 lines
415 B
Go

package utils
import (
"bytes"
"fmt"
"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)
}
*v = parsed
return nil
}