github.com/shuguocloud/go-zero@v1.3.0/core/timex/relativetime_test.go (about)

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