Index of: /package/Lunar/

File Name  ↓ File Size  ↓ Date  ↓ 
--
16.0 KiB2013-Jul-19 16:39
16.7 KiB2014-Jan-25 17:52
16.8 KiB2015-Jun-09 03:16
17.8 KiB2015-Dec-07 23:41
232 B2015-Dec-07 23:44

Lunar pear package

Lunar package는 고영창님의 진짜 만세력을 PHP로 포팅하여 개선한 것으로, 양력/음력 간의 변환을 제공합니다.

1852년 10월 15일 이전의 양력 날자는 율리우스력으로 취급을 하며, 내부 계산시에 그레고리력으로 변환을 하여 계산을 합니다.

2.0 부터는 oops/KASI_Lunar package가 설치되어 있고, 코드에서 KASI_Lunar.php를 Lunar.php보다 먼저 include 를 하면, 1391-02-05 ~ 2050-12-31 까지의 기간은 한국천문연구원의 음양력 DB를 이용하여 처리 합니다. (속도도 훨씬 빠릅니다.)

또한, 2.0 부터는 namespace oops가 추가되어, 선언시에, "new oops\Lunar;" 와 같이 선언해야 합니다.

이 패키지가 제공하는 기능은 다음과 같습니다.

  1. 양력/음력 변환 API
  2. 절기 API
  3. 합삭/막 정보 API
  4. 세차/월간/일진 API 등

이 변환 API의 유효기간은 다음과 같습니다.

  • 32bit
    • -2087-02-09(음력 -2087-01-01) ~ 6078-01-29(음 6077-12-29)
    • -2087-07-05(음력 -2087-05-29) 이전은 계산이 무지 느려짐..
  • 64bit
    • -4712-02-08 ~ 9999-12-31
    • API의 연도 체크가 4자리 까지이므로 10000년 이상은 확인 못함
    • 64bit 계산이 가능한 시점까지 가능할 듯..
    • 기원전의 경우 Julian date가 BC 4713년 1월 1일 부터이므로 Gregorian calendar 변환이 가능한 BC 4713년 2월 8일부터 가능

계산 처리 시간상, 과거 2000년전과 미래 100년후의 시간은 왠만하면 웹에서는 사용하는 것을 권장하지 않음!

Reference: Example:
<?php
/*
 * Test code for pear_Lunar
 * $Id: test.php 19 2013-07-15 17:15:37Z oops $
 */

// 한국 천문 연구원의 DB를 사용하기 위해서
// oops/KASI_Lunar pear package가 설치 되어 있어야 한다.
require_once 'KASI_Lunar.php';
 
/*
 * Lunar API import
 */
require_once 'Lunar.php';
 
 
$target = $argv[1] ? $argv[1] : date ('Ymd', time ());
 
$lunar = new oops\Lunar;
 
$target = $argv[1];
$lunar->toargs ($target);
 
echo "**\n";
printf ("** target date is %s\n", $target);
echo "**\n";
echo "\n";
 
# 1일의 음력 정보
$z = $lunar->tolunar ($target);
# 이번달의 세차/월간/일진 정보
$tune = $lunar->dayfortune ($target);
# 1일의 음력월에 대한 합삭/망 정보
$moon = $lunar->moonstatus ($target);
# 1일의 28수 정보
$s28  = $lunar->s28day ($target);
# 이번달의 절기 정보
$season = $lunar->seasondate ($target);
 
$yoon = $z->moonyoon ? ', 윤달' : '';
$bmon = $z->largemonth ? '큰달' : '평달';
 
echo <<<EOF
-- 음력 변환 --------------------------------
 
날자   {$z->date} {$z->week} ({$z->hweek})
연     {$z->year}
월     {$z->month} ($bmon$yoon) {$tune->month}({$tune->hmonth})월
일     {$z->day} {$tune->day}({$tune->hday})일
간지   {$z->ganji} ({$z->hganji}) ({$tune->year})
띠     {$z->ddi}
28수   {$s28->k} ({$s28->h})
 
합삭 (New Moon)   {$moon->new->year}년 {$moon->new->month}월 {$moon->new->day}일 {$moon->new->hour}시 {$moon->new->min}분
망   (Full Moon)  {$moon->full->year}년 {$moon->full->month}월 {$moon->full->day}일 {$moon->full->hour}시 {$moon->full->min}분
 
 
EOF;
 
foreach ( $season as $v )
    printf ("%s(%s) %d년 %d월 %d일\n", $v->name, $v->hname, $v->year, $v->month, $v->day);
 
 
$z = $lunar->tosolar ($z->date, $z->moonyoon);
 
echo <<<EOF
 
-- 양력 재변환 ------------------------------
날자   {$z->date} {$z->week} ({$z->hweek})
연     {$z->year}
월     {$z->month}
일     {$z->day}
간지   {$z->ganji} ({$z->hganji})
띠     {$z->ddi}
 
EOF;
 
/*
 * Local variables:
 * tab-width: 4
 * c-basic-offset: 4
 * End:
 * vim: set filetype=php noet sw=4 ts=4 fdm=marker:
 * vim600: noet sw=4 ts=4 fdm=marker
 * vim<600: noet sw=4 ts=4
 */
?>
Installation:
shell> pear channel-discover pear.oops.org
shell> pear install oops/Lunar
shell> pear list -a