1 package pgtype_test
2
3 import (
4 "context"
5 "testing"
6 "time"
7
8 "github.com/jackc/pgx/v5/pgtype"
9 "github.com/jackc/pgx/v5/pgxtest"
10 )
11
12 func TestTimeCodec(t *testing.T) {
13 pgxtest.RunValueRoundTripTests(context.Background(), t, defaultConnTestRunner, nil, "time", []pgxtest.ValueRoundTripTest{
14 {
15 pgtype.Time{Microseconds: 0, Valid: true},
16 new(pgtype.Time),
17 isExpectedEq(pgtype.Time{Microseconds: 0, Valid: true}),
18 },
19 {
20 pgtype.Time{Microseconds: 1, Valid: true},
21 new(pgtype.Time),
22 isExpectedEq(pgtype.Time{Microseconds: 1, Valid: true}),
23 },
24 {
25 pgtype.Time{Microseconds: 86399999999, Valid: true},
26 new(pgtype.Time),
27 isExpectedEq(pgtype.Time{Microseconds: 86399999999, Valid: true}),
28 },
29 {
30 pgtype.Time{Microseconds: 86400000000, Valid: true},
31 new(pgtype.Time),
32 isExpectedEq(pgtype.Time{Microseconds: 86400000000, Valid: true}),
33 },
34 {
35 time.Date(2000, 1, 1, 0, 0, 0, 0, time.UTC),
36 new(pgtype.Time),
37 isExpectedEq(pgtype.Time{Microseconds: 0, Valid: true}),
38 },
39 {
40 pgtype.Time{Microseconds: 0, Valid: true},
41 new(time.Time),
42 isExpectedEq(time.Date(2000, 1, 1, 0, 0, 0, 0, time.UTC)),
43 },
44 {pgtype.Time{}, new(pgtype.Time), isExpectedEq(pgtype.Time{})},
45 {nil, new(pgtype.Time), isExpectedEq(pgtype.Time{})},
46 })
47 }
48
View as plain text