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:
@@ -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 <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 != "" {
|
||||
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 {
|
||||
|
||||
Reference in New Issue
Block a user