package tools import ( "context" "encoding/json" "fmt" "time" "github.com/crypto/openclaw/internal/llm" ) // TimeNow returns the current time, optionally in an IANA time zone. type TimeNow struct{ Now func() time.Time } func (TimeNow) Spec() llm.ToolSpec { return llm.ToolSpec{ Name: "time_now", Description: "Get the current date and time. Optional IANA time zone, e.g. Europe/Berlin.", Parameters: obj(map[string]any{"timezone": map[string]any{"type": "string"}}), } } func (t TimeNow) Call(_ context.Context, raw json.RawMessage) (string, error) { var a struct{ Timezone string `json:"timezone"` } if err := json.Unmarshal(raw, &a); err != nil { return "", err } now := time.Now if t.Now != nil { now = t.Now } n := now() if a.Timezone != "" { loc, err := time.LoadLocation(a.Timezone) if err != nil { return "", fmt.Errorf("unknown timezone %q", a.Timezone) } n = n.In(loc) } return n.Format("2006-01-02T15:04:05 MST (Monday)"), nil }