Tests for time conversion utils

This commit is contained in:
Deluan 2016-03-08 19:29:56 -05:00
parent 5be236515d
commit e9ab07e4d3
2 changed files with 19 additions and 1 deletions

View File

@ -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 {

17
utils/time_test.go Normal file
View File

@ -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())
})
}