add Time helper as well (#536)

This commit is contained in:
Victor Agababov 2019-07-18 20:44:28 -07:00 committed by Knative Prow Robot
parent 83cfa18c15
commit 8fe96d53cc
2 changed files with 13 additions and 0 deletions

View File

@ -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
}

View File

@ -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)