/** * Numerology Timing Cycles * * Calculates Personal and Universal timing cycles for planning and understanding * the energy of different time periods. */ const MASTER_NUMBERS = [11, 22, 33]; /** * Reduce number to single digit or master number */ function reduce(n: number): number { if (MASTER_NUMBERS.includes(n)) { return n; } const total = String(n).split('').reduce((sum, digit) => sum + parseInt(digit), 0); return total < 10 ? total : reduce(total); } /** * Parse date string (mm/dd/yyyy) */ function parseDate(dateStr: string): { month: number; day: number; year: number } { const parts = dateStr.split('/'); if (parts.length !== 3) { throw new Error('Invalid date format. Use mm/dd/yyyy'); } return { month: parseInt(parts[0]), day: parseInt(parts[1]), year: parseInt(parts[2]) }; } export interface CycleCalculations { targetDate: string; birthdate: string; universal: { year: number; month: number; day: number; }; personal: { year: number; month: number; day: number; }; calculations: { universalYearCalc: string; universalMonthCalc: string; universalDayCalc: string; personalYearCalc: string; personalMonthCalc: string; personalDayCalc: string; }; } /** * Calculate all timing cycles for a specific date */ export function calculateCycles(birthdate: string, targetDate?: string): CycleCalculations { // Use current date if not specified const target = targetDate || new Date().toLocaleDateString('en-US', { month: '2-digit', day: '2-digit', year: 'numeric' }).replace(/\//g, '/'); const birth = parseDate(birthdate); const current = parseDate(target); // Universal Cycles (based on calendar date only) const universalYear = reduce(current.year); const universalMonth = reduce(universalYear + current.month); const universalDay = reduce(universalMonth + current.day); // Personal Cycles (based on birthdate + current date) const birthMonth = reduce(birth.month); const birthDay = reduce(birth.day); // Personal Year = Birth Month + Birth Day + Current Year (all reduced) const personalYear = reduce(birthMonth + birthDay + reduce(current.year)); // Personal Month = Personal Year + Current Month const personalMonth = reduce(personalYear + current.month); // Personal Day = Personal Month + Current Day const personalDay = reduce(personalMonth + current.day); return { targetDate: target, birthdate, universal: { year: universalYear, month: universalMonth, day: universalDay }, personal: { year: personalYear, month: personalMonth, day: personalDay }, calculations: { universalYearCalc: `${current.year} → ${universalYear}`, universalMonthCalc: `UY(${universalYear}) + ${current.month} = ${universalMonth}`, universalDayCalc: `UM(${universalMonth}) + ${current.day} = ${universalDay}`, personalYearCalc: `BM(${birthMonth}) + BD(${birthDay}) + CY(${reduce(current.year)}) = ${personalYear}`, personalMonthCalc: `PY(${personalYear}) + ${current.month} = ${personalMonth}`, personalDayCalc: `PM(${personalMonth}) + ${current.day} = ${personalDay}` } }; } /** * Calculate Personal Year for entire year (Jan-Dec) */ export function calculateYearCycles(birthdate: string, year: number): Array<{month: number; personalMonth: number}> { const birth = parseDate(birthdate); const birthMonth = reduce(birth.month); const birthDay = reduce(birth.day); const personalYear = reduce(birthMonth + birthDay + reduce(year)); const months = []; for (let month = 1; month <= 12; month++) { const personalMonth = reduce(personalYear + month); months.push({ month, personalMonth }); } return months; } /** * Calculate Personal Day for entire month */ export function calculateMonthCycles( birthdate: string, year: number, month: number ): Array<{day: number; personalDay: number}> { const birth = parseDate(birthdate); const birthMonth = reduce(birth.month); const birthDay = reduce(birth.day); const personalYear = reduce(birthMonth + birthDay + reduce(year)); const personalMonth = reduce(personalYear + month); // Get days in month const daysInMonth = new Date(year, month, 0).getDate(); const days = []; for (let day = 1; day <= daysInMonth; day++) { const personalDay = reduce(personalMonth + day); days.push({ day, personalDay }); } return days; } /** * Find optimal days in a month based on desired energy */ export function findOptimalDays( birthdate: string, year: number, month: number, desiredNumber: number ): number[] { const days = calculateMonthCycles(birthdate, year, month); return days .filter(d => d.personalDay === desiredNumber) .map(d => d.day); } /** * Get cycle interpretation context */ export function getCycleContext(cycles: CycleCalculations): string { let context = `## Timing Cycles for ${cycles.targetDate}\n\n`; context += `**Universal Energy (Global):**\n`; context += `- Year: ${cycles.universal.year}\n`; context += `- Month: ${cycles.universal.month}\n`; context += `- Day: ${cycles.universal.day}\n\n`; context += `**Personal Energy (Your Rhythm):**\n`; context += `- Year: ${cycles.personal.year}\n`; context += `- Month: ${cycles.personal.month}\n`; context += `- Day: ${cycles.personal.day}\n\n`; context += `**Combined Interpretation:**\n`; context += `You are in a Personal Year ${cycles.personal.year} within a Universal Year ${cycles.universal.year}.\n`; context += `Your Personal Month ${cycles.personal.month} operates within Universal Month ${cycles.universal.month}.\n`; context += `Today's Personal Day ${cycles.personal.day} aligns with Universal Day ${cycles.universal.day}.\n`; return context; }