Skip to main content
Glama

convert_time

Convert time between timezones using IANA names or system time, handling 24-hour format inputs for accurate timezone calculations.

Instructions

Convert time between timezones (defaults to system time for source/target)

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
source_timezoneYesSource timezone. Use 'system' or 'local' for user's local time (Etc/UTC), or IANA names like 'America/New_York', 'UTC'. System time is the most practical default.
target_timezoneYesTarget timezone. Use 'system' or 'local' for user's local time (Etc/UTC), or IANA names like 'Asia/Tokyo', 'UTC'. System time is the most practical default.
timeYesTime to convert in 24-hour format (HH:MM)

Implementation Reference

  • Core implementation of the convert_time tool in TimeServer class. Parses input time, handles timezone resolution including 'system'/'local', converts using pytz, computes time difference, and returns structured TimeConversionResult.
    def convert_time(
        self, source_tz: str, time_str: str, target_tz: str
    ) -> TimeConversionResult:
        """Convert time between timezones (defaults to system time)"""
        local_tz_name = str(get_local_tz())
        
        # Handle system/local timezone references
        actual_source_tz = source_tz
        if source_tz.lower() in ["system", "local"]:
            actual_source_tz = local_tz_name
        
        actual_target_tz = target_tz
        if target_tz.lower() in ["system", "local"]:
            actual_target_tz = local_tz_name
            
        source_timezone = get_zoneinfo(actual_source_tz)
        target_timezone = get_zoneinfo(actual_target_tz)
    
        try:
            parsed_time = datetime.strptime(time_str, "%H:%M").time()
        except ValueError:
            raise ValueError("Invalid time format. Expected HH:MM [24-hour format]")
    
        now = datetime.now(source_timezone)
        source_time = datetime(
            now.year,
            now.month,
            now.day,
            parsed_time.hour,
            parsed_time.minute,
            tzinfo=source_timezone,
        )
    
        target_time = source_time.astimezone(target_timezone)
        source_offset = source_time.utcoffset() or timedelta()
        target_offset = target_time.utcoffset() or timedelta()
        hours_difference = (target_offset - source_offset).total_seconds() / 3600
    
        if hours_difference.is_integer():
            time_diff_str = f"{hours_difference:+.1f}h"
        else:
            # For fractional hours like Nepal's UTC+5:45
            time_diff_str = f"{hours_difference:+.2f}".rstrip("0").rstrip(".") + "h"
    
        # Create formatted timezone displays
        source_formatted = source_time.strftime("%B %d, %Y at %I:%M:%S %p")
        target_formatted = target_time.strftime("%B %d, %Y at %I:%M:%S %p")
        
        if source_tz.lower() in ["system", "local"]:
            source_formatted += f" (System Time - {local_tz_name})"
            display_source_tz = f"System ({local_tz_name})"
        else:
            source_formatted += f" ({source_tz})"
            display_source_tz = source_tz
            
        if target_tz.lower() in ["system", "local"]:
            target_formatted += f" (System Time - {local_tz_name})"
            display_target_tz = f"System ({local_tz_name})"
        else:
            target_formatted += f" ({target_tz})"
            display_target_tz = target_tz
    
        return TimeConversionResult(
            source=TimeResult(
                timezone=display_source_tz,
                datetime=source_time.isoformat(timespec="seconds"),
                formatted_timezone=source_formatted,
                day_of_week=source_time.strftime("%A"),
                is_dst=bool(source_time.dst()),
            ),
            target=TimeResult(
                timezone=display_target_tz,
                datetime=target_time.isoformat(timespec="seconds"),
                formatted_timezone=target_formatted,
                day_of_week=target_time.strftime("%A"),
                is_dst=bool(target_time.dst()),
            ),
            time_difference=time_diff_str,
        )
  • MCP tool registration in list_tools(). Defines name, description, and input schema (source_timezone, time HH:MM, target_timezone).
    Tool(
        name=TimeTools.CONVERT_TIME.value,
        description="Convert time between timezones (defaults to system time for source/target)",
        inputSchema={
            "type": "object",
            "properties": {
                "source_timezone": {
                    "type": "string",
                    "description": f"Source timezone. Use 'system' or 'local' for user's local time ({local_tz}), or IANA names like 'America/New_York', 'UTC'. System time is the most practical default.",
                },
                "time": {
                    "type": "string",
                    "description": "Time to convert in 24-hour format (HH:MM)",
                },
                "target_timezone": {
                    "type": "string", 
                    "description": f"Target timezone. Use 'system' or 'local' for user's local time ({local_tz}), or IANA names like 'Asia/Tokyo', 'UTC'. System time is the most practical default.",
                },
            },
            "required": ["source_timezone", "time", "target_timezone"],
        },
    ),
    Tool(
  • Tool dispatch logic in _execute_tool(). Validates inputs using helper functions and calls the TimeServer.convert_time handler.
    case TimeTools.CONVERT_TIME.value:
        if not all(
            k in arguments
            for k in ["source_timezone", "time", "target_timezone"]
        ):
            raise ValueError("Missing required arguments")
    
        # Validate inputs with helpful error messages
        source_tz = validate_timezone(arguments["source_timezone"])
        target_tz = validate_timezone(arguments["target_timezone"])
        validated_time = validate_time_format(arguments["time"])
    
        result = time_server.convert_time(source_tz, validated_time, target_tz)
  • Pydantic model defining the output structure for convert_time: source/target TimeResult and time_difference.
    class TimeConversionResult(BaseModel):
        source: TimeResult
        target: TimeResult
        time_difference: str
  • Helper function to validate input time string format (HH:MM, 00:00-23:59), used in convert_time execution.
    def validate_time_format(time_str: str) -> str:
        """Validate time format and provide helpful error messages."""
        if not isinstance(time_str, str):
            raise ValueError("Time must be a string")
    
        # Check HH:MM format
        if not time_str or len(time_str) != 5 or time_str[2] != ':':
            raise ValueError(
                f"Invalid time format '{time_str}'. Expected 24-hour format HH:MM (00:00-23:59)"
            )
    
        try:
            hours, minutes = time_str.split(':')
            hours = int(hours)
            minutes = int(minutes)
    
            if not (0 <= hours <= 23):
                raise ValueError(f"Hours must be between 00-23, got {hours:02d}")
    
            if not (0 <= minutes <= 59):
                raise ValueError(f"Minutes must be between 00-59, got {minutes:02d}")
    
            return time_str
        except ValueError as e:
            if "too many values" in str(e) or "not enough values" in str(e):
                raise ValueError(
                    f"Invalid time format '{time_str}'. Expected HH:MM format (e.g., 14:30)"
                )
            raise
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations provided, the description carries the full burden of behavioral disclosure. It mentions default behaviors (system time defaults) but lacks critical details: it doesn't specify the output format (e.g., whether it returns a string, object, or includes date), error handling for invalid inputs, or any rate limits or authentication requirements. For a tool with no annotations, this is a significant gap.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is extremely concise and front-loaded, consisting of a single sentence that directly states the tool's purpose and key default behavior. Every word earns its place, with no redundant or verbose language, making it efficient and easy to parse.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness2/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the complexity of time conversion (3 required parameters, no output schema, and no annotations), the description is incomplete. It fails to explain the return value format, error conditions, or practical examples, leaving the agent with insufficient context to use the tool effectively without trial and error.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

The input schema has 100% description coverage, providing detailed parameter information (e.g., IANA timezone names, 24-hour format). The description adds minimal value beyond this, only reinforcing the default behavior mentioned in the schema. With high schema coverage, the baseline score of 3 is appropriate, as the description doesn't significantly enhance parameter understanding.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the tool's purpose: 'Convert time between timezones'. It specifies the verb ('convert') and resource ('time between timezones'), making the function unambiguous. However, it doesn't explicitly differentiate from sibling tools like 'get_current_time' or 'get_elapsed_time', which prevents a perfect score.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines3/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides some usage context by mentioning defaults ('defaults to system time for source/target'), which implies when to omit parameters. However, it doesn't offer explicit guidance on when to use this tool versus alternatives like 'get_current_time' for current time retrieval or 'get_elapsed_time' for duration calculations, leaving room for ambiguity.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/n0zer0d4y/chronos-protocol'

If you have feedback or need assistance with the MCP directory API, please join our Discord server