fix(worklog): always send logged_date (required datetime) on worklog add

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
<yyyy-mm-dd> to start-of-day so it parses as a datetime.

Verified on sim: `hf worklog add --task <code> --hours <n> --desc ...`
(no --date) now succeeds.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
h z
2026-06-10 10:15:10 +01:00
parent 6dcf43ce41
commit f145979684

View File

@@ -4,6 +4,7 @@ import (
"bytes" "bytes"
"encoding/json" "encoding/json"
"fmt" "fmt"
"time"
"git.hangman-lab.top/zhi/HarborForge.Cli/internal/output" "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 != "" { if desc != "" {
payload["description"] = desc payload["description"] = desc
} }
// logged_date is a REQUIRED datetime on the backend. Default to now; if
// the operator passed --date <yyyy-mm-dd>, anchor it to start-of-day so a
// bare date still parses as a datetime.
loggedDate := time.Now().UTC().Format(time.RFC3339)
if date != "" { 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) body, err := json.Marshal(payload)
if err != nil { if err != nil {