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.

feat: support time format (#4138)

Yeuolye7fe7ec0f65d
diff --git a/api/core/tools/provider/builtin/time/tools/current_time.py b/api/core/tools/provider/builtin/time/tools/current_time.py
index 8722274565c..90c01665e6e 100644
--- a/api/core/tools/provider/builtin/time/tools/current_time.py
+++ b/api/core/tools/provider/builtin/time/tools/current_time.py
@@ -17,11 +17,12 @@ class CurrentTimeTool(BuiltinTool):
"""
# get timezone
tz = tool_parameters.get('timezone', 'UTC')
+ fm = tool_parameters.get('format') or '%Y-%m-%d %H:%M:%S %Z'
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:
tz = pytz_timezone(tz)
except:
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")}')
\ No newline at end of file
+ return self.create_text_message(f'{datetime.now(tz).strftime(fm)}')
\ No newline at end of file
diff --git a/api/core/tools/provider/builtin/time/tools/current_time.yaml b/api/core/tools/provider/builtin/time/tools/current_time.yaml
index f0b5f53bd8f..d85d81ad54c 100644
--- a/api/core/tools/provider/builtin/time/tools/current_time.yaml
+++ b/api/core/tools/provider/builtin/time/tools/current_time.yaml
@@ -12,6 +12,19 @@ description:
pt_BR: A tool for getting the current time.
llm: A tool for getting the current time.
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
type: select
required: false