get-day-of-week
Determine the day of the week for any date or today's date. Specify a locale to get localized day names in formats like YYYY-MM-DD.
Instructions
Returns the day of the week for a given date or today.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| date | No | Date in YYYY-MM-DD format (defaults to today) | |
| locale | No | Locale for day name (e.g., "en-US", "de-DE") |
Implementation Reference
- src/index.ts:57-84 (handler)The handler function implementing the 'get-day-of-week' tool. It parses an optional date (YYYY-MM-DD) or uses today, validates it, determines the day of the week using toLocaleDateString and getDay(), handles errors for invalid date or locale, and returns structured JSON content.async ({ date, locale = 'en-US' }) => { const targetDate = date ? new Date(date + 'T00:00:00') : new Date(); if (isNaN(targetDate.getTime())) { return { content: [{ type: 'text', text: 'Error: Invalid date format. Use YYYY-MM-DD.' }], isError: true }; } try { return { content: [{ type: 'text', text: JSON.stringify({ dayName: targetDate.toLocaleDateString(locale, { weekday: 'long' }), dayNumber: targetDate.getDay(), date: targetDate.toISOString().split('T')[0] }, null, 2) }] }; } catch { return { content: [{ type: 'text', text: `Error: Invalid locale "${locale}".` }], isError: true }; } }
- src/index.ts:49-56 (schema)Input schema for the 'get-day-of-week' tool using Zod, defining optional 'date' (YYYY-MM-DD) and 'locale' parameters with descriptions.{ title: 'Get Day of Week', description: 'Returns the day of the week for a given date or today.', inputSchema: { date: z.string().optional().describe('Date in YYYY-MM-DD format (defaults to today)'), locale: z.string().optional().describe('Locale for day name (e.g., "en-US", "de-DE")') } },
- src/index.ts:47-85 (registration)The server.registerTool call registering the 'get-day-of-week' tool with its name, schema, and handler function.server.registerTool( 'get-day-of-week', { title: 'Get Day of Week', description: 'Returns the day of the week for a given date or today.', inputSchema: { date: z.string().optional().describe('Date in YYYY-MM-DD format (defaults to today)'), locale: z.string().optional().describe('Locale for day name (e.g., "en-US", "de-DE")') } }, async ({ date, locale = 'en-US' }) => { const targetDate = date ? new Date(date + 'T00:00:00') : new Date(); if (isNaN(targetDate.getTime())) { return { content: [{ type: 'text', text: 'Error: Invalid date format. Use YYYY-MM-DD.' }], isError: true }; } try { return { content: [{ type: 'text', text: JSON.stringify({ dayName: targetDate.toLocaleDateString(locale, { weekday: 'long' }), dayNumber: targetDate.getDay(), date: targetDate.toISOString().split('T')[0] }, null, 2) }] }; } catch { return { content: [{ type: 'text', text: `Error: Invalid locale "${locale}".` }], isError: true }; } } );