Skip to content

Commit

Permalink
Update parseDuration, skip empty values
Browse files Browse the repository at this point in the history
  • Loading branch information
roeldev committed Jan 26, 2023
1 parent 6426d35 commit 4040919
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
4 changes: 4 additions & 0 deletions parse.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@ func unmarshalText(val Value, dest interface{}) error {
}

func parseDuration(val Value, dest interface{}) error {
if val.Empty() {
return nil
}

d, err := time.ParseDuration(val.String())
if err != nil {
return err
Expand Down
4 changes: 1 addition & 3 deletions value.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@ const (
ValidationError errors.Kind = "validation error"
)

var Separator = ","

func errKind(err error) errors.Kind {
if ne, ok := err.(*strconv.NumError); ok {
if ne.Err == strconv.ErrRange {
Expand All @@ -34,7 +32,7 @@ func errKind(err error) errors.Kind {
type Value string

// Empty indicates if Value is an empty string.
func (v Value) Empty() bool { return v.String() == "" }
func (v Value) Empty() bool { return string(v) == "" }

func (v Value) GoString() string { return `parseval.Value("` + v.String() + `")` }

Expand Down

0 comments on commit 4040919

Please sign in to comment.