Skip to content

🎧 Your Personal Streaming Service

Tests for time conversion utils

Deluane9ab07e4d3ab
diff --git a/utils/time.go b/utils/time.go
index cc99ab495..0d070a052 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 000000000..91e053658
--- /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())
+ })
+}