relativetime_test.go 433 B

12345678910111213141516171819202122232425
  1. package timex
  2. import (
  3. "testing"
  4. "time"
  5. "github.com/stretchr/testify/assert"
  6. )
  7. func TestRelativeTime(t *testing.T) {
  8. time.Sleep(time.Millisecond)
  9. now := Now()
  10. assert.True(t, now > 0)
  11. time.Sleep(time.Millisecond)
  12. assert.True(t, Since(now) > 0)
  13. }
  14. func TestRelativeTime_Time(t *testing.T) {
  15. diff := time.Until(Time())
  16. if diff > 0 {
  17. assert.True(t, diff < time.Second)
  18. } else {
  19. assert.True(t, -diff < time.Second)
  20. }
  21. }