Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions scw/convert.go
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,11 @@ func TimeDurationPtr(v time.Duration) *time.Duration {
return &v
}

// TimePtr returns a pointer to the Time value passed in.
func TimePtr(v time.Time) *time.Time {
return &v
}

// SizePtr returns a pointer to the Size value passed in.
func SizePtr(v Size) *Size {
return &v
Expand Down
9 changes: 9 additions & 0 deletions scw/convert_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ var (
testFloat32 float32 = 46
testFloat64 float64 = 47
testDuration time.Duration = 48
testTime time.Time = time.Date(2009, 11, 10, 23, 0, 0, 0, time.UTC)
testSize Size = 3 * GB
)

Expand Down Expand Up @@ -169,6 +170,14 @@ func TestDurationPtr(t *testing.T) {
testhelpers.Equals(t, testDuration, *pointer)
}

func TestTimePtr(t *testing.T) {
pointer := TimePtr(testTime)

// value to pointer value
testhelpers.Assert(t, pointer != nil, "Pointer should have value")
testhelpers.Equals(t, testTime, *pointer)
}

func TestSizePtr(t *testing.T) {
pointer := SizePtr(testSize)

Expand Down