-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
gtime.String() lost timezone #3188
Comments
This's not problem. NewFromStr defaults to UTC. time.Local has set +08:00 |
for example: I receive a json string like this: {"time": "2023-12-01T00:00:00.000000Z"} convert it to struct: type A struct {
Time *gtime.Time `json:"time"`
} then marshal the struct to a new json string: {"time": "2023-12-01 00:00:00"} |
@qinyuguang |
codepackage main
import (
"fmt"
"time"
"github.com/gogf/gf/v2/encoding/gjson"
"github.com/gogf/gf/v2/os/gtime"
"github.com/gogf/gf/v2/util/gconv"
)
type T1 struct {
Time1 *gtime.Time `json:"time1"`
Time2 *gtime.Time `json:"time2"`
}
type T2 struct {
Time1 *time.Time `json:"time1"`
Time2 *time.Time `json:"time2"`
}
func main() {
str := `{"time1": "2023-12-01T00:00:00.000000Z", "time2": "2023-12-01T00:00:00.000000+08:00"}`
var (
t1 *T1
t2 *T2
)
_ = gconv.Struct(str, &t1)
_ = gconv.Struct(str, &t2)
s1 := gjson.New(t1).MustToJsonIndentString()
s2 := gjson.New(t2).MustToJsonIndentString()
fmt.Println(s1)
fmt.Println(s2)
} output
Is this result expected? time.Time retains the timezone, but gtime.Time loses the timezone. What I mean is that instead of letting people know the timezone of each field, after conversion, all time fields become the current timezone set by gtime. |
anything new? |
I find the gdb debug mode can output the raw sql, will this problem cause the output raw sql is not the sql that the database really execute? for example when use postgre database,the field type is timestamp with time zone , I did find the debug mode sql seems not the real query sql, this makes me confused。 yesterday,our sandbox database change the timezone from Asia/Shanghai to UTF8, then I find some test case can't pass,
but the fact is 2.0.3 can pass,2.6.2 can’t。 |
1. What version of
Go
and system type/arch are you using?go version go1.21.3 darwin/arm64
2. What version of
GoFrame
are you using?gf v2.5.7
3. Can this issue be re-produced with the latest release?
yes
4. What did you do?
marshal a map which contains gtime.Time, the result lost timezone.
5. What did you expect to see?
with local timezone
or same result as encoding/json marshal
6. What did you see instead?
Since gtime.String() loses timezone, can it be formatted to the local timezone by default?
change to:
@gqcn
The text was updated successfully, but these errors were encountered: