diff --git a/Godeps/Godeps.json b/Godeps/Godeps.json index f24ceaf1..c80b4d32 100644 --- a/Godeps/Godeps.json +++ b/Godeps/Godeps.json @@ -9,19 +9,19 @@ }, { "ImportPath": "github.com/bitrise-io/go-utils/cmdex", - "Rev": "7cc4f2865477d667b2b7bd42569a1a9c7f67afc8" + "Rev": "0584aca98a0963494a02cdaa2c511302472ac615" }, { "ImportPath": "github.com/bitrise-io/go-utils/fileutil", - "Rev": "7cc4f2865477d667b2b7bd42569a1a9c7f67afc8" + "Rev": "0584aca98a0963494a02cdaa2c511302472ac615" }, { "ImportPath": "github.com/bitrise-io/go-utils/pathutil", - "Rev": "7cc4f2865477d667b2b7bd42569a1a9c7f67afc8" + "Rev": "0584aca98a0963494a02cdaa2c511302472ac615" }, { "ImportPath": "github.com/bitrise-io/go-utils/pointers", - "Rev": "7cc4f2865477d667b2b7bd42569a1a9c7f67afc8" + "Rev": "0584aca98a0963494a02cdaa2c511302472ac615" }, { "ImportPath": "github.com/bitrise-io/goinp/goinp", diff --git a/Godeps/_workspace/src/github.com/bitrise-io/go-utils/pointers/pointers.go b/Godeps/_workspace/src/github.com/bitrise-io/go-utils/pointers/pointers.go index 11146075..901d8d56 100644 --- a/Godeps/_workspace/src/github.com/bitrise-io/go-utils/pointers/pointers.go +++ b/Godeps/_workspace/src/github.com/bitrise-io/go-utils/pointers/pointers.go @@ -1,5 +1,7 @@ package pointers +import "time" + // NewBoolPtr ... func NewBoolPtr(val bool) *bool { ptrValue := new(bool) @@ -13,3 +15,10 @@ func NewStringPtr(val string) *string { *ptrValue = val return ptrValue } + +// NewTimePtr ... +func NewTimePtr(val time.Time) *time.Time { + ptrValue := new(time.Time) + *ptrValue = val + return ptrValue +} diff --git a/Godeps/_workspace/src/github.com/bitrise-io/go-utils/pointers/pointers_test.go b/Godeps/_workspace/src/github.com/bitrise-io/go-utils/pointers/pointers_test.go index ba6ab3e8..c45a5836 100644 --- a/Godeps/_workspace/src/github.com/bitrise-io/go-utils/pointers/pointers_test.go +++ b/Godeps/_workspace/src/github.com/bitrise-io/go-utils/pointers/pointers_test.go @@ -1,6 +1,9 @@ package pointers -import "testing" +import ( + "testing" + "time" +) func TestNewBoolPtr(t *testing.T) { t.Log("Create false ptr") @@ -50,3 +53,25 @@ func TestNewStringPtr(t *testing.T) { t.Fatal("The original var was affected!!") } } + +func TestNewTimePtr(t *testing.T) { + t.Log("Create a time") + if (*NewTimePtr(time.Date(2009, time.January, 1, 0, 0, 0, 0, time.UTC))).Equal(time.Date(2009, time.January, 1, 0, 0, 0, 0, time.UTC)) == false { + t.Fatal("Invalid pointer") + } + + t.Log("Try to change the original value - should not be affected!") + myTime := time.Date(2012, time.January, 1, 0, 0, 0, 0, time.UTC) + myTimePtr := NewTimePtr(myTime) + if (*myTimePtr).Equal(time.Date(2012, time.January, 1, 0, 0, 0, 0, time.UTC)) == false { + t.Fatal("Invalid pointer - original value") + } + *myTimePtr = time.Date(2015, time.January, 1, 0, 0, 0, 0, time.UTC) + if *myTimePtr != time.Date(2015, time.January, 1, 0, 0, 0, 0, time.UTC) { + t.Fatal("Invalid pointer - changed value") + } + // the original var should remain intact! + if myTime.Equal(time.Date(2012, time.January, 1, 0, 0, 0, 0, time.UTC)) == false { + t.Fatal("The original var was affected!!") + } +}