feat(tool): add datetime_to_timestamp operation with timezone support
This commit is contained in:
@@ -253,9 +253,9 @@ class DateTimeTool(BuiltinTool):
|
|||||||
return {
|
return {
|
||||||
"datetime": input_value,
|
"datetime": input_value,
|
||||||
"timezone": timezone_str,
|
"timezone": timezone_str,
|
||||||
"timestamp": int(dt.timestamp()),
|
"timestamp": int(dt.timestamp()) * 1000,
|
||||||
"iso_format": dt.isoformat(),
|
"iso_format": dt.isoformat(),
|
||||||
"result_data": int(dt.timestamp())
|
"result_data": int(dt.timestamp()) * 1000
|
||||||
}
|
}
|
||||||
|
|
||||||
def _calculate_datetime(self, kwargs) -> dict:
|
def _calculate_datetime(self, kwargs) -> dict:
|
||||||
|
|||||||
@@ -138,6 +138,29 @@ class OperationTool(BaseTool):
|
|||||||
default="Asia/Shanghai"
|
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:
|
else:
|
||||||
return []
|
return []
|
||||||
|
|
||||||
|
|||||||
@@ -574,6 +574,29 @@ class ToolService:
|
|||||||
"default": "Asia/Shanghai"
|
"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:
|
else:
|
||||||
# 默认返回所有参数(除了operation)
|
# 默认返回所有参数(除了operation)
|
||||||
return [
|
return [
|
||||||
|
|||||||
Reference in New Issue
Block a user