Skip to content

Commit 0e8476b

Browse files
committed
fix: 修复mindoc部署在安卓termux上的时区问题
1 parent cc871ed commit 0e8476b

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

main.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import (
1717
"github.com/mindoc-org/mindoc/commands"
1818
"github.com/mindoc-org/mindoc/commands/daemon"
1919
_ "github.com/mindoc-org/mindoc/routers"
20+
"github.com/mindoc-org/mindoc/utils"
2021
)
2122

2223
func isViaDaemonUnix() bool {
@@ -49,6 +50,11 @@ func main() {
4950

5051
d := daemon.NewDaemon()
5152

53+
// 安卓 go/src/time/zoneinfo_android.go 固定localLoc 为 UTC
54+
if runtime.GOOS == "android" {
55+
utils.FixTimezone()
56+
}
57+
5258
if runtime.GOOS != "windows" && !isViaDaemonUnix() {
5359
s, err := service.New(d, d.Config())
5460

utils/android_time.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package utils
2+
3+
import (
4+
"os/exec"
5+
"strings"
6+
"time"
7+
)
8+
9+
func FixTimezone() {
10+
out, err := exec.Command("/system/bin/getprop", "persist.sys.timezone").Output()
11+
if err != nil {
12+
return
13+
}
14+
timeZone, err := time.LoadLocation(strings.TrimSpace(string(out)))
15+
if err != nil {
16+
return
17+
}
18+
time.Local = timeZone
19+
}

0 commit comments

Comments
 (0)