Skip to content
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

fix: 安卓环境Go Time 固定UTC时区,通过时区获取偏移量修正时区 #1284

Merged
merged 2 commits into from
Oct 17, 2024

Conversation

lpcheng1208
Copy link
Contributor

@lpcheng1208 lpcheng1208 commented Oct 17, 2024

修复安卓环境运行ddns-go 少8小时的问题。

[go/src/time/zoneinfo_android.go]
func initLocal() {
// TODO(elias.naur): getprop persist.sys.timezone
localLoc = *UTC
}

zoneinfo_android.go 固定了 localLoc 为 UTC,所以设置环境变量无效。
设置启动参数 tZ, 默认从环境获取时区字符串, 判断当前GOOS为 android 调用 FixTimezone 进行时区修正

@jeessy2
Copy link
Owner

jeessy2 commented Oct 17, 2024

能自动更好。golang/go#20455 (comment)

@lpcheng1208
Copy link
Contributor Author

能自动更好。golang/go#20455 (comment)

根据你的提示已经做了修改, tZ 参数不设置默认值, 根据环境获取时区字符串, 传入 tZ 则用自定义的时区

@lpcheng1208
Copy link
Contributor Author

lpcheng1208 commented Oct 17, 2024

image 本地环境已经做了验证

main.go Outdated
Comment on lines 60 to 62
// 修正安卓时区
var timeZone = flag.String("tZ", "", "fix Android Time Zone")

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

只有android才有问题吧,可以不要此参数,判断是android才自动改。

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

是的目前发现只有安卓会出现这个问题

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

只有android才有问题吧,可以不要此参数,判断是android才自动改。

加入参数是为了,让用户可以自定义选择时区

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

那可以不用这个参数,简单点

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

那可以不用这个参数,简单点

好的

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

判断是android,直接用那段代码,不搞复杂了

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

判断是android,直接用那段代码,不搞复杂了

已做修改

main.go Outdated
Comment on lines 81 to 84
// func initLocal() {
// // TODO(elias.naur): getprop persist.sys.timezone
// localLoc = *UTC
// }
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这段也不要了吧

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

已去除,希望能加入

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

测了正常吧?

Copy link
Contributor Author

@lpcheng1208 lpcheng1208 Oct 17, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

测了正常吧?

image image

我这边基于 我的车机adb 环境测试是没问题的

@jeessy2 jeessy2 merged commit 2c4d8a8 into jeessy2:master Oct 17, 2024
@fa1seut0pia
Copy link

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants