get_local_time
Retrieve precise local time for any IANA timezone using NTP consensus. Compensates for latency to ensure accuracy.
Instructions
Get current time for a specific IANA timezone with high accuracy.
Uses NTP consensus for accurate UTC time, then converts to the requested
timezone using IANA tzdata. This provides authoritative local time independent
of system clock accuracy.
Args:
timezone: IANA timezone identifier (e.g., "America/New_York", "Europe/London")
mode: Accuracy mode - "fast" or "accurate"
compensate_latency: If True, add query duration to timestamp (default: True)
Returns:
LocalTimeResponse with local time and timezone metadataInput Schema
| Name | Required | Description | Default |
|---|---|---|---|
| timezone | Yes | ||
| mode | No | fast | |
| compensate_latency | No |
Implementation Reference
- src/chuk_mcp_time/server.py:223-267 (handler)Main handler function for get_local_time tool. Uses NTP consensus for accurate UTC time, then converts to the requested IANA timezone using zoneinfo.
@tool # type: ignore[arg-type] async def get_local_time( timezone: str, mode: AccuracyMode = AccuracyMode.FAST, compensate_latency: bool = True, ) -> LocalTimeResponse: """Get current time for a specific IANA timezone with high accuracy. Uses NTP consensus for accurate UTC time, then converts to the requested timezone using IANA tzdata. This provides authoritative local time independent of system clock accuracy. Args: timezone: IANA timezone identifier (e.g., "America/New_York", "Europe/London") mode: Accuracy mode - "fast" or "accurate" compensate_latency: If True, add query duration to timestamp (default: True) Returns: LocalTimeResponse with local time and timezone metadata """ # Get accurate UTC time time_response = await get_time_utc(mode=mode, compensate_latency=compensate_latency) # type: ignore[misc] # Convert to local timezone utc_timestamp = time_response.epoch_ms / 1000.0 utc_dt = datetime.fromtimestamp(utc_timestamp, tz=UTC) # Get timezone info tz_info = get_timezone_info_at_datetime(timezone, utc_dt) # Apply timezone from zoneinfo import ZoneInfo local_dt = utc_dt.astimezone(ZoneInfo(timezone)) return LocalTimeResponse( local_datetime=local_dt.isoformat(), timezone=timezone, utc_offset_seconds=tz_info.utc_offset_seconds, is_dst=tz_info.is_dst, abbreviation=tz_info.abbreviation, source_utc=time_response.iso8601_time, tzdata_version=get_tzdata_version(), estimated_error_ms=time_response.estimated_error_ms, ) - src/chuk_mcp_time/models.py:129-139 (schema)LocalTimeResponse Pydantic model - the response schema for get_local_time tool.
class LocalTimeResponse(BaseModel): """Response for get_local_time tool.""" local_datetime: str = Field(description="Local time in ISO 8601 format with timezone") timezone: str = Field(description="IANA timezone identifier") utc_offset_seconds: int = Field(description="UTC offset in seconds") is_dst: bool = Field(description="Whether daylight saving time is active") abbreviation: str = Field(description="Timezone abbreviation (e.g., EST, BST)") source_utc: str = Field(description="Source UTC time from consensus") tzdata_version: str = Field(description="IANA tzdata version") estimated_error_ms: float = Field(description="Estimated error from UTC consensus") - src/chuk_mcp_time/__init__.py:5-26 (registration)Registration of get_local_time in the public API (exported from __init__.py).
from chuk_mcp_time.server import ( compare_system_clock, convert_time, get_local_time, get_time_for_timezone, get_time_utc, get_timezone_info, list_timezones, main, ) __all__ = [ "get_time_utc", "get_time_for_timezone", "get_local_time", "compare_system_clock", "convert_time", "list_timezones", "get_timezone_info", "main", "__version__", ] - src/chuk_mcp_time/__init__.py:16-19 (registration)Registration of get_local_time in __all__ list.
__all__ = [ "get_time_utc", "get_time_for_timezone", "get_local_time",