From 5975d70bf9b4e1398730a3386f37d1df258ac369 Mon Sep 17 00:00:00 2001 From: Timebomb2018 <18868801967@163.com> Date: Thu, 9 Apr 2026 15:14:15 +0800 Subject: [PATCH] feat(tool): add datetime_to_timestamp operation with timezone support --- api/app/core/tools/builtin/datetime_tool.py | 4 ++-- api/app/core/tools/builtin/operation_tool.py | 23 ++++++++++++++++++++ api/app/services/tool_service.py | 23 ++++++++++++++++++++ 3 files changed, 48 insertions(+), 2 deletions(-) diff --git a/api/app/core/tools/builtin/datetime_tool.py b/api/app/core/tools/builtin/datetime_tool.py index 8db830ce..aaba90f0 100644 --- a/api/app/core/tools/builtin/datetime_tool.py +++ b/api/app/core/tools/builtin/datetime_tool.py @@ -253,9 +253,9 @@ class DateTimeTool(BuiltinTool): return { "datetime": input_value, "timezone": timezone_str, - "timestamp": int(dt.timestamp()), + "timestamp": int(dt.timestamp()) * 1000, "iso_format": dt.isoformat(), - "result_data": int(dt.timestamp()) + "result_data": int(dt.timestamp()) * 1000 } def _calculate_datetime(self, kwargs) -> dict: diff --git a/api/app/core/tools/builtin/operation_tool.py b/api/app/core/tools/builtin/operation_tool.py index 126541a8..95e6fdf5 100644 --- a/api/app/core/tools/builtin/operation_tool.py +++ b/api/app/core/tools/builtin/operation_tool.py @@ -138,6 +138,29 @@ class OperationTool(BaseTool): default="Asia/Shanghai" ) ] + elif self.operation == "datetime_to_timestamp": + return [ + ToolParameter( + name="input_value", + type=ParameterType.STRING, + description="输入值(时间字符串,如:2026-04-07 10:30:25)", + required=True + ), + ToolParameter( + name="input_format", + type=ParameterType.STRING, + description="输入时间格式(如:%Y-%m-%d %H:%M:%S)", + required=False, + default="%Y-%m-%d %H:%M:%S" + ), + ToolParameter( + name="from_timezone", + type=ParameterType.STRING, + description="源时区(如:UTC, Asia/Shanghai)", + required=False, + default="Asia/Shanghai" + ) + ] else: return [] diff --git a/api/app/services/tool_service.py b/api/app/services/tool_service.py index 089f0ec5..165b060f 100644 --- a/api/app/services/tool_service.py +++ b/api/app/services/tool_service.py @@ -574,6 +574,29 @@ class ToolService: "default": "Asia/Shanghai" } ] + elif operation == "datetime_to_timestamp": + return [ + { + "name": "input_value", + "type": "string", + "description": "输入值(时间字符串,如:2026-04-07 10:30:25)", + "required": True + }, + { + "name": "input_format", + "type": "string", + "description": "输入时间格式(如:%Y-%m-%d %H:%M:%S)", + "required": False, + "default": "%Y-%m-%d %H:%M:%S" + }, + { + "name": "from_timezone", + "type": "string", + "description": "源时区(如:UTC, Asia/Shanghai)", + "required": False, + "default": "Asia/Shanghai" + } + ] else: # 默认返回所有参数(除了operation) return [