From 7a88b4a32908a7413c3a90cb9a56deabd7dedb65 Mon Sep 17 00:00:00 2001 From: debidong <1953531014@qq.com> Date: Fri, 9 Oct 2026 11:19:27 +0800 Subject: [PATCH] automation: accept timezone on rule update --- automations_models.go | 5 +++++ automations_models_test.go | 39 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 44 insertions(+) create mode 100644 automations_models_test.go diff --git a/automations_models.go b/automations_models.go index fc7f260..e7cda56 100644 --- a/automations_models.go +++ b/automations_models.go @@ -14,6 +14,11 @@ type AutomationRuleUpdateRequest struct { Enabled *bool `json:"enabled,omitempty" toon:"enabled,omitempty"` // Run cadence. Supports 4 fields (`hour day month weekday`, minute defaults to 0) and 5 fields (`minute hour day month weekday`). CronExpr *string `json:"cron_expr,omitempty" toon:"cron_expr,omitempty"` + // IANA timezone `cron_expr` is evaluated in. The server must be able to load + // the name; an invalid value is rejected. Nil leaves the stored timezone + // unchanged, including a legacy empty string. An explicit empty string is + // stored as UTC, not reset to the account default. + Timezone *string `json:"timezone,omitempty" toon:"timezone,omitempty"` // Whether the schedule trigger is enabled. ScheduleTriggerEnabled *bool `json:"schedule_trigger_enabled,omitempty" toon:"schedule_trigger_enabled,omitempty"` // New task prompt. diff --git a/automations_models_test.go b/automations_models_test.go new file mode 100644 index 0000000..15f630d --- /dev/null +++ b/automations_models_test.go @@ -0,0 +1,39 @@ +package flashduty + +import ( + "encoding/json" + "strings" + "testing" +) + +func TestAutomationRuleUpdateRequestTimezone(t *testing.T) { + omitted, err := json.Marshal(&AutomationRuleUpdateRequest{RuleID: "arule_1"}) + if err != nil { + t.Fatal(err) + } + if strings.Contains(string(omitted), "timezone") { + t.Fatalf("nil timezone must be omitted, got %s", omitted) + } + + empty, err := json.Marshal(&AutomationRuleUpdateRequest{ + RuleID: "arule_1", + Timezone: String(""), + }) + if err != nil { + t.Fatal(err) + } + if !strings.Contains(string(empty), `"timezone":""`) { + t.Fatalf("empty timezone must be sent, got %s", empty) + } + + named, err := json.Marshal(&AutomationRuleUpdateRequest{ + RuleID: "arule_1", + Timezone: String("Asia/Shanghai"), + }) + if err != nil { + t.Fatal(err) + } + if !strings.Contains(string(named), `"timezone":"Asia/Shanghai"`) { + t.Fatalf("named timezone must be sent, got %s", named) + } +}