本文整理匯總了Golang中github.com/guregu/toki.NullTime類的典型用法代碼示例。如果您正苦於以下問題:Golang NullTime類的具體用法?Golang NullTime怎麽用?Golang NullTime使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
在下文中一共展示了NullTime類的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: BenchmarkMarshal
func BenchmarkMarshal(b *testing.B) {
for n := 0; n < b.N; n++ {
t := toki.NullTime{
toki.Time{
Hours: 12,
Minutes: 34,
Seconds: 00,
}, true}
t.MarshalJSON()
}
}
示例2: TestMarshalNullJSON
func TestMarshalNullJSON(t *testing.T) {
for given, expected := range jsonTable {
time := toki.NullTime{}
time.UnmarshalJSON([]byte(given))
data, err := json.Marshal(time)
if err != nil {
t.Errorf("MarshalJSON: error: %s", err)
}
result := string(data)
if result != expected {
t.Errorf("MarshalJSON: %s ≠ %s (%#v)", result, expected, time)
}
}
}
示例3: TestNullScan
func TestNullScan(t *testing.T) {
expected := toki.MustParseNullTime("12:34")
byteTime := toki.NullTime{}
err := byteTime.Scan([]byte("12:34:00"))
if err != nil {
t.Errorf("Scan: error: %v", err)
}
if byteTime != expected {
t.Errorf("Scan: %#v ≠ %#v", byteTime, expected)
}
nullTime := toki.NullTime{}
err = nullTime.Scan(nil)
if err != nil {
t.Errorf("Scan: error: %v", err)
}
if nullTime.Valid {
t.Errorf("Scan: not null, got %s", nullTime.String())
}
emptyTime := toki.NullTime{}
err = emptyTime.Scan("")
if err != nil {
t.Errorf("Scan: error: %v", err)
}
if emptyTime.Valid {
t.Errorf("Scan: not null, got %s", emptyTime.String())
}
emptyByteTime := toki.NullTime{}
err = emptyByteTime.Scan([]byte{})
if err != nil {
t.Errorf("Scan: error: %v", err)
}
if emptyByteTime.Valid {
t.Errorf("Scan: not null, got %s", emptyByteTime.String())
}
}
示例4: BenchmarkMarshalNull
func BenchmarkMarshalNull(b *testing.B) {
for n := 0; n < b.N; n++ {
t := toki.NullTime{toki.Time{}, false}
t.MarshalJSON()
}
}
示例5: BenchmarkEmptyTime
func BenchmarkEmptyTime(b *testing.B) {
for n := 0; n < b.N; n++ {
t := toki.NullTime{}
t.UnmarshalJSON([]byte{'"', '"'})
}
}
示例6: BenchmarkNormalTime
func BenchmarkNormalTime(b *testing.B) {
for n := 0; n < b.N; n++ {
t := toki.NullTime{}
t.UnmarshalJSON([]byte{'1', '2', ':', '3', '0'})
}
}
示例7: BenchmarkNull
func BenchmarkNull(b *testing.B) {
for n := 0; n < b.N; n++ {
t := toki.NullTime{}
t.UnmarshalJSON([]byte{'n', 'u', 'l', 'l'})
}
}