UNPKG

@xzkcz/iztro-mcp-server

Version:

MCP server exposing iztro astrology methods for Zi Wei Dou Shu astrolabe generation and horoscope analysis

65 lines 2.38 kB
/** * Convert 24-hour format to Chinese timeIndex (0-12) * Based on traditional Chinese time periods (十二时辰) * @param hour - Hour in 24-hour format (0-23) * @returns timeIndex - Chinese hour index (0-12) */ export function hourToTimeIndex(hour) { if (hour < 0 || hour > 23 || !Number.isInteger(hour)) { throw new Error('Hour must be an integer between 0 and 23'); } // Chinese time periods mapping (十二时辰) with early/late Zi distinction: // 早子时 (Early Zi): 00:00-01:00 -> timeIndex 0 // 丑时 (Chou): 01:00-03:00 -> timeIndex 1 // 寅时 (Yin): 03:00-05:00 -> timeIndex 2 // 卯时 (Mao): 05:00-07:00 -> timeIndex 3 // 辰时 (Chen): 07:00-09:00 -> timeIndex 4 // 巳时 (Si): 09:00-11:00 -> timeIndex 5 // 午时 (Wu): 11:00-13:00 -> timeIndex 6 // 未时 (Wei): 13:00-15:00 -> timeIndex 7 // 申时 (Shen): 15:00-17:00 -> timeIndex 8 // 酉时 (You): 17:00-19:00 -> timeIndex 9 // 戌时 (Xu): 19:00-21:00 -> timeIndex 10 // 亥时 (Hai): 21:00-23:00 -> timeIndex 11 // 晚子时 (Late Zi): 23:00-00:00 -> timeIndex 12 if (hour >= 0 && hour < 1) { return 0; // 早子时 (Early Zi) - 00:00-01:00 } else if (hour >= 1 && hour < 3) { return 1; // 丑时 (Chou) - 01:00-03:00 } else if (hour >= 3 && hour < 5) { return 2; // 寅时 (Yin) - 03:00-05:00 } else if (hour >= 5 && hour < 7) { return 3; // 卯时 (Mao) - 05:00-07:00 } else if (hour >= 7 && hour < 9) { return 4; // 辰时 (Chen) - 07:00-09:00 } else if (hour >= 9 && hour < 11) { return 5; // 巳时 (Si) - 09:00-11:00 } else if (hour >= 11 && hour < 13) { return 6; // 午时 (Wu) - 11:00-13:00 } else if (hour >= 13 && hour < 15) { return 7; // 未时 (Wei) - 13:00-15:00 } else if (hour >= 15 && hour < 17) { return 8; // 申时 (Shen) - 15:00-17:00 } else if (hour >= 17 && hour < 19) { return 9; // 酉时 (You) - 17:00-19:00 } else if (hour >= 19 && hour < 21) { return 10; // 戌时 (Xu) - 19:00-21:00 } else if (hour >= 21 && hour < 23) { return 11; // 亥时 (Hai) - 21:00-23:00 } else { // hour == 23 return 12; // 晚子时 (Late Zi) - 23:00-00:00 } } //# sourceMappingURL=hourToTimeIndex.js.map