go-zero/core/timex/relativetime_test.go

26 lines
433 B
Go
Raw Normal View History

2020-07-26 17:09:05 +08:00
package timex
import (
"testing"
"time"
"github.com/stretchr/testify/assert"
)
func TestRelativeTime(t *testing.T) {
time.Sleep(time.Millisecond)
now := Now()
assert.True(t, now > 0)
time.Sleep(time.Millisecond)
assert.True(t, Since(now) > 0)
}
func TestRelativeTime_Time(t *testing.T) {
2020-10-16 10:50:43 +08:00
diff := time.Until(Time())
2020-07-26 17:09:05 +08:00
if diff > 0 {
assert.True(t, diff < time.Second)
} else {
assert.True(t, -diff < time.Second)
}
}