github.com/gogf/gf/v2@v2.7.4/os/gtime/gtime_z_unit_feature_sql_test.go (about)

     1  package gtime_test
     2  
     3  import (
     4  	"testing"
     5  
     6  	"github.com/gogf/gf/v2/os/gtime"
     7  	"github.com/gogf/gf/v2/test/gtest"
     8  )
     9  
    10  func TestTime_Scan(t1 *testing.T) {
    11  	gtest.C(t1, func(t *gtest.T) {
    12  		tt := gtime.Time{}
    13  		// test string
    14  		s := gtime.Now().String()
    15  		t.Assert(tt.Scan(s), nil)
    16  		t.Assert(tt.String(), s)
    17  		// test nano
    18  		n := gtime.TimestampNano()
    19  		t.Assert(tt.Scan(n), nil)
    20  		t.Assert(tt.TimestampNano(), n)
    21  		// test nil
    22  		none := (*gtime.Time)(nil)
    23  		t.Assert(none.Scan(nil), nil)
    24  		t.Assert(none, nil)
    25  	})
    26  
    27  }
    28  
    29  func TestTime_Value(t1 *testing.T) {
    30  	gtest.C(t1, func(t *gtest.T) {
    31  		tt := gtime.Now()
    32  		s, err := tt.Value()
    33  		t.AssertNil(err)
    34  		t.Assert(s, tt.Time)
    35  		// test nil
    36  		none := (*gtime.Time)(nil)
    37  		s, err = none.Value()
    38  		t.AssertNil(err)
    39  		t.Assert(s, nil)
    40  
    41  	})
    42  }