gitee.com/gricks/utils@v1.0.8/time_test.go (about)

     1  package utils
     2  
     3  import (
     4  	"testing"
     5  	"time"
     6  
     7  	. "github.com/smartystreets/goconvey/convey"
     8  )
     9  
    10  func TestTime(t *testing.T) {
    11  	Convey("ParseTime", t, func() {
    12  		n := time.Now().Truncate(time.Second)
    13  		s := FormatTime(n)
    14  		p, err := ParseTime(s)
    15  		So(err, ShouldBeNil)
    16  		So(p.Unix(), ShouldEqual, n.Unix())
    17  	})
    18  
    19  	Convey("ParseDate", t, func() {
    20  		n := time.Now().Truncate(time.Hour)
    21  		n = n.Add(-time.Hour * time.Duration(n.Hour()))
    22  		s := FormatDate(n)
    23  		p, err := ParseDate(s)
    24  		So(err, ShouldBeNil)
    25  		So(p.Unix(), ShouldEqual, n.Unix())
    26  	})
    27  }