You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
package test
import (
"fmt"
"log"
"testing"
"time"
"github.com/gogf/gf/frame/g"
"github.com/gogf/gf/os/gtime"
"github.com/gogf/gf/test/gtest"
)
func createTable() string {
db := g.Database()
db.SetDebug(true)
tableName := "test_date"
if _, err := db.Exec(fmt.Sprintf(`
CREATE TABLE %s (
id int(10) unsigned NOT NULL AUTO_INCREMENT,
date datetime NULL,
PRIMARY KEY (id)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
`, tableName,
)); err != nil {
gtest.Fatal(err)
}
return tableName
}
func dropTable(table string) {
db := g.Database()
if _, err := db.Exec(fmt.Sprintf("DROP TABLE IF EXISTS `%s`", table)); err != nil {
gtest.Error(err)
}
}
func Test_mainFile(t *testing.T) {
db := g.Database()
tableName := createTable()
defer dropTable(tableName)
type TestDate struct {
Id int `json:"id"`
Date *gtime.Time `json:"date"`
}
str := "2020-11-23 00:00:00"
date, _ := time.ParseInLocation("2006-01-02 15:04:05", str, time.Local)
log.Print(date)
u := &TestDate{
Id: 1,
Date: gtime.New(date),
}
gtest.C(t, func(t *gtest.T) {
_, _ = db.Table(tableName).Insert(u)
dateEntity := &TestDate{}
err := db.Table(tableName).Where("date=?", date).Struct(&dateEntity)
t.Assert(err, nil)
t.Assert(dateEntity.Date.String(), str)
})
}
日志输出:
2020-11-23 16:56:08.667 [DEBU] [ 25 ms] [default]
CREATE TABLE test_date (
id int(10) unsigned NOT NULL AUTO_INCREMENT,
date datetime NULL,
PRIMARY KEY (id)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
2020/11/23 16:56:08 2020-11-23 00:00:00 +0800 CST
2020-11-23 16:56:08.670 [DEBU] [ 3 ms] [default] SHOW FULL COLUMNS FROM `test_date`
2020-11-23 16:56:08.671 [DEBU] [ 1 ms] [default] INSERT INTO `test_date`(`id`,`date`) VALUES(1,'2020-11-23 00:00:00')
2020-11-23 16:56:11.973 [DEBU] [ 1 ms] [default] SELECT * FROM `test_date` WHERE date='2020-11-23 00:00:00' LIMIT 1
...
2020-11-23 16:56:11.975 [DEBU] [ 2 ms] [default] DROP TABLE IF EXISTS `test_date`
--- FAIL: Test_mainFile (3.33s)
FAIL
MYSQL执行日志:
201123 16:56:08 63 Connect root@localhost on test_data using TCP/IP
63 Query SET NAMES utf8mb4
63 Query CREATE TABLE test_date (
id int(10) unsigned NOT NULL AUTO_INCREMENT,
date datetime NULL,
PRIMARY KEY (id)
) ENGINE=InnoDB DEFAULT CHARSET=utf8
63 Query SHOW FULL COLUMNS FROM `test_date`
63 Prepare INSERT INTO `test_date`(`id`,`date`) VALUES(?,?)
63 Execute INSERT INTO `test_date`(`id`,`date`) VALUES(1,'2020-11-23 00:00:00')
63 Close stmt
201123 16:56:11 63 Prepare SELECT * FROM `test_date` WHERE date=? LIMIT 1
63 Execute SELECT * FROM `test_date` WHERE date='2020-11-22 16:00:00' LIMIT 1
63 Close stmt
63 Query DROP TABLE IF EXISTS `test_date`
The text was updated successfully, but these errors were encountered:
1. What version of
Go
and system type/arch are you using?go version go1.15.5 darwin/amd64
2. What version of
GoFrame
are you using?github.com/gogf/gf v1.14.5
3. Can this issue be reproduced with the latest release?
4. What did you do?
使用 time.Time 类型插入数据时mysql执行日志正常,使用同一个参数作为查询参数时,框架日志显示的时区正常,mysql日志执行中时区变成了UTC时区.
5. What did you expect to see?
6. What did you see instead?
测试代码
日志输出:
MYSQL执行日志:
The text was updated successfully, but these errors were encountered: