MCPcopy
hub / github.com/go-sql-driver/mysql / TestTimezoneConversion

Function TestTimezoneConversion

driver_test.go:1683–1720  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

1681}
1682
1683func TestTimezoneConversion(t *testing.T) {
1684 zones := []string{"UTC", "America/New_York", "Asia/Hong_Kong", "Local"}
1685
1686 // Regression test for timezone handling
1687 tzTest := func(dbt *DBTest) {
1688 // Create table
1689 dbt.mustExec("CREATE TABLE test (ts TIMESTAMP)")
1690
1691 // Insert local time into database (should be converted)
1692 newYorkTz, _ := time.LoadLocation("America/New_York")
1693 reftime := time.Date(2014, 05, 30, 18, 03, 17, 0, time.UTC).In(newYorkTz)
1694 dbt.mustExec("INSERT INTO test VALUE (?)", reftime)
1695
1696 // Retrieve time from DB
1697 rows := dbt.mustQuery("SELECT ts FROM test")
1698 defer rows.Close()
1699 if !rows.Next() {
1700 dbt.Fatal("did not get any rows out")
1701 }
1702
1703 var dbTime time.Time
1704 err := rows.Scan(&dbTime)
1705 if err != nil {
1706 dbt.Fatal("Err", err)
1707 }
1708
1709 // Check that dates match
1710 if reftime.Unix() != dbTime.Unix() {
1711 dbt.Errorf("times do not match.\n")
1712 dbt.Errorf(" Now(%v)=%v\n", newYorkTz, reftime)
1713 dbt.Errorf(" Now(UTC)=%v\n", dbTime)
1714 }
1715 }
1716
1717 for _, tz := range zones {
1718 runTests(t, dsn+"&parseTime=true&loc="+url.QueryEscape(tz), tzTest)
1719 }
1720}
1721
1722// Special cases
1723

Callers

nothing calls this directly

Calls 6

runTestsFunction · 0.85
mustExecMethod · 0.80
mustQueryMethod · 0.80
ScanMethod · 0.80
CloseMethod · 0.45
NextMethod · 0.45

Tested by

no test coverage detected