diff --git a/ptr/ptr.go b/ptr/ptr.go index 7b7d581f9..a3bfef85c 100644 --- a/ptr/ptr.go +++ b/ptr/ptr.go @@ -47,3 +47,9 @@ func String(s string) *string { func Duration(t time.Duration) *time.Duration { return &t } + +// Time is a helper for turning a const time.Time into a pointer for use in +// API types that want *time.Duration. +func Time(t time.Time) *time.Time { + return &t +} diff --git a/ptr/ptr_test.go b/ptr/ptr_test.go index e8c14c18a..4ae102aa9 100644 --- a/ptr/ptr_test.go +++ b/ptr/ptr_test.go @@ -53,6 +53,13 @@ func TestString(t *testing.T) { } } +func TestTime(t *testing.T) { + want := time.Now().Add(time.Minute) + if got, want := *Time(want), want; got != want { + t.Errorf("got = %v, want: %v", got, want) + } +} + func TestDuration(t *testing.T) { want := 42 * time.Second gotPtr := Duration(want)