<?php
header('Content-Type: text/plain; charset=utf-8');

$jd = gregoriantojd(6, 21, 2026);
echo "2026-06-21 Julian Day: $jd\n";
echo "Day TG index: " . (($jd + 9) % 10) . " (0=甲 1=乙 2=丙 3=丁 4=戊 5=己 6=庚 7=辛 8=壬 9=癸)\n";
echo "Day DZ index: " . (($jd + 1) % 12) . " (0=子 1=丑 2=寅 3=卯 4=辰 5=巳 6=午 7=未 8=申 9=酉 10=戌 11=亥)\n";

$tg = ['甲','乙','丙','丁','戊','己','庚','辛','壬','癸'];
$dz = ['子','丑','寅','卯','辰','巳','午','未','申','酉','戌','亥'];

$day_tg = $tg[($jd + 9) % 10];
$day_dz = $dz[($jd + 1) % 12];
echo "Day pillar: $day_tg$day_dz (expected: 丙寅)\n";

$y = 2026;
$m = 6;
$month_dz_index = ($m + 1) % 12;
$month_tg_index = ($y % 5 * 2 + $m + 3) % 10;
echo "\nCurrent month pillar calculation:\n";
echo "Month DZ index: $month_dz_index => " . $dz[$month_dz_index] . " (expected: 午=6)\n";
echo "Month TG index: $month_tg_index => " . $tg[$month_tg_index] . " (expected: 甲=0)\n";
echo "Current result: " . $tg[$month_tg_index] . $dz[$month_dz_index] . "月 (expected: 甲午月)\n";

echo "\n--- Correct month pillar algorithm ---\n";
$year_tg_index = ($y - 4) % 10;
echo "Year TG index: $year_tg_index => " . $tg[$year_tg_index] . "\n";

$lunar_month = 5;
$month_branch = $lunar_month + 1;
echo "Lunar month 5 => branch index: $month_branch => " . $dz[$month_branch] . "\n";

$month_tg_correct = ($year_tg_index % 5 * 2 + $month_branch) % 10;
echo "Correct month TG index: $month_tg_correct => " . $tg[$month_tg_correct] . "\n";
echo "Correct month pillar: " . $tg[$month_tg_correct] . $dz[$month_branch] . "月\n";

echo "\n--- Test multiple dates ---\n";
$test_dates = [
    ['2026-06-21', '丙午年', '甲午月', '丙寅日'],
    ['2024-02-10', '甲辰年', '丙寅月', '甲辰日'],
    ['2025-01-29', '乙巳年', '丁丑月', '己酉日'],
];
