|
/** |
|
* Gist: Biorhythm Milestone Calculator |
|
* Description: Calculates current biorhythm cycles, tomorrow's outlook, |
|
* and identifies upcoming life-day milestones (every 100 and 1000 days). |
|
* Requirements: npm install luxon |
|
*/ |
|
|
|
import { DateTime } from 'luxon'; |
|
|
|
/** |
|
* Finds upcoming milestone days (e.g., every 100 or 1000 days) |
|
*/ |
|
function takeDates(startDay, divisor) { |
|
const milestones = []; |
|
let current = startDay; |
|
// Look for the next 11 milestones or up to a safety limit |
|
while (current < 42000 || milestones.length < 11) { |
|
if (current % divisor === 0) { |
|
milestones.push(current); |
|
} |
|
current++; |
|
} |
|
return milestones; |
|
} |
|
|
|
/** |
|
* Calculates biorhythm value (-1 to 1) for a specific cycle period |
|
*/ |
|
function getBiorhythm(daysAlive, period) { |
|
const phase = (daysAlive % period) / period * 2 * Math.PI; |
|
const y = Math.sin(phase); |
|
return y.toFixed(2); |
|
} |
|
|
|
/** |
|
* Main Logic |
|
*/ |
|
const birthDate = '1985-05-09'; |
|
const dtBirth = DateTime.fromISO(birthDate); |
|
const now = DateTime.local(); |
|
|
|
// Calculate total days alive |
|
const diff = now.diff(dtBirth, 'days'); |
|
const lifeDays = Math.floor(diff.days); |
|
|
|
console.info(`--- Biorhythm Report ---`); |
|
console.info(`Birth Date: ${dtBirth.toISODate()}`); |
|
console.info(`Days Alive: ${lifeDays}\n`); |
|
|
|
// 1. Calculate Milestones |
|
const hundreds = takeDates(lifeDays, 100); |
|
if (hundreds[0]) { |
|
// Use birth date as starting point for addition |
|
const nextMilestoneDate = dtBirth.plus({ days: hundreds[0] }); |
|
console.info(`Next 100-day Milestone: ${nextMilestoneDate.toISODate()} (Day ${hundreds[0]})`); |
|
} |
|
|
|
// 2. Today's Calculations |
|
const cycles = [ |
|
{ name: 'Emotional', period: 28 }, |
|
{ name: 'Physical', period: 23 }, |
|
{ name: 'Intellectual', period: 33 } |
|
]; |
|
|
|
console.info(`\n--- Today's Status ---`); |
|
const todayResults = cycles.map(cycle => { |
|
const val = getBiorhythm(lifeDays, cycle.period); |
|
const percent = ((1 + Number(val)) / 2 * 100).toFixed(2); |
|
console.info(`${cycle.name.padEnd(12)}: ${val} (${percent}%)`); |
|
return { ...cycle, today: val }; |
|
}); |
|
|
|
// 3. Tomorrow's Outlook & Changes |
|
console.info(`\n--- Tomorrow's Change ---`); |
|
todayResults.forEach(cycle => { |
|
const tomorrowVal = getBiorhythm(lifeDays + 1, cycle.period); |
|
const change = (Number(tomorrowVal) - Number(cycle.today)).toFixed(2); |
|
const direction = change > 0 ? '↗' : '↘'; |
|
console.info(`${cycle.name.padEnd(12)}: ${tomorrowVal} (Change: ${change} ${direction})`); |
|
}); |