From 275bcfb65866a25334909393ebeaa2ed32827055 Mon Sep 17 00:00:00 2001
From: Xing Ji <41811005+micsama@users.noreply.github.com>
Date: Sat, 14 Mar 2026 00:40:03 +0800
Subject: [PATCH] fix(time): treat empty timezone string as absent (#1127)
LLMs sometimes pass "" for optional parameters instead of omitting
them. Previously, passing timezone: "" or from_timezone: "" to the
time tool would trigger a parse error ("Unknown timezone ''") rather
than falling back to the context timezone or UTC.
Fix by adding .filter(|s| !s.is_empty()) after .as_str() in
resolve_timezone_for_output and optional_timezone, so empty strings
are treated the same as a missing field.
The same pattern exists in routine.rs (cron trigger timezone and
schedule fields), where "" produces "invalid IANA timezone: ''" or a
cron parse error. That will be addressed separately once routine.rs
has a test harness in place.
Regression tests added for the now and convert operations with
empty timezone strings.
Closes #1127
---
src/tools/builtin/time.rs | 56 +++++++++++++++++++++++++++++++++++++--
1 file changed, 54 insertions(+), 2 deletions(-)
diff --git a/src/tools/builtin/time.rs b/src/tools/builtin/time.rs
index bafbd4d7..5f037964 100644
--- a/src/tools/builtin/time.rs
+++ b/src/tools/builtin/time.rs
@@ -247,7 +247,11 @@ fn resolve_timezone_for_output(
params: &serde_json::Value,
ctx: &JobContext,
) -> Result