From 83160ddac2d80c40d5a9e40359fc32f13f37678b Mon Sep 17 00:00:00 2001 From: David Ribeiro Date: Tue, 18 Aug 2020 17:14:45 +0200 Subject: [PATCH] feat(scw): add function TimePtr() --- scw/convert.go | 5 +++++ scw/convert_test.go | 9 +++++++++ 2 files changed, 14 insertions(+) diff --git a/scw/convert.go b/scw/convert.go index ccdb45654..7b671dcf5 100644 --- a/scw/convert.go +++ b/scw/convert.go @@ -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 diff --git a/scw/convert_test.go b/scw/convert_test.go index 59bd945a2..39596393c 100644 --- a/scw/convert_test.go +++ b/scw/convert_test.go @@ -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 ) @@ -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)