From 29b6e486ff4962ebf5e07cd505dcf156c9b798dd Mon Sep 17 00:00:00 2001 From: muava12 Date: Mon, 23 Feb 2026 09:51:49 +0800 Subject: [PATCH] feat(config): add timezone setting to agents.defaults Add a timezone field to AgentDefaults that overrides the process-wide default timezone via time.Local at startup. This ensures all time.Now() calls across cron, heartbeat, and agent context use the configured timezone instead of relying on the server system timezone. Also supports override via PICOCLAW_AGENTS_DEFAULTS_TIMEZONE env var. --- config/config.example.json | 3 ++- pkg/config/config.go | 11 +++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/config/config.example.json b/config/config.example.json index 77a8c0683..001d42939 100644 --- a/config/config.example.json +++ b/config/config.example.json @@ -2,6 +2,7 @@ "agents": { "defaults": { "workspace": "~/.picoclaw/workspace", + "timezone": "Asia/Makassar", "restrict_to_workspace": true, "model": "gpt4", "max_tokens": 8192, @@ -246,4 +247,4 @@ "host": "0.0.0.0", "port": 18790 } -} +} \ No newline at end of file diff --git a/pkg/config/config.go b/pkg/config/config.go index 036021e49..f08ea2747 100644 --- a/pkg/config/config.go +++ b/pkg/config/config.go @@ -6,6 +6,7 @@ import ( "os" "path/filepath" "sync/atomic" + "time" "github.com/caarlos0/env/v11" ) @@ -167,6 +168,7 @@ type SessionConfig struct { } type AgentDefaults struct { + Timezone string `json:"timezone,omitempty" env:"PICOCLAW_AGENTS_DEFAULTS_TIMEZONE"` Workspace string `json:"workspace" env:"PICOCLAW_AGENTS_DEFAULTS_WORKSPACE"` RestrictToWorkspace bool `json:"restrict_to_workspace" env:"PICOCLAW_AGENTS_DEFAULTS_RESTRICT_TO_WORKSPACE"` Provider string `json:"provider" env:"PICOCLAW_AGENTS_DEFAULTS_PROVIDER"` @@ -515,6 +517,15 @@ func LoadConfig(path string) (*Config, error) { return nil, err } + // Apply timezone from config — overrides process-wide default + if tz := cfg.Agents.Defaults.Timezone; tz != "" { + loc, err := time.LoadLocation(tz) + if err != nil { + return nil, fmt.Errorf("invalid timezone %q: %w", tz, err) + } + time.Local = loc + } + return cfg, nil }