Get Timezone Information
get-timezone-infoRetrieve timezone details including current or specified IANA timezone information for accurate temporal data handling.
Instructions
Returns information about the current or specified timezone.
Tool call template
This tool declares no required parameters. Add optional parameters from the input schema as needed.
{
"id": 1,
"jsonrpc": "2.0",
"method": "tools/call",
"params": {
"arguments": {},
"name": "get-timezone-info"
}
}Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| timezone | No | IANA timezone name (e.g., "America/New_York") |
Implementation Reference
- src/index.ts:97-135 (handler)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 }; } } ); - src/index.ts:90-96 (schema)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 }; } } );