src.dualinventive.com/go/dinet/ditime/time_test.go

47 lines
941 B
Go

package ditime
import (
"strings"
"testing"
"time"
)
func TestNow(t *testing.T) {
now := Now()
t.Log(now)
_ = now
}
func TestToTime(t *testing.T) {
tm := ToTime(0)
if tm.Format(time.StampNano) != "Jan 1 01:00:00.000000000" {
t.Error("Unexpected time format at 0 ms")
}
tm = ToTime(1123)
if tm.Format(time.StampNano) != "Jan 1 01:00:01.123000000" {
t.Error("Unexpected time format at 1123 ms")
}
tm = ToTime(1479762835294)
if tm.Format(time.StampNano) != "Nov 21 22:13:55.294000000" {
t.Error("Unexpected time format at 1479762835294 ms")
}
}
func TestString(t *testing.T) {
tm := Time(1123)
if str := tm.String(); !strings.Contains(str, "1970-01-01 01:00:01.123") {
t.Error("Unexpected time format at 1123 ms:", str)
}
}
func TestFormat(t *testing.T) {
tm := Time(1001)
if str := tm.Format(time.StampNano); str != "Jan 1 01:00:01.001000000" {
t.Error("Unexpected time format at 1001 ms:", str)
}
}