-
-
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
feat(os/gtime): SetStringLayout #4130
Conversation
yzy613
commented
Jan 21, 2025
合理使用Format, Layout, 你的这种方式可能会导致其他依赖gtime.String() 的组件或工具得到的预期值不一致。 |
Use Format and Layout properly. Your approach may cause other components or tools that rely on gtime.String() to get inconsistent expected values. |
有没有可能我就是需要让依赖gtime.Time.String()的值改变,例如gtime.Time.MarshalJSON()。 并且如果你不使用这个全局函数,他的默认行为和以往版本保持一致。 |
@yzy613 实在是想要你可以封装成StringForRFC3339(),StringForISO8601(),StringForRFC822() |
@yzy613 I really want you to encapsulate it into StringForRFC3339(), StringISO8601(), StringRFC822() |
但他并不会影响MarshalJSON()的行为 |
那你可以SetStringLayout声明在gtime.Time上,而不是全局函数。或者基于gtime.Time定义一个自定义结构体,复写String(),比如
|
全局设置时间格式会导致其他依赖原时间格式的代码出现不可预知的错误。 |
Setting the time format globally will cause unpredictable errors in other code that relies on the original time format. |
还有一个问题就是,gtime.Time.String()没有时区信息,在跨时区的数据交换上,不好用。 |
这种建议保留在你自己的分支,定期同步源分支就好 |
It is recommended to keep this in your own branch, and just synchronize the source branch regularly. |
那我们为什么不试试将依赖原格式的代码找到并解耦呢? |
So why don't we try to find and decouple the code that relies on the original format? |
@yzy613 感谢参与咱们的开源项目共建!其实在时间这块,不建议全局改动 |
@yzy613 Thank you for participating in our open source project! In fact, when it comes to time, it is not recommended to globally change the formatting logic of |
那时区输出就只能再wrap一层做String()和MarshalJSON()咯(好不优雅XP |
At that time, the zone output can only be done by wrapping one layer to String() and MarshalJSON() (so inelegant XP |
懂了,是因为MySQL不支持其他时间格式 |
Got it, it’s because MySQL does not support other time formats |