Skip to content

fix: add timezone conversion support to time tool#687

Open
tsubasakong wants to merge 2 commits intonearai:mainfrom
tsubasakong:fix/662-time-tool-timezones
Open

fix: add timezone conversion support to time tool#687
tsubasakong wants to merge 2 commits intonearai:mainfrom
tsubasakong:fix/662-time-tool-timezones

Conversation

@tsubasakong
Copy link

Summary

  • add explicit IANA timezone support to the builtin time tool
  • implement the missing convert and format operations
  • support naive timestamps when timezone / from_timezone is supplied, and fall back to JobContext.metadata.user_timezone when available
  • add focused tests for explicit timezone handling, context fallback, DST conversion, formatting, and invalid timezone errors

Validation

  • git diff --check
  • Rust toolchain is not installed on this host, so compile/test validation is deferred to CI

Fixes #662

@github-actions github-actions bot added scope: tool/builtin Built-in tools scope: dependencies Dependency updates size: L 200-499 changed lines risk: medium Business logic, config, or moderate-risk modules contributor: new First-time contributor labels Mar 7, 2026
@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request significantly upgrades the time built-in tool by integrating robust timezone awareness. It introduces the ability to convert timestamps between different IANA timezones, format them according to specified timezones and patterns, and intelligently handle naive timestamps by inferring timezone context. These enhancements provide greater flexibility and accuracy for time-related operations within the system.

Highlights

  • IANA Timezone Support: Added explicit support for IANA timezone names (e.g., 'America/New_York') across various time operations.
  • New Operations: Implemented new convert and format operations to allow direct timezone conversion and custom formatting of timestamps.
  • Naive Timestamp Handling: Enabled the tool to interpret naive timestamps (without timezone information) when an explicit timezone or from_timezone is provided, or by falling back to the JobContext.metadata.user_timezone.
  • Enhanced Parameter Schema: Updated the tool's parameter schema to include new fields like input, timezone, from_timezone, to_timezone, and format_string, while maintaining backward compatibility for existing timestamp and format parameters.
  • Comprehensive Testing: Added focused test cases to validate explicit timezone handling, context fallback mechanisms, Daylight Saving Time (DST) conversions, custom formatting, and proper error handling for invalid timezones.
Changelog
  • Cargo.toml
    • Added chrono-tz dependency to enable IANA timezone support.
  • src/tools/builtin/time.rs
    • Updated chrono imports and added chrono_tz::Tz for timezone types.
    • Expanded the tool's description to reflect new parsing and formatting capabilities.
    • Modified the parameters_schema to include convert operation, input, timezone, from_timezone, to_timezone, and format_string fields, while retaining timestamp and format for backward compatibility.
    • Refactored the execute function to delegate time operations to new, modular helper functions.
    • Implemented execute_now, execute_parse, execute_convert, execute_format, and execute_diff functions to encapsulate specific time logic.
    • Introduced utility functions such as require_input, resolve_parse_timezone, resolve_timezone_for_output, context_timezone, optional_timezone, parse_timezone, parse_timestamp, parse_naive_datetime, and localize_naive_datetime to manage input parsing and timezone resolution.
    • Added extensive unit tests covering explicit timezone usage, context-based timezone fallback, DST transitions, custom formatting, and error handling for unknown timezones.
Activity
  • The author performed git diff --check for local validation.
  • Rust toolchain compilation and testing validation are deferred to CI, indicating reliance on automated build and test pipelines.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request significantly enhances the time tool by adding comprehensive timezone support, implementing convert and format operations, and including a solid set of tests. The code is well-structured, with the core logic refactored into clear, focused functions. My review focuses on improving the consistency of the JSON output across the different time operations. By standardizing the fields returned, we can make the tool more predictable, easier to maintain for developers who will consume its output, and prevent client-side parsing failures.

let dt = parse_timestamp(input, parse_tz.as_ref())?;

Ok(serde_json::json!({
"iso": dt.to_rfc3339(),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The output of time operations is inconsistent across different operation values regarding the iso and utc_iso fields. For consistency with the now operation and to support a smoother transition, please return both iso (for backward compatibility) and the more explicit utc_iso field. This ensures a consistent and valid JSON structure, preventing potential client-side parsing failures.

Suggested change
"iso": dt.to_rfc3339(),
"iso": dt.to_rfc3339(),
"utc_iso": dt.to_rfc3339(),
References
  1. API endpoints should return a consistent and valid JSON structure to prevent client-side parsing failures and ensure predictability.


let mut result = serde_json::json!({
"input": input,
"utc_iso": dt.to_rfc3339(),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

This new convert operation only returns utc_iso. To maintain consistency with other operations like now and for backward compatibility with consumers that might expect an iso field, please add the iso field here as well, with the same value as utc_iso. This ensures a consistent and valid JSON structure, preventing potential client-side parsing failures.

Suggested change
"utc_iso": dt.to_rfc3339(),
"iso": dt.to_rfc3339(),
"utc_iso": dt.to_rfc3339(),
References
  1. API endpoints should return a consistent and valid JSON structure to prevent client-side parsing failures and ensure predictability.

})
};

result["utc_iso"] = serde_json::Value::String(dt.to_rfc3339());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Similar to other operations, this should return both iso and utc_iso for consistency. This helps in maintaining a uniform output structure across all time-related operations, ensuring a consistent and valid JSON structure and preventing potential client-side parsing failures.

Suggested change
result["utc_iso"] = serde_json::Value::String(dt.to_rfc3339());
result["iso"] = serde_json::Value::String(dt.to_rfc3339());
result["utc_iso"] = result["iso"].clone();
References
  1. API endpoints should return a consistent and valid JSON structure to prevent client-side parsing failures and ensure predictability.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

contributor: new First-time contributor risk: medium Business logic, config, or moderate-risk modules scope: dependencies Dependency updates scope: tool/builtin Built-in tools size: L 200-499 changed lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Fix time tool to support timezone conversion using session context

1 participant