diff --git a/internal/handlers/sidecar.go b/internal/handlers/sidecar.go
index 92c3b6a..9ba5cf9 100644
--- a/internal/handlers/sidecar.go
+++ b/internal/handlers/sidecar.go
@@ -388,6 +388,23 @@ func (h *SidecarHandler) UpdateSystemConfiguration(c *echo.Context) error {
// Update each config value
for key, value := range req {
+ if key == "default_timezone" {
+ if _, err := time.LoadLocation(value); err != nil {
+ return c.JSON(http.StatusBadRequest, map[string]string{
+ "error": "invalid timezone",
+ })
+ }
+ err := h.db.UpdateSystemSetting(ctx, database.UpdateSystemSettingParams{
+ SettingKey: "default_timezone",
+ SettingValue: value,
+ })
+ if err != nil {
+ return c.JSON(http.StatusInternalServerError, map[string]string{
+ "error": "failed to update default timezone",
+ })
+ }
+ continue
+ }
_, err := h.db.SetSystemConfig(ctx, database.SetSystemConfigParams{
Key: key,
Value: value,
@@ -408,6 +425,12 @@ func (h *SidecarHandler) UpdateSystemConfiguration(c *echo.Context) error {
return c.HTML(http.StatusInternalServerError, `
Failed to fetch updated configuration
`)
}
+ defaultTimezone := "UTC"
+ tz, err := h.db.GetSystemTimezone(ctx)
+ if err == nil && tz != "" {
+ defaultTimezone = tz
+ }
+
// Render success message with updated form
return c.HTML(http.StatusOK, fmt.Sprintf(`
@@ -437,6 +460,28 @@ func (h *SidecarHandler) UpdateSystemConfiguration(c *echo.Context) error {
+
+
System Defaults
+
+
+
+
Default timezone for users who haven't set their own.
+
+
+
+
+
@@ -447,7 +492,16 @@ func (h *SidecarHandler) UpdateSystemConfiguration(c *echo.Context) error {
Device Sync: %s/api/sync
-`, baseURL.Value, baseURL.Value, baseURL.Value, baseURL.Value))
+`, baseURL.Value,
+ selectedAttr(defaultTimezone, "UTC"),
+ selectedAttr(defaultTimezone, "America/New_York"),
+ selectedAttr(defaultTimezone, "America/Chicago"),
+ selectedAttr(defaultTimezone, "America/Denver"),
+ selectedAttr(defaultTimezone, "America/Los_Angeles"),
+ selectedAttr(defaultTimezone, "America/Phoenix"),
+ selectedAttr(defaultTimezone, "America/Anchorage"),
+ selectedAttr(defaultTimezone, "Pacific/Honolulu"),
+ baseURL.Value, baseURL.Value, baseURL.Value))
}
return c.JSON(http.StatusOK, map[string]string{
@@ -477,3 +531,10 @@ func sanitizeAll(s string, old string, new string) string {
}
return result
}
+
+func selectedAttr(current, value string) string {
+ if current == value {
+ return " selected"
+ }
+ return ""
+}
diff --git a/internal/router/frontend.go b/internal/router/frontend.go
index b63dc8e..2dca858 100644
--- a/internal/router/frontend.go
+++ b/internal/router/frontend.go
@@ -932,7 +932,13 @@ func registerFrontendRoutes(cfg *Config) {
}
systemConfig := map[string]string{
- "base_url": baseURL,
+ "base_url": baseURL,
+ "default_timezone": "UTC",
+ }
+
+ defaultTimezone, err := cfg.Queries.GetSystemTimezone(c.Request().Context())
+ if err == nil && defaultTimezone != "" {
+ systemConfig["default_timezone"] = defaultTimezone
}
var buf bytes.Buffer
diff --git a/templates/admin_settings.templ b/templates/admin_settings.templ
index 1bd0e26..f9d254c 100644
--- a/templates/admin_settings.templ
+++ b/templates/admin_settings.templ
@@ -51,19 +51,27 @@ templ AdminSettings(user User, systemConfig map[string]string, errorMessage stri
-
-
System Defaults
-
-
+
+
System Defaults
+
+
+
+
Default timezone for users who haven't set their own.
+