-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjson_time_test.go
54 lines (45 loc) · 1.01 KB
/
json_time_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
package jsontime
import (
"encoding/json"
"log"
"testing"
"time"
)
func TestTime(t *testing.T) {
type Person struct {
Id int64 `json:"id"`
Name string `json:"name"`
Birthday Time `json:"birthday"`
}
// NullToEmptyStr = true
now := Time(time.Now())
t.Log(now)
src := `{"id":5,"name":"xiaoming","birthday":null}`
p := new(Person)
err := json.Unmarshal([]byte(src), p)
if err != nil {
t.Fatal(err)
}
t.Log(p)
t.Log(time.Time(p.Birthday))
js, _ := json.Marshal(p)
t.Log(string(js))
p2 := Person{
Id: 1,
Name: "fefe",
}
b, _ := json.Marshal(p2)
log.Println("str: ", string(b))
}
/**
% go test -v
=== RUN TestTime
json_time_test.go:20: 2021-05-01 21:45:01
json_time_test.go:28: &{5 xiaoming 0001-01-01 00:00:00}
json_time_test.go:29: 0001-01-01 00:00:00 +0000 UTC
json_time_test.go:31: {"id":5,"name":"xiaoming","birthday":null}
2021/05/01 21:45:01 str: {"id":1,"name":"fefe","birthday":null}
--- PASS: TestTime (0.00s)
PASS
ok github.com/go-god/jsontime 0.006s
*/