@@ -161,6 +161,47 @@ func TestRawBytesResultExceedsBuffer(t *testing.T) {
161
161
})
162
162
}
163
163
164
+ func TestTimezoneConversion (t * testing.T ) {
165
+
166
+ zones := []string {"UTC" , "US/Central" , "US/Pacific" , "Local" }
167
+
168
+ // Regression test for timezone handling
169
+ tzTest := func (dbt * DBTest ) {
170
+
171
+ // Create table
172
+ dbt .mustExec ("CREATE TABLE test (ts TIMESTAMP)" )
173
+
174
+ // Insert local time into database (should be converted)
175
+ usCentral , _ := time .LoadLocation ("US/Central" )
176
+ now := time .Now ().In (usCentral )
177
+ dbt .mustExec ("INSERT INTO test VALUE (?)" , now )
178
+
179
+ // Retrieve time from DB
180
+ rows := dbt .mustQuery ("SELECT ts FROM test" )
181
+ if ! rows .Next () {
182
+ dbt .Fatal ("Didn't get any rows out" )
183
+ }
184
+
185
+ var nowDB time.Time
186
+ err := rows .Scan (& nowDB )
187
+ if err != nil {
188
+ dbt .Fatal ("Err" , err )
189
+ }
190
+
191
+ // Check that dates match
192
+ if now .Unix () != nowDB .Unix () {
193
+ dbt .Errorf ("Times don't match.\n " )
194
+ dbt .Errorf (" Now(%v)=%v\n " , usCentral , now )
195
+ dbt .Errorf (" Now(UTC)=%v\n " , nowDB )
196
+ }
197
+
198
+ }
199
+
200
+ for _ , tz := range zones {
201
+ runTests (t , dsn + "&parseTime=true&loc=" + tz , tzTest )
202
+ }
203
+ }
204
+
164
205
func TestCRUD (t * testing.T ) {
165
206
runTests (t , dsn , func (dbt * DBTest ) {
166
207
// Create Table
@@ -1054,7 +1095,7 @@ func TestStmtMultiRows(t *testing.T) {
1054
1095
1055
1096
func TestConcurrent (t * testing.T ) {
1056
1097
if enabled , _ := readBool (os .Getenv ("MYSQL_TEST_CONCURRENT" )); ! enabled {
1057
- t .Skip ("CONCURRENT env var not set" )
1098
+ t .Skip ("MYSQL_TEST_CONCURRENT env var not set" )
1058
1099
}
1059
1100
1060
1101
runTests (t , dsn , func (dbt * DBTest ) {
0 commit comments