From f145979684156b604444abc68168e5df14df27d8 Mon Sep 17 00:00:00 2001 From: hzhang Date: Wed, 10 Jun 2026 10:15:10 +0100 Subject: [PATCH] fix(worklog): always send logged_date (required datetime) on `worklog add` MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The backend's WorkLogCreate.logged_date is a REQUIRED datetime, but the CLI only sent it when --date was passed, and then as a bare YYYY-MM-DD that failed datetime parsing → `hf worklog add` always 422'd (missing, then invalid). Default logged_date to now (RFC3339); anchor a bare --date to start-of-day so it parses as a datetime. Verified on sim: `hf worklog add --task --hours --desc ...` (no --date) now succeeds. Co-Authored-By: Claude Opus 4.8 (1M context) --- internal/commands/worklog.go | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/internal/commands/worklog.go b/internal/commands/worklog.go index fa51328..a608fc6 100644 --- a/internal/commands/worklog.go +++ b/internal/commands/worklog.go @@ -4,6 +4,7 @@ import ( "bytes" "encoding/json" "fmt" + "time" "git.hangman-lab.top/zhi/HarborForge.Cli/internal/output" ) @@ -35,9 +36,18 @@ func RunWorklogAdd(taskCode string, hours float64, desc, date, tokenFlag string) if desc != "" { payload["description"] = desc } + // logged_date is a REQUIRED datetime on the backend. Default to now; if + // the operator passed --date , anchor it to start-of-day so a + // bare date still parses as a datetime. + loggedDate := time.Now().UTC().Format(time.RFC3339) if date != "" { - payload["logged_date"] = date + if len(date) == 10 { // bare YYYY-MM-DD + loggedDate = date + "T00:00:00Z" + } else { + loggedDate = date + } } + payload["logged_date"] = loggedDate body, err := json.Marshal(payload) if err != nil {