Skip to content

OOPS-ORG-PHP/KASI-Lunar

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

28 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

KASI-Lunar

GitHub license

Solar/Lunar convert API with KASI(한국 천문 과학 연구원) data

Description

이 패키지는 한국천문연구원의 음양력 데이터를 기반으로 하여 양력/음열간의 변환을 제공하며, aero님의 Date-Korean-0.0.2 perl module을 PHP로 포팅한 것 입니다.

양력 기준으로 1391-02-05 부터 2050-12-31 까지의 기간만 가능하며, 절기, 합삭/망 정보, 세차/월간/일진등의 정보는 Lunar pear package를 이용하도록 합니다.

이 패키지는 Lunar pear package의 확장을 위하여 제작이 되었으며, 라이센스 문제로 Lunar pear package와 별도의 패키지로 제작이 되었습니다. (물론 독립적으로도 사용을 할 수 있습니다.)

License

GPLv2

Installation

[root@host ~]$ pear channel-discover pear.oops.org
Adding Channel "pear.oops.org" succeeded
Discovery of channel "pear.oops.org" succeeded
[root@host ~]$ pear install oops/Lunar

dependency

  • PHP >= 5.3.0
  • PHP extensions
    • calendar
  • Pear pakcages

Sample codes

<?php
/*
 * oops\KASI/Lunar API import
 */
require_once 'KASI_Lunar.php';

$lunar = new oops\KASI\Lunar;

$days = array (
    '1391-02-05',
    '1582-10-04',
    '1582-10-05',
    '1582-10-15',
    '1583-03-03', // not leap
    '1583-04-03', // leap
    '2050-12-31',
    '2051-12-31',
);

$ment = array (
    '유효범위 시작날자',
    '율리우스력 마지막 날자',
    '율리우스력과 그레고리력 사이의 존재하지 않는 날',
    '그레고리력 시작 날자',
    '윤달 체크(아님)',
    '윤달 체크(맞음)',
    '유효범위 마지막 날자',
    '유효범위 밖'
);

echo "-----------------------------------------------------------------------\n";

try {
    $i = 0;
    foreach ( $days as $day ) {
        $l = $lunar->tolunar ($day);

        $leap  = $l->leap ? 'true' : 'false';
        $lmoon = $l->lmoon ? 'true' : 'false';

        $s = $lunar->tosolar ($l->fmt, $l->leap);

        echo <<<EOF
지정 날자: $day - {$ment[$i++]}
음력 변환: {$l->fmt}, leap: {$leap}, LargeMoon: {$lmoon}
양력 변환: {$s->fmt} {$s->jd}
-----------------------------------------------------------------------

EOF;
    }
} catch ( Exception $e ) {
    echo $e->Message () . "\n";
    print_r ($e->TraceAsArray ()) . "\n";
    $e->finalize ();
}

?>