Skip to main content
Glama
ainarsklavins

Date MCP Server

get-timezone-info

Retrieve timezone details including current or specified IANA timezone information for accurate temporal data handling.

Instructions

Returns information about the current or specified timezone.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
timezoneNoIANA timezone name (e.g., "America/New_York")

Implementation Reference

  • The asynchronous handler function implementing the core logic for the 'get-timezone-info' tool. It retrieves timezone offset, abbreviation, and current time using Intl.DateTimeFormat API, with error handling for invalid timezones.
    async ({ timezone }) => { const tz = timezone || Intl.DateTimeFormat().resolvedOptions().timeZone; const now = new Date(); try { const longFormatter = new Intl.DateTimeFormat('en-US', { timeZone: tz, timeZoneName: 'longOffset' }); const shortFormatter = new Intl.DateTimeFormat('en-US', { timeZone: tz, timeZoneName: 'short' }); const longParts = longFormatter.formatToParts(now); const shortParts = shortFormatter.formatToParts(now); const offset = longParts.find(p => p.type === 'timeZoneName')?.value || 'Unknown'; const abbreviation = shortParts.find(p => p.type === 'timeZoneName')?.value || 'Unknown'; return { content: [{ type: 'text', text: JSON.stringify({ timezone: tz, offset, abbreviation, currentTime: now.toLocaleString('en-US', { timeZone: tz }) }, null, 2) }] }; } catch { return { content: [{ type: 'text', text: `Error: Invalid timezone "${timezone}". Use IANA format.` }], isError: true }; } } );
  • The input schema definition for the tool, using Zod for validation. Defines an optional 'timezone' parameter.
    { title: 'Get Timezone Information', description: 'Returns information about the current or specified timezone.', inputSchema: { timezone: z.string().optional().describe('IANA timezone name (e.g., "America/New_York")') } },
  • src/index.ts:88-136 (registration)
    The registration of the 'get-timezone-info' tool using server.registerTool, including name, schema, and handler.
    server.registerTool( 'get-timezone-info', { title: 'Get Timezone Information', description: 'Returns information about the current or specified timezone.', inputSchema: { timezone: z.string().optional().describe('IANA timezone name (e.g., "America/New_York")') } }, async ({ timezone }) => { const tz = timezone || Intl.DateTimeFormat().resolvedOptions().timeZone; const now = new Date(); try { const longFormatter = new Intl.DateTimeFormat('en-US', { timeZone: tz, timeZoneName: 'longOffset' }); const shortFormatter = new Intl.DateTimeFormat('en-US', { timeZone: tz, timeZoneName: 'short' }); const longParts = longFormatter.formatToParts(now); const shortParts = shortFormatter.formatToParts(now); const offset = longParts.find(p => p.type === 'timeZoneName')?.value || 'Unknown'; const abbreviation = shortParts.find(p => p.type === 'timeZoneName')?.value || 'Unknown'; return { content: [{ type: 'text', text: JSON.stringify({ timezone: tz, offset, abbreviation, currentTime: now.toLocaleString('en-US', { timeZone: tz }) }, null, 2) }] }; } catch { return { content: [{ type: 'text', text: `Error: Invalid timezone "${timezone}". Use IANA format.` }], isError: true }; } } );

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/ainarsklavins/date-mcp'

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