Skip to content

Conversation

@hariprasad-t
Copy link

Fix local timezone detection for non-IANA timezone abbreviations

Description

This PR fixes an issue where the get_local_tz function fails when encountering timezone abbreviations like IST (Indian Standard Time) that don't directly map to IANA timezone names. The implementation now includes a fallback mechanism that maps UTC offsets to appropriate IANA timezone names when direct conversion fails.

Server Details

  • Server: mcp_server_time
  • Changes to: modified timezone detection functionality

Motivation and Context

The current implementation attempts to convert local timezone information directly to an IANA timezone name, which works for many cases but fails for certain abbreviations (like IST). This causes the server to fail when running in environments using these timezones. By implementing a fallback mechanism based on UTC offset, we ensure the server works consistently across all timezone environments.

How Has This Been Tested?

  • Tested on systems with IST (Indian Standard Time) as local timezone
  • Verified time conversion works correctly with the new implementation
  • Confirmed behavior is unchanged for systems with standard IANA timezone names

Breaking Changes

No breaking changes.

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Documentation update

Checklist

  • I have read the MCP Protocol Documentation
  • My changes follows MCP security best practices
  • I have updated the server's README accordingly
  • I have tested this with an LLM client
  • My code follows the repository's style guidelines
  • New and existing tests pass locally
  • I have added appropriate error handling
  • I have documented all environment variables and configuration options

Additional context

Fix local timezone detection for non-IANA timezone abbreviations
try:
# Try to get the IANA timezone name directly
return ZoneInfo(str(tzinfo))
except Exception:

Choose a reason for hiding this comment

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

I don't think you can just swallow an Exception here and assume you can just parse something other than tzinfo a different way...

@olaservo olaservo added server-time Reference implementation for the Time MCP server - src/time bug Something isn't working labels Apr 18, 2025
@domdomegg
Copy link
Member

Thanks for your contribution! This looks like a duplicate of #1761. We're tracking this there, so I'm going to close this one to keep the discussion consolidated. Feel free to add any additional context or thoughts to the original issue if you have them!

@domdomegg domdomegg closed this Aug 15, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working server-time Reference implementation for the Time MCP server - src/time

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants