From e9ab07e4d3abf963d9501656617db1e249ff1d22 Mon Sep 17 00:00:00 2001 From: Deluan Date: Tue, 8 Mar 2016 19:29:56 -0500 Subject: [PATCH] Tests for time conversion utils --- utils/time.go | 3 ++- utils/time_test.go | 17 +++++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) create mode 100644 utils/time_test.go diff --git a/utils/time.go b/utils/time.go index cc99ab49..0d070a05 100644 --- a/utils/time.go +++ b/utils/time.go @@ -3,7 +3,8 @@ package utils import "time" func ToTime(millis int64) time.Time { - return time.Unix(0, millis*int64(time.Millisecond)) + t := time.Unix(0, millis*int64(time.Millisecond)) + return t.Local() } func ToMillis(t time.Time) int64 { diff --git a/utils/time_test.go b/utils/time_test.go new file mode 100644 index 00000000..91e05365 --- /dev/null +++ b/utils/time_test.go @@ -0,0 +1,17 @@ +package utils + +import ( + "testing" + "time" + + . "github.com/smartystreets/goconvey/convey" +) + +func TestTimeConversion(t *testing.T) { + + Convey("Conversion should work both ways", t, func() { + now := time.Date(2002, 8, 9, 12, 11, 13, 1000000, time.Local) + milli := ToMillis(now) + So(ToTime(milli).String(), ShouldEqual, now.String()) + }) +}