Skip to content

Commit

Permalink
- 0.92 original cgi 버전의 버그 수정
Browse files Browse the repository at this point in the history
  - fixed typo in sydtoso24yd method
- 0.93 변경 사항 반영
  - 망(음력보름)시간 및 해당 보름날의 월식여부 추가
- 한국 천문 연구원의 절기 데이터 연동
  - KASI-Lunar 2.0.0 이상 필요
  - 2004 ~ 2026 사이의 절기 데이터를 한국 천문 연구권의 측정 값을 사용
  • Loading branch information
Joungkyun committed Aug 26, 2024
1 parent ac02f78 commit 1a43bab
Show file tree
Hide file tree
Showing 2 changed files with 110 additions and 41 deletions.
35 changes: 34 additions & 1 deletion Lunar.php
Original file line number Diff line number Diff line change
Expand Up @@ -1136,7 +1136,8 @@ public function seasondate ($v = null) {
$outgiday = $r->day;
}

return (object) array (
unset ($r);
$r = (object) array (
'center' => (object) array (
'name' => $this->month_st[$inginame],
'hname' => $this->hmonth_st[$inginame],
Expand Down Expand Up @@ -1171,6 +1172,38 @@ public function seasondate ($v = null) {
'julian' => $j_ne
)
);

# KASI-Lunar package 가 있으면, 한국 천문 연구원의 2004~2026년도 절기 데이터를
# 이용한다.
if ( class_exists ('oops\KASI\Lunar') ) {
if ( $this->KASI == null )
$this->KASI = new \oops\KASI\Lunar;

# KASI-Lunar > 2.0.0 부터 사용 가능하다.
# season method 가 없으면 진짜만세력 절기 데이터를 그냥 반환한다.
if ( ! method_exists ($this->KASI, 'season') )
return $r;

foreach ( $r as $k => $v ) {
$kv = $this->KASI->season ($r->{$k}->name, $r->{$k}->year);
if ( $kv != false ) {
$r->{$k}->month = $kv->month;
$r->{$k}->day = $kv->day;
$r->{$k}->hour = $kv->hour;
$r->{$k}->min = $kv->min;
$r->{$k}->julian = $this->to_utc_julian (
sprintf (
'%s %s:%s:00',
$this->regdate (array ($r->{$k}->year, $r->{$k}->month, $r->{$k}->day)),
$r->{$k}->hour < 10 ? '0' . $r->{$k}->hour : $r->{$k}->hour,
$r->{$k}->min < 10 ? '0' . $r->{$k}->min : $r->{$k}->min
)
);
}
}
}

return $r;
}
// }}}

Expand Down
116 changes: 76 additions & 40 deletions Lunar/Lunar_API.php
Original file line number Diff line number Diff line change
Expand Up @@ -200,8 +200,8 @@
*/
protected $ganji = array (
'갑자', '을축', '병인', '정묘', '무진', '기사', '경오', '신미', '임신', '계유', '갑술', '을해',
'병자', '정축', '무인', '기묘', '경진', '신사', '임오', '계미', '갑신', '을유', '병술', '정해',
'무자', '기축', '경인', '신묘', '임진', '계사', '갑오', '을미', '병신', '정유', '무술', '기해',
'병자', '정축', '무인', '기묘', '경진', '신사', '임오', '계미', '갑신', '을유', '병술', '정해',
'무자', '기축', '경인', '신묘', '임진', '계사', '갑오', '을미', '병신', '정유', '무술', '기해',
'경자', '신축', '임인', '계묘', '갑진', '을사', '병오', '정미', '무신', '기유', '경술', '신해',
'임자', '계축', '갑인', '을묘', '병진', '정사', '무오', '기미', '경신', '신유', '임술', '계해'
);
Expand Down Expand Up @@ -332,7 +332,30 @@ protected function disp2days ($y1, $m1, $d1, $y2, $m2, $d2) {
$ppp2 = $pp2 - 1;

for ( $k = $ppp1; $k <= $ppp2; $k++ ) {
if ( $k == -2000 && $ppp2 > 1990 ) {
# 0.93 diff {{{
if ( $k == -9000 && $ppp2 > 1990 ) {
$dis += 4014377;
$k = 1991;
} else if ( $k == -8000 && $ppp2 > 1990 ) {
$dis += 3649135;
$k = 1991;
} else if ( $k == -7000 && $ppp2 > 1990 ) {
$dis += 3283893;
$k = 1991;
} else if ( $k == -6000 && $ppp2 > 1990 ) {
$dis += 2918651;
$k = 1991;
} else if ( $k == -5000 && $ppp2 > 1990 ) {
$dis += 2553408;
$k = 1991;
} else if ( $k == -4000 && $ppp2 > 1990 ) {
$dis += 2188166;
$k = 1991;
} else if ( $k == -3000 && $ppp2 > 1990 ) {
$dis += 1822924;
$k = 1991;
# 0.93 diff }}}
} else if ( $k == -2000 && $ppp2 > 1990 ) {
$dis += 1457682;
$k = 1991;
} else if ( $k == -1750 && $ppp2 > 1990 ) {
Expand Down Expand Up @@ -396,7 +419,7 @@ protected function disp2days ($y1, $m1, $d1, $y2, $m2, $d2) {
// {{{ +-- protected (int) getminbytime ($uy, $umm, $ud, $uh, $umin, $y1, $mo1, $d1, $h1, $mm1)
/**
* uy,umm,ud,uh,umin과 y1,mo1,d1,h1,mm1사이의 시간(분)
*
*
* @access protected
* @return int 분
* @param int
Expand Down Expand Up @@ -436,7 +459,6 @@ function getminbytime ($uy, $umm, $ud, $uh, $umin, $y1, $mo1, $d1, $h1, $mm1) {
*/
protected function getdatebymin ($tmin, $uyear, $umonth, $uday, $uhour, $umin) {
$y1 = $mo1 = $d1 = $h1 = $mi1 = $t = 0;

$y1 = $uyear - $this->div ($tmin, 525949);

if ( $tmin > 0 ) {
Expand Down Expand Up @@ -483,7 +505,7 @@ protected function getdatebymin ($tmin, $uyear, $umonth, $uday, $uhour, $umin) {
$mo1--;
$d1 = 0;
do {
$d1 = $d1 + 1;
$d1++;
$t = $this->getminbytime ($uyear, $umonth, $uday, $uhour, $umin, $y1, $mo1, $d1, 0, 0);
} while ( $t >= $tmin );

Expand Down Expand Up @@ -521,7 +543,7 @@ protected function getdatebymin ($tmin, $uyear, $umonth, $uday, $uhour, $umin) {
* [4] => 20 // 60간지의 시 배열 index
* )
* </pre>
*
*
* @param int
* @param int
* @param int
Expand Down Expand Up @@ -564,20 +586,19 @@ protected function sydtoso24yd ($soloryear, $solormonth, $solorday, $solorhour,
$j = $i * 2;
if ( ($this->month[$j] <= $monthmin100) && ($monthmin100 < $this->month[$j+2]))
$so24month = $i;
};
}

// 월주 구하기
$i = $so24month;
$t = $so24year % 10 ;
$t %= 5 ;
$t = $t * 12 + 2 + $i;
$so24month = $t ;
if ( $so24month > 59 )
if ( $so24month > 59 )
$so24month -= 60;

$so24day = $displ2day % 60;

// 일주 구하기
$so24day = $displ2day % 60;
$so24day *= -1;
$so24day += 7;
if ( $so24day < 0 )
Expand Down Expand Up @@ -632,12 +653,11 @@ protected function sydtoso24yd ($soloryear, $solormonth, $solorday, $solorhour,
|| ($solorhour == 23 && $solormin < 30) )
$i = 11;

else if ( $solorhour == 23 && $solormin >= 30 )
{
else if ( $solorhour == 23 && $solormin >= 30 ) {
$so24day++;
if ( $so24day == 60 )
$so24day = 0;
$i=0;
$i = 0;
}

$t = $so24day % 10;
Expand Down Expand Up @@ -674,14 +694,15 @@ protected function solortoso24 ($soloryear, $solormonth, $solorday, $solorhour,
);

# 이거 고민좀 해 봐야 할 듯!!
# perl 과 php 의 음수의 나머지 결과값이 다르다! --;
#$monthmin100 = $displ2min % 525949;
#$monthmin100 = 525949 - $monthmin100;
$monthmin100 = ($displ2min % 525949) * -1;

if ( $monthmin100 < 0 )
$monthmin100 += 525949;
else if ( $monthmin100 >= 525949 )
$monthmin100 = $monthmin - 525949;
$monthmin100 -= 525949;

$i = $so24month % 12 - 2;
if ( $i == -2 ) $i = 10;
Expand Down Expand Up @@ -834,17 +855,17 @@ protected function getlunarfirst ($syear, $smonth, $sday) {
while ( $de > 13.5 ) {
$d--;
$de = $this->moonsundegree ($d);
};
}

while ( $de > 1 ) {
$d -= 0.04166666666;
$de = $this->moonsundegree ($d);
};
}

while ( $de < 359.99 ) {
$d -= 0.000694444;
$de = $this->moonsundegree ($d);
};
}

$d += 0.375;
$d *= 1440;
Expand All @@ -857,17 +878,17 @@ protected function getlunarfirst ($syear, $smonth, $sday) {
while ( $de < 346.5 ) {
$d++;
$de = $this->moonsundegree ($d);
};
}

while ( $de < 359 ) {
$d += 0.04166666666;
$de = $this->moonsundegree ($d);
};
}

while ( $de > 0.01 ) {
$d += 0.000694444;
$de = $this->moonsundegree ($d);
};
}

$pd = $d;
$d += 0.375;
Expand All @@ -882,46 +903,57 @@ protected function getlunarfirst ($syear, $smonth, $sday) {
$hour = $hour2;
$min = $min2;

# {{{ for 0.93 diff
$d = $pd + 26;

$de = $this->moonsundegree ($d);
while ( $de < 346.5) {
$de = $this->moonsundegree ($d);
while ( $de < 346.5 ) {
$d++;
$de = $this->moonsundegree ($d);
};
}
# 위의 라인 부분이 pascal(0.93) 버전에서는 아래와 같이 처리 되어 있음.
# 함수 반환 값의 차이가 없는 것으로 보아 성능 개선 코드일까?
#$d = $pd;
#while ( $de < 347 ) {
# $d++;
# $de = $this->moonsundegree ($d);
#}
# 0.93 diff }}}

while ( $de < 359 ) {
$d += 0.04166666666;
$de = $this->moonsundegree ($d);
};
}

while ( $de > 0.01 ) {
$d += 0.000694444;
$de = $this->moonsundegree ($d);
};
}

$d += 0.375;
$d *= 1440;
$i = (int) $d * -1;
list ($year2, $month2, $day2, $hour2, $min2) = $this->getdatebymin ($i, 1995, 12, 31, 0, 0);
};
}

# 음력 초하루
$d = $this->disp2days ($year, $month, $day, 1995, 12, 31);
# 음력 12월
$d += 12;

$de = $this->moonsundegree ($d);
while ( $de < 166.5 ) {
$d++;
$de = $this->moonsundegree ($d);
};
}
while ( $de < 179 ) {
$d += 0.04166666666;
$de = $this->moonsundegree ($d);
};
}
while ( $de < 179.999 ) {
$d += 0.000694444;
$de = $this->moonsundegree ($d);
};
}

