2021-03-31 14:07:28 +08:00
|
|
|
package gtime_test
|
|
|
|
|
|
|
|
import (
|
2021-11-15 20:49:02 +08:00
|
|
|
"testing"
|
|
|
|
|
2021-10-11 21:41:56 +08:00
|
|
|
"github.com/gogf/gf/v2/os/gtime"
|
|
|
|
"github.com/gogf/gf/v2/test/gtest"
|
2021-03-31 14:07:28 +08:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestTime_Scan(t1 *testing.T) {
|
|
|
|
gtest.C(t1, func(t *gtest.T) {
|
|
|
|
tt := gtime.Time{}
|
2021-11-15 20:49:02 +08:00
|
|
|
// test string
|
2021-03-31 14:07:28 +08:00
|
|
|
s := gtime.Now().String()
|
|
|
|
t.Assert(tt.Scan(s), nil)
|
|
|
|
t.Assert(tt.String(), s)
|
2021-11-15 20:49:02 +08:00
|
|
|
// test nano
|
2021-03-31 14:07:28 +08:00
|
|
|
n := gtime.TimestampNano()
|
|
|
|
t.Assert(tt.Scan(n), nil)
|
|
|
|
t.Assert(tt.TimestampNano(), n)
|
2021-11-15 20:49:02 +08:00
|
|
|
// test nil
|
2021-03-31 14:07:28 +08:00
|
|
|
none := (*gtime.Time)(nil)
|
|
|
|
t.Assert(none.Scan(nil), nil)
|
|
|
|
t.Assert(none, nil)
|
|
|
|
})
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestTime_Value(t1 *testing.T) {
|
|
|
|
gtest.C(t1, func(t *gtest.T) {
|
|
|
|
tt := gtime.Now()
|
|
|
|
s, err := tt.Value()
|
|
|
|
t.Assert(err, nil)
|
|
|
|
t.Assert(s, tt.Time)
|
2021-11-15 20:49:02 +08:00
|
|
|
// test nil
|
2021-03-31 14:07:28 +08:00
|
|
|
none := (*gtime.Time)(nil)
|
|
|
|
s, err = none.Value()
|
|
|
|
t.Assert(err, nil)
|
|
|
|
t.Assert(s, nil)
|
|
|
|
|
|
|
|
})
|
|
|
|
}
|