Skip to content

Commit ad1b119

Browse files
authored
fix localtime_to_timestamp tool throws 'no attribute localize error' when it executes without specifying a timezone parameter (#23517)
1 parent 85f33fb commit ad1b119

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

api/core/tools/builtin_tool/providers/time/tools/localtime_to_timestamp.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,12 @@ def _invoke(
3737
@staticmethod
3838
def localtime_to_timestamp(localtime: str, time_format: str, local_tz=None) -> int | None:
3939
try:
40+
local_time = datetime.strptime(localtime, time_format)
4041
if local_tz is None:
41-
local_tz = datetime.now().astimezone().tzinfo
42-
if isinstance(local_tz, str):
42+
localtime = local_time.astimezone() # type: ignore
43+
elif isinstance(local_tz, str):
4344
local_tz = pytz.timezone(local_tz)
44-
local_time = datetime.strptime(localtime, time_format)
45-
localtime = local_tz.localize(local_time) # type: ignore
45+
localtime = local_tz.localize(local_time) # type: ignore
4646
timestamp = int(localtime.timestamp()) # type: ignore
4747
return timestamp
4848
except Exception as e:

0 commit comments

Comments
 (0)