Skip to content

Commit

Permalink
✨ feat: add ToValue function to convert duration string to reflect.Value
Browse files Browse the repository at this point in the history
  • Loading branch information
watzon committed Nov 18, 2024
1 parent e5d81f0 commit 96d41ad
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion convert.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package hdur

import "time"
import (
"reflect"
"time"
)

// ToStandard converts our Duration to a time.Duration
// Note: This is an approximation as time.Duration doesn't handle months and years
Expand All @@ -9,3 +12,12 @@ func (d Duration) ToStandard() time.Duration {
t := time.Now()
return d.Add(t).Sub(t)
}

// ToValue converts a duration string to a reflect.Value, perfect for use
// with Fiber
func ToValue(value string) reflect.Value {
if v, err := ParseDuration(value); err == nil {
return reflect.ValueOf(v)
}
return reflect.Value{}
}

0 comments on commit 96d41ad

Please sign in to comment.