From 3dff430dc8205ef4668b034459c38d4400eb1226 Mon Sep 17 00:00:00 2001 From: Jeff Carr Date: Sat, 25 Oct 2025 08:26:25 -0500 Subject: handle proto duration values --- duration.go | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) 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() { -- cgit v1.2.3