소스 검색

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

tags/1.7.2
goofy 2 달 전
부모
커밋
ad1b1193fa
No account linked to committer's email address
1개의 변경된 파일4개의 추가작업 그리고 4개의 파일을 삭제
  1. 4
    4
      api/core/tools/builtin_tool/providers/time/tools/localtime_to_timestamp.py

+ 4
- 4
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:

Loading…
취소
저장