MCPcopy Create free account
hub / github.com/AGenUI/AGenUI / execute

Method execute

core/src/function_call/builtins/agenui_format_date_functioncall.cpp:160–196  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

158}
159
160FunctionCallResolution FormatDateFunctionCall::execute(const nlohmann::json& args) {
161 if (!args.contains("value") || !args.contains("format")) {
162 return FunctionCallResolution::createError("Missing required parameters");
163 }
164
165 if (!args["format"].is_string()) {
166 return FunctionCallResolution::createError("Format must be a string");
167 }
168
169 std::string format = args["format"].get<std::string>();
170 std::time_t timestamp;
171
172 if (args["value"].is_string()) {
173 // ISO 8601 string
174 std::string dateStr = args["value"].get<std::string>();
175 timestamp = parseISO8601(dateStr);
176
177 if (timestamp == -1) {
178 return FunctionCallResolution::createError("Invalid date string format");
179 }
180 } else if (args["value"].is_number()) {
181 // Unix timestamp in milliseconds
182 int64_t ms = args["value"].get<int64_t>();
183 timestamp = static_cast<std::time_t>(ms / 1000);
184 } else {
185 return FunctionCallResolution::createError("Value must be a string or number");
186 }
187
188 std::tm* tm = std::localtime(&timestamp);
189 if (!tm) {
190 return FunctionCallResolution::createError("Failed to convert timestamp");
191 }
192
193 std::string result = formatWithTR35(*tm, format);
194
195 return FunctionCallResolution::createSuccess(result);
196}
197
198FunctionCallConfig FormatDateFunctionCall::getConfig() const {
199 FunctionCallConfig config;

Callers

nothing calls this directly

Calls 3

parseISO8601Function · 0.85
formatWithTR35Function · 0.85
containsMethod · 0.80

Tested by

no test coverage detected