diff options
| author | Jeff Carr <[email protected]> | 2025-10-25 08:26:25 -0500 | 
|---|---|---|
| committer | Jeff Carr <[email protected]> | 2025-10-25 08:26:25 -0500 | 
| commit | 3dff430dc8205ef4668b034459c38d4400eb1226 (patch) | |
| tree | 937dd49561d9ea6557a1c3347923c0ad3e6055f0 | |
| parent | 395aa701c03a4bd6d01436ce17cee489ee6a98e3 (diff) | |
handle proto duration values
| -rw-r--r-- | duration.go | 12 | 
1 files changed, 11 insertions, 1 deletions
diff --git a/duration.go b/duration.go index 96722c9..ea25d47 100644 --- a/duration.go +++ b/duration.go @@ -4,6 +4,7 @@ import (  	"errors"  	"time" +	"google.golang.org/protobuf/types/known/durationpb"  	"google.golang.org/protobuf/types/known/timestamppb"  ) @@ -31,6 +32,12 @@ func DurationCheck(maybeTime any) (time.Duration, error) {  	case time.Time:  		// If the type is time.Time, 'v' is now a time.Time variable.  		d = time.Since(v) +	case time.Duration: +		// If the type is time.Time, 'v' is now a time.Time variable. +		d = v +	case *time.Duration: +		// If the type is time.Time, 'v' is now a time.Time variable. +		d = *v  	case string:  		// The type is string, so 'v' is a string variable.  		// t, err = doTimeString(v) @@ -44,7 +51,10 @@ func DurationCheck(maybeTime any) (time.Duration, error) {  		} else {  			err = errors.New("pb time invalid")  		} - +	case *durationpb.Duration: +		d = v.AsDuration() +	case durationpb.Duration: +		d = v.AsDuration()  	case timestamppb.Timestamp:  		// Handle the less common case of a value type instead of a pointer.  		if v.IsValid() {  | 
