Skip to content

Commit 8527b1e

Browse files
adamshiervaniym
andauthored
feat: improve custom jiggler settings and add timezone support (#742)
* feat: add timezone support to jiggler and fix custom settings persistence - Add timezone field to JigglerConfig with comprehensive IANA timezone list - Fix custom settings not loading current values - Remove business hours preset, add as examples in custom settings - Improve error handling for invalid cron expressions * fix: format jiggler.go with gofmt * fix: add embedded timezone data and validation - Import time/tzdata to embed timezone database in binary - Add timezone validation in runJigglerCronTab() to gracefully fallback to UTC - Add timezone to debug logging in rpcSetJigglerConfig - Fixes 'unknown time zone' errors when system lacks timezone data * refactor: add timezone field comments from jiggler options * chore: move tzdata to backend * refactor: fix JigglerSetting linting - Adjusted useEffect dependency to include send function for better data fetching - Modified layout classes for improved responsiveness and consistency - Cleaned up code formatting for better readability --------- Co-authored-by: Siyuan Miao <[email protected]>
1 parent 9f57320 commit 8527b1e

File tree

8 files changed

+831
-42
lines changed

8 files changed

+831
-42
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ VERSION ?= 0.4.6
88
PROMETHEUS_TAG := github.com/prometheus/common/version
99
KVM_PKG_NAME := github.com/jetkvm/kvm
1010

11-
GO_BUILD_ARGS := -tags netgo
11+
GO_BUILD_ARGS := -tags netgo -tags timetzdata
1212
GO_RELEASE_BUILD_ARGS := -trimpath $(GO_BUILD_ARGS)
1313
GO_LDFLAGS := \
1414
-s -w \

config.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,7 @@ var defaultConfig = &Config{
123123
InactivityLimitSeconds: 60,
124124
JitterPercentage: 25,
125125
ScheduleCronTab: "0 * * * * *",
126+
Timezone: "UTC",
126127
},
127128
TLSMode: "",
128129
UsbConfig: &usbgadget.Config{

internal/tzdata/gen.go

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
//go:build ignore
2+
3+
package main
4+
5+
import (
6+
"archive/zip"
7+
"bytes"
8+
"flag"
9+
"fmt"
10+
"os"
11+
"text/template"
12+
)
13+
14+
var tmpl = `// Code generated by "go run gen.go". DO NOT EDIT.
15+
//go:generate env ZONEINFO=$GOROOT/lib/time/zoneinfo.zip go run gen.go -output tzdata.go
16+
package tzdata
17+
var TimeZones = []string{
18+
{{- range . }}
19+
"{{.}}",
20+
{{- end }}
21+
}
22+
`
23+
24+
var filename = flag.String("output", "tzdata.go", "output file name")
25+
26+
func main() {
27+
flag.Parse()
28+
29+
path := os.Getenv("ZONEINFO")
30+
if path == "" {
31+
fmt.Println("ZONEINFO is not set")
32+
os.Exit(1)
33+
}
34+
35+
if _, err := os.Stat(path); os.IsNotExist(err) {
36+
fmt.Printf("ZONEINFO %s does not exist\n", path)
37+
os.Exit(1)
38+
}
39+
40+
zipfile, err := zip.OpenReader(path)
41+
if err != nil {
42+
fmt.Printf("Error opening ZONEINFO %s: %v\n", path, err)
43+
os.Exit(1)
44+
}
45+
defer zipfile.Close()
46+
47+
timezones := []string{}
48+
49+
for _, file := range zipfile.File {
50+
timezones = append(timezones, file.Name)
51+
}
52+
53+
var buf bytes.Buffer
54+
55+
tmpl, err := template.New("tzdata").Parse(tmpl)
56+
if err != nil {
57+
fmt.Printf("Error parsing template: %v\n", err)
58+
os.Exit(1)
59+
}
60+
61+
err = tmpl.Execute(&buf, timezones)
62+
if err != nil {
63+
fmt.Printf("Error executing template: %v\n", err)
64+
os.Exit(1)
65+
}
66+
67+
err = os.WriteFile(*filename, buf.Bytes(), 0644)
68+
if err != nil {
69+
fmt.Printf("Error writing file %s: %v\n", *filename, err)
70+
os.Exit(1)
71+
}
72+
}

0 commit comments

Comments
 (0)