Skip to content

Commit

Permalink
Add helper for time.Time (#14293)
Browse files Browse the repository at this point in the history
  • Loading branch information
jhendrixMSFT authored Feb 10, 2021
1 parent dc4dfc8 commit 2322783
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
7 changes: 7 additions & 0 deletions sdk/to/to.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@

package to

import "time"

// BoolPtr returns a pointer to the provided bool.
func BoolPtr(b bool) *bool {
return &b
Expand Down Expand Up @@ -34,3 +36,8 @@ func Int64Ptr(i int64) *int64 {
func StringPtr(s string) *string {
return &s
}

// TimePtr returns a pointer to the provided time.Time.
func TimePtr(t time.Time) *time.Time {
return &t
}
16 changes: 15 additions & 1 deletion sdk/to/to_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@

package to

import "testing"
import (
"testing"
"time"
)

func TestBoolPtr(t *testing.T) {
b := true
Expand Down Expand Up @@ -72,3 +75,14 @@ func TestStringPtr(t *testing.T) {
t.Fatalf("got %v, want %v", *ps, s)
}
}

func TestTimePtr(t *testing.T) {
tt := time.Now()
pt := TimePtr(tt)
if pt == nil {
t.Fatal("unexpected nil conversion")
}
if *pt != tt {
t.Fatalf("got %v, want %v", *pt, tt)
}
}

0 comments on commit 2322783

Please sign in to comment.