@@ -44,7 +44,8 @@ func TestTimeFormat_Encode(t *testing.T) {
44
44
func TestTimeFormat_Decode (t * testing.T ) {
45
45
t .Parallel ()
46
46
47
- zone := time .FixedZone ("" , - 4 * 3600 )
47
+ const offset = - 4 * 3600
48
+ zone := time .FixedZone ("" , offset )
48
49
reference := time .Date (2013 , 10 , 7 , 4 , 23 , 19 , 120_000_000 , zone )
49
50
refnodate := time .Date (2000 , 01 , 1 , 4 , 23 , 19 , 120_000_000 , zone )
50
51
@@ -53,63 +54,63 @@ func TestTimeFormat_Decode(t *testing.T) {
53
54
val any
54
55
want time.Time
55
56
wantDelta time.Duration
56
- wantLoc * time. Location
57
+ wantOff int
57
58
wantErr bool
58
59
}{
59
- {sqlite3 .TimeFormatJulianDay , "2456572.849526851851852" , reference , 0 , time . UTC , false },
60
- {sqlite3 .TimeFormatJulianDay , 2456572.849526851851852 , reference , time .Millisecond , time . UTC , false },
61
- {sqlite3 .TimeFormatJulianDay , int64 (2456572 ), reference , 24 * time .Hour , time . UTC , false },
62
- {sqlite3 .TimeFormatJulianDay , false , time.Time {}, 0 , nil , true },
63
-
64
- {sqlite3 .TimeFormatUnix , "1381134199.120" , reference , time .Microsecond , time . UTC , false },
65
- {sqlite3 .TimeFormatUnix , 1381134199.120 , reference , time .Microsecond , time . UTC , false },
66
- {sqlite3 .TimeFormatUnix , int64 (1381134199 ), reference , time .Second , time . UTC , false },
67
- {sqlite3 .TimeFormatUnix , "abc" , time.Time {}, 0 , nil , true },
68
- {sqlite3 .TimeFormatUnix , false , time.Time {}, 0 , nil , true },
69
-
70
- {sqlite3 .TimeFormatUnixMilli , "1381134199120" , reference , 0 , time . UTC , false },
71
- {sqlite3 .TimeFormatUnixMilli , 1381134199.120e3 , reference , 0 , time . UTC , false },
72
- {sqlite3 .TimeFormatUnixMilli , int64 (1381134199_120 ), reference , 0 , time . UTC , false },
73
- {sqlite3 .TimeFormatUnixMilli , "abc" , time.Time {}, 0 , nil , true },
74
- {sqlite3 .TimeFormatUnixMilli , false , time.Time {}, 0 , nil , true },
75
-
76
- {sqlite3 .TimeFormatUnixMicro , "1381134199120000" , reference , 0 , time . UTC , false },
77
- {sqlite3 .TimeFormatUnixMicro , 1381134199.120e6 , reference , 0 , time . UTC , false },
78
- {sqlite3 .TimeFormatUnixMicro , int64 (1381134199_120000 ), reference , 0 , time . UTC , false },
79
- {sqlite3 .TimeFormatUnixMicro , "abc" , time.Time {}, 0 , nil , true },
80
- {sqlite3 .TimeFormatUnixMicro , false , time.Time {}, 0 , nil , true },
81
-
82
- {sqlite3 .TimeFormatUnixNano , "1381134199120000000" , reference , 0 , time . UTC , false },
83
- {sqlite3 .TimeFormatUnixNano , 1381134199.120e9 , reference , 0 , time . UTC , false },
84
- {sqlite3 .TimeFormatUnixNano , int64 (1381134199_120000000 ), reference , 0 , time . UTC , false },
85
- {sqlite3 .TimeFormatUnixNano , "abc" , time.Time {}, 0 , nil , true },
86
- {sqlite3 .TimeFormatUnixNano , false , time.Time {}, 0 , nil , true },
87
-
88
- {sqlite3 .TimeFormatAuto , "2456572.849526851851852" , reference , time .Millisecond , time . UTC , false },
89
- {sqlite3 .TimeFormatAuto , "2456572" , reference , 24 * time .Hour , time . UTC , false },
90
- {sqlite3 .TimeFormatAuto , "1381134199.120" , reference , time .Microsecond , time . UTC , false },
91
- {sqlite3 .TimeFormatAuto , "1381134199.120e3" , reference , time .Microsecond , time . UTC , false },
92
- {sqlite3 .TimeFormatAuto , "1381134199.120e6" , reference , time .Microsecond , time . UTC , false },
93
- {sqlite3 .TimeFormatAuto , "1381134199.120e9" , reference , time .Microsecond , time . UTC , false },
94
- {sqlite3 .TimeFormatAuto , "1381134199" , reference , time .Second , time . UTC , false },
95
- {sqlite3 .TimeFormatAuto , "1381134199120" , reference , 0 , time . UTC , false },
96
- {sqlite3 .TimeFormatAuto , "1381134199120000" , reference , 0 , time . UTC , false },
97
- {sqlite3 .TimeFormatAuto , "1381134199120000000" , reference , 0 , time . UTC , false },
98
- {sqlite3 .TimeFormatAuto , "2013-10-07 04:23:19.12-04:00" , reference , 0 , zone , false },
99
- {sqlite3 .TimeFormatAuto , "04:23:19.12-04:00" , refnodate , 0 , zone , false },
100
- {sqlite3 .TimeFormatAuto , "abc" , time.Time {}, 0 , nil , true },
101
- {sqlite3 .TimeFormatAuto , false , time.Time {}, 0 , nil , true },
102
-
103
- {sqlite3 .TimeFormat3 , "2013-10-07 04:23:19.12-04:00" , reference , 0 , zone , false },
104
- {sqlite3 .TimeFormat3 , "2013-10-07 08:23:19.12" , reference , 0 , time . UTC , false },
105
- {sqlite3 .TimeFormat9 , "04:23:19.12-04:00" , refnodate , 0 , zone , false },
106
- {sqlite3 .TimeFormat9 , "08:23:19.12" , refnodate , 0 , time . UTC , false },
107
- {sqlite3 .TimeFormat3 , false , time.Time {}, 0 , nil , true },
108
- {sqlite3 .TimeFormat9 , false , time.Time {}, 0 , nil , true },
109
-
110
- {sqlite3 .TimeFormatDefault , "2013-10-07T04:23:19.12-04:00" , reference , 0 , zone , false },
111
- {sqlite3 .TimeFormatDefault , "2013-10-07T08:23:19.12Z" , reference , 0 , time . UTC , false },
112
- {sqlite3 .TimeFormatDefault , false , time.Time {}, 0 , nil , true },
60
+ {sqlite3 .TimeFormatJulianDay , "2456572.849526851851852" , reference , 0 , 0 , false },
61
+ {sqlite3 .TimeFormatJulianDay , 2456572.849526851851852 , reference , time .Millisecond , 0 , false },
62
+ {sqlite3 .TimeFormatJulianDay , int64 (2456572 ), reference , 24 * time .Hour , 0 , false },
63
+ {sqlite3 .TimeFormatJulianDay , false , time.Time {}, 0 , 0 , true },
64
+
65
+ {sqlite3 .TimeFormatUnix , "1381134199.120" , reference , time .Microsecond , 0 , false },
66
+ {sqlite3 .TimeFormatUnix , 1381134199.120 , reference , time .Microsecond , 0 , false },
67
+ {sqlite3 .TimeFormatUnix , int64 (1381134199 ), reference , time .Second , 0 , false },
68
+ {sqlite3 .TimeFormatUnix , "abc" , time.Time {}, 0 , 0 , true },
69
+ {sqlite3 .TimeFormatUnix , false , time.Time {}, 0 , 0 , true },
70
+
71
+ {sqlite3 .TimeFormatUnixMilli , "1381134199120" , reference , 0 , 0 , false },
72
+ {sqlite3 .TimeFormatUnixMilli , 1381134199.120e3 , reference , 0 , 0 , false },
73
+ {sqlite3 .TimeFormatUnixMilli , int64 (1381134199_120 ), reference , 0 , 0 , false },
74
+ {sqlite3 .TimeFormatUnixMilli , "abc" , time.Time {}, 0 , 0 , true },
75
+ {sqlite3 .TimeFormatUnixMilli , false , time.Time {}, 0 , 0 , true },
76
+
77
+ {sqlite3 .TimeFormatUnixMicro , "1381134199120000" , reference , 0 , 0 , false },
78
+ {sqlite3 .TimeFormatUnixMicro , 1381134199.120e6 , reference , 0 , 0 , false },
79
+ {sqlite3 .TimeFormatUnixMicro , int64 (1381134199_120000 ), reference , 0 , 0 , false },
80
+ {sqlite3 .TimeFormatUnixMicro , "abc" , time.Time {}, 0 , 0 , true },
81
+ {sqlite3 .TimeFormatUnixMicro , false , time.Time {}, 0 , 0 , true },
82
+
83
+ {sqlite3 .TimeFormatUnixNano , "1381134199120000000" , reference , 0 , 0 , false },
84
+ {sqlite3 .TimeFormatUnixNano , 1381134199.120e9 , reference , 0 , 0 , false },
85
+ {sqlite3 .TimeFormatUnixNano , int64 (1381134199_120000000 ), reference , 0 , 0 , false },
86
+ {sqlite3 .TimeFormatUnixNano , "abc" , time.Time {}, 0 , 0 , true },
87
+ {sqlite3 .TimeFormatUnixNano , false , time.Time {}, 0 , 0 , true },
88
+
89
+ {sqlite3 .TimeFormatAuto , "2456572.849526851851852" , reference , time .Millisecond , 0 , false },
90
+ {sqlite3 .TimeFormatAuto , "2456572" , reference , 24 * time .Hour , 0 , false },
91
+ {sqlite3 .TimeFormatAuto , "1381134199.120" , reference , time .Microsecond , 0 , false },
92
+ {sqlite3 .TimeFormatAuto , "1381134199.120e3" , reference , time .Microsecond , 0 , false },
93
+ {sqlite3 .TimeFormatAuto , "1381134199.120e6" , reference , time .Microsecond , 0 , false },
94
+ {sqlite3 .TimeFormatAuto , "1381134199.120e9" , reference , time .Microsecond , 0 , false },
95
+ {sqlite3 .TimeFormatAuto , "1381134199" , reference , time .Second , 0 , false },
96
+ {sqlite3 .TimeFormatAuto , "1381134199120" , reference , 0 , 0 , false },
97
+ {sqlite3 .TimeFormatAuto , "1381134199120000" , reference , 0 , 0 , false },
98
+ {sqlite3 .TimeFormatAuto , "1381134199120000000" , reference , 0 , 0 , false },
99
+ {sqlite3 .TimeFormatAuto , "2013-10-07 04:23:19.12-04:00" , reference , 0 , offset , false },
100
+ {sqlite3 .TimeFormatAuto , "04:23:19.12-04:00" , refnodate , 0 , offset , false },
101
+ {sqlite3 .TimeFormatAuto , "abc" , time.Time {}, 0 , 0 , true },
102
+ {sqlite3 .TimeFormatAuto , false , time.Time {}, 0 , 0 , true },
103
+
104
+ {sqlite3 .TimeFormat3 , "2013-10-07 04:23:19.12-04:00" , reference , 0 , offset , false },
105
+ {sqlite3 .TimeFormat3 , "2013-10-07 08:23:19.12" , reference , 0 , 0 , false },
106
+ {sqlite3 .TimeFormat9 , "04:23:19.12-04:00" , refnodate , 0 , offset , false },
107
+ {sqlite3 .TimeFormat9 , "08:23:19.12" , refnodate , 0 , 0 , false },
108
+ {sqlite3 .TimeFormat3 , false , time.Time {}, 0 , 0 , true },
109
+ {sqlite3 .TimeFormat9 , false , time.Time {}, 0 , 0 , true },
110
+
111
+ {sqlite3 .TimeFormatDefault , "2013-10-07T04:23:19.12-04:00" , reference , 0 , offset , false },
112
+ {sqlite3 .TimeFormatDefault , "2013-10-07T08:23:19.12Z" , reference , 0 , 0 , false },
113
+ {sqlite3 .TimeFormatDefault , false , time.Time {}, 0 , 0 , true },
113
114
}
114
115
115
116
for _ , tt := range tests {
@@ -122,8 +123,8 @@ func TestTimeFormat_Decode(t *testing.T) {
122
123
if got .Sub (tt .want ).Abs () > tt .wantDelta {
123
124
t .Errorf ("%q.Decode(%v) = %v, want %v" , tt .fmt , tt .val , got , tt .want )
124
125
}
125
- if got .Location (). String () != tt .wantLoc . String () {
126
- t .Errorf ("%q.Decode(%v) = %v, want %v" , tt .fmt , tt .val , got . Location () , tt .wantLoc )
126
+ if _ , off := got .Zone (); off != tt .wantOff {
127
+ t .Errorf ("%q.Decode(%v) = %v, want %v" , tt .fmt , tt .val , off , tt .wantOff )
127
128
}
128
129
})
129
130
}
0 commit comments