mirror of https://github.com/knative/pkg.git
add Time helper as well (#536)
This commit is contained in:
parent
83cfa18c15
commit
8fe96d53cc
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in New Issue