$d += 0.375;
$d *= 1440;
Expand Down Expand Up @@ -963,12 +995,12 @@ protected function solartolunar ($solyear, $solmon, $solday) {
$y0, $mo0, $d0, $h0, $mi0, $y1, $mo1, $d1, $h1, $mi1)
= $this->getlunarfirst ($solyear, $solmon, $solday);

$lday = $this->disp2days ($solyear, $solmon, $solday, $smoyear, $smomonth, $smoday)+1;
$lday = $this->disp2days ($solyear, $solmon, $solday, $smoyear, $smomonth, $smoday) + 1;

$i=abs ($this->disp2days ($smoyear, $smomonth, $smoday, $y1, $mo1, $d1));
if ( $i==30 )
$i = abs ($this->disp2days ($smoyear, $smomonth, $smoday, $y1, $mo1, $d1));
if ( $i == 30 )
$largemonth = 1; # 대월
if ( $i==29 )
if ( $i == 29 )
$largemonth = 0; # 소월

list ($inginame, $ingiyear, $ingimonth, $ingiday, $ingihour, $ingimin,
Expand All @@ -978,7 +1010,7 @@ protected function solartolunar ($solyear, $solmon, $solday) {

$midname2 = $midname1 + 2;
if ( $midname2 > 24 )
$midname2=1;
$midname2 = 1;
$s0 = $this->month[$midname2] - $this->month[$midname1];
if ( $s0 < 0 )
$s0 += 525949;
Expand All @@ -996,11 +1028,11 @@ protected function solartolunar ($solyear, $solmon, $solday) {
$leap = 0;
} else {
if ( $smomonth < $midmonth2 && $midmonth2 < $mo1 ) {
$lmonth = ($midname2 - 1) /2 + 1;
$lmonth = ($midname2 - 1) / 2 + 1;
$leap = 0;
} else {
$lmonth = ($midname1 - 1) / 2 + 1;
$leap =1;
$leap = 1;
}
}
}
Expand Down Expand Up @@ -1031,9 +1063,9 @@ protected function solartolunar ($solyear, $solmon, $solday) {
if ( $lmonth == 0 ) {
$lyear--;
$lmonth = 12;
};
}
$leap = 0;
};
}
} else {
if ( $lmonth == $outgimonth ) {
$leap = 1;
Expand Down Expand Up @@ -1110,7 +1142,7 @@ protected function lunartosolar ($lyear, $lmonth, $lday, $leap = false) {
}
}
} else {
// ㅈ우기가 두번든 달의 전후
// 중기가 두번든 달의 전후
list ($lyear2, $lmonth2, $lday2, $lnp, $lnp2)
= $this->solartolunar ($year1, $month1, $day1);
if ( $lyear2 == $lyear && $lmonth == $lmonth2 ) {
Expand Down Expand Up @@ -1183,8 +1215,12 @@ protected function get28sday ($syear, $smonth, $sday) {
$d += 28;
}

# {{{ for 0.93 diff
# parscal(0.93) 버전에서는 이 2라인이 제거 되어 있음.
# 실행의 값은 차이가 없는데, 성능 개선인가?
if ( $d < 0 )
$d += 7;
# 0.93 diff }}}

$d -= 11;

Expand Down

0 comments on commit 1a43bab

Please sign in to comment.