mirror of
https://git.mirrors.martin98.com/https://github.com/langgenius/dify.git
synced 2025-08-12 18:19:11 +08:00
feat: support time format (#4138)
This commit is contained in:
parent
049abd698f
commit
e7fe7ec0f6
@ -17,11 +17,12 @@ class CurrentTimeTool(BuiltinTool):
|
|||||||
"""
|
"""
|
||||||
# get timezone
|
# get timezone
|
||||||
tz = tool_parameters.get('timezone', 'UTC')
|
tz = tool_parameters.get('timezone', 'UTC')
|
||||||
|
fm = tool_parameters.get('format') or '%Y-%m-%d %H:%M:%S %Z'
|
||||||
if tz == 'UTC':
|
if tz == 'UTC':
|
||||||
return self.create_text_message(f'{datetime.now(timezone.utc).strftime("%Y-%m-%d %H:%M:%S %Z")}')
|
return self.create_text_message(f'{datetime.now(timezone.utc).strftime(fm)}')
|
||||||
|
|
||||||
try:
|
try:
|
||||||
tz = pytz_timezone(tz)
|
tz = pytz_timezone(tz)
|
||||||
except:
|
except:
|
||||||
return self.create_text_message(f'Invalid timezone: {tz}')
|
return self.create_text_message(f'Invalid timezone: {tz}')
|
||||||
return self.create_text_message(f'{datetime.now(tz).strftime("%Y-%m-%d %H:%M:%S %Z")}')
|
return self.create_text_message(f'{datetime.now(tz).strftime(fm)}')
|
@ -12,6 +12,19 @@ description:
|
|||||||
pt_BR: A tool for getting the current time.
|
pt_BR: A tool for getting the current time.
|
||||||
llm: A tool for getting the current time.
|
llm: A tool for getting the current time.
|
||||||
parameters:
|
parameters:
|
||||||
|
- name: format
|
||||||
|
type: string
|
||||||
|
required: false
|
||||||
|
label:
|
||||||
|
en_US: Format
|
||||||
|
zh_Hans: 格式
|
||||||
|
pt_BR: Format
|
||||||
|
human_description:
|
||||||
|
en_US: Time format in strftime standard.
|
||||||
|
zh_Hans: strftime 标准的时间格式。
|
||||||
|
pt_BR: Time format in strftime standard.
|
||||||
|
form: form
|
||||||
|
default: "%Y-%m-%d %H:%M:%S"
|
||||||
- name: timezone
|
- name: timezone
|
||||||
type: select
|
type: select
|
||||||
required: false
|
required: false
|
||||||
|
Loading…
x
Reference in New Issue
Block a user