check_holiday
Determine if a specific date is a holiday in Taiwan by entering the date in YYYY-MM-DD or YYYYMMDD format.
Instructions
檢查指定日期是否為台灣假期
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| date | Yes | 要查詢的日期,支援格式:YYYY-MM-DD 或 YYYYMMDD |
Implementation Reference
- src/server.ts:75-91 (registration)Registration of the 'check_holiday' tool including its name, description, and input schema in the ListToolsRequestSchema handler.{ name: 'check_holiday', description: '檢查指定日期是否為台灣假期', inputSchema: { type: 'object', properties: { date: { type: 'string', description: '要查詢的日期,支援格式:YYYY-MM-DD 或 YYYYMMDD', pattern: '^(\\d{4}-\\d{2}-\\d{2}|\\d{8})$' } }, required: ['date'], additionalProperties: false, }, } as Tool, {
- src/server.ts:492-520 (handler)The main handler function for the 'check_holiday' tool, which extracts the date argument, calls the HolidayService, and formats the response.private async handleCheckHoliday(args: any) { const { date } = args; if (!date || typeof date !== 'string') { throw new Error('缺少必要參數:date'); } const holiday = await this.holidayService.checkHoliday(date); return { content: [ { type: 'text', text: JSON.stringify({ success: true, data: { date: date, isHoliday: holiday?.isHoliday || false, description: holiday?.description || '一般工作日', week: holiday?.week || '', normalizedDate: holiday?.date || '' }, timestamp: new Date().toISOString(), tool: 'check_holiday' }, null, 2), }, ], }; }
- src/holiday-service.ts:185-201 (handler)Core logic implementation in HolidayService that parses the date, fetches holidays for the year (using cache), and checks if the date matches any holiday.async checkHoliday(dateString: string): Promise<Holiday | null> { try { const parsedDate = parseDate(dateString); const holidays = await this.getHolidaysForYear(parsedDate.year); return holidays.find(holiday => holiday.date === parsedDate.normalized) || null; } catch (error) { if (error instanceof DateParseError) { throw new HolidayServiceError( `日期解析錯誤: ${error.message}`, error.type, error ); } throw error; } }
- src/server.ts:145-147 (registration)Registration of the tool handler in the switch statement of CallToolRequestSchema.case 'check_holiday': return await this.handleCheckHoliday(args);