Skip to content

armgit / dify

Public Imported from GitHub
0

Build Agentic workflows, RAG pipelines, with rich AI model and tool support on one collaborative workspace. Deploy on cloud, VPC, or self-hosted, so teams move from prototype to production without rebuilding the stack.

fix localtime_to_timestamp tool throws 'no attribute localize error' when it executes without specifying a timezone parameter (#23517)

goofyad1b1193faec
diff --git a/api/core/tools/builtin_tool/providers/time/tools/localtime_to_timestamp.py b/api/core/tools/builtin_tool/providers/time/tools/localtime_to_timestamp.py
index 1639dd687f5..a8fd6ec2cdf 100644
--- a/api/core/tools/builtin_tool/providers/time/tools/localtime_to_timestamp.py
+++ b/api/core/tools/builtin_tool/providers/time/tools/localtime_to_timestamp.py
@@ -37,12 +37,12 @@ class LocaltimeToTimestampTool(BuiltinTool):
@staticmethod
def localtime_to_timestamp(localtime: str, time_format: str, local_tz=None) -> int | None:
try:
+ local_time = datetime.strptime(localtime, time_format)
if local_tz is None:
- local_tz = datetime.now().astimezone().tzinfo
- if isinstance(local_tz, str):
+ localtime = local_time.astimezone() # type: ignore
+ elif isinstance(local_tz, str):
local_tz = pytz.timezone(local_tz)
- local_time = datetime.strptime(localtime, time_format)
- localtime = local_tz.localize(local_time) # type: ignore
+ localtime = local_tz.localize(local_time) # type: ignore
timestamp = int(localtime.timestamp()) # type: ignore
return timestamp
except Exception as e: