oops-Lunar
[ class tree: oops-Lunar ] [ index: oops-Lunar ] [ all elements ]

Source for file Lunar.php

Documentation is available at Lunar.php

  1. <?php
  2. /**
  3.  * Project: Lunar :: 양력/음력 변환 클래스<br>
  4.  * File:    Lunar.php
  5.  *
  6.  * 이 패키지는 양력/음력간의 변환을 제공한다.
  7.  *
  8.  * 1852년 10월 15일 이전의 양력 날자는 율리우스력으로 취급을 하며, 내부
  9.  * 계산시에 그레고리력으로 변환을 하여 계산을 한다.
  10.  *
  11.  * 제공 되는 기능은 다음과 같다.
  12.  *
  13.  * 1. 양력/음력 변환 API
  14.  * 2. 절기 API
  15.  * 3. 합삭/막 정보 API
  16.  * 4. 세차/월간/일진 API 등
  17.  *
  18.  * 이 변환 API의 유효기간은 다음과 같다.
  19.  *
  20.  * <pre>
  21.  *   * 32bit
  22.  *     + -2087-02-09(음력 -2087-01-01) ~ 6078-01-29(음 6077-12-29)
  23.  *     + -2087-07-05(음력 -2087-05-29) 이전은 계산이 무지 느려짐..
  24.  *
  25.  *   * 64bit
  26.  *     + -4712-02-08 ~ 9999-12-31
  27.  *     + API의 연도 체크가 4자리 까지이므로 10000년 이상은 확인 못함
  28.  *     + 64bit 계산이 가능한 시점까지 가능할 듯..
  29.  *     + 기원전의 경우 Julian date가 BC 4713년 1월 1일 부터이므로
  30.  *       Gregorian calendar 변환이 가능한 BC 4713년 2월 8일부터 가능
  31.  * </pre>
  32.  *
  33.  * 계산 처리 시간상, 과거 2000년전과 미래 100년후의 시간은 왠만하면 웹에서는
  34.  * 사용하는 것을 권장하지 않음!
  35.  *
  36.  * 참고!
  37.  *
  38.  * oops\KASI_Lunar pear package를 설치한 후에, KASI_Lunar.php 를 include 하면,
  39.  * 내부적으로 1391-02-05 ~ 2050-12-31 기간은 한국천문연구원의 음양력 DB를 이용하여
  40.  * 처리를 한다.
  41.  *
  42.  * 주의!
  43.  *
  44.  * Lunar package는 2가지 라이센스를 가지고 있다. Lunar 패키지의
  45.  * Core API (Lunar/Lunar_API.php)는 고영창님의 '진짜만세력' 코드를 PHP로
  46.  * 포팅한 것으로, 고영창님에게 라이센스가 있으며, front end API(Lunar.php)는
  47.  * 김정균이 작성한 코드들로 BSD license를 따른다.
  48.  *
  49.  * @category    Calendar
  50.  * @package     oops\Lunar
  51.  * @author      JoungKyun.Kim <http://oops.org>
  52.  * @copyright   (c) 2018, OOPS.org
  53.  * @license     BSD (Lunar.php) And 고영창(Lunar/Lunar_API.php)
  54.  * @link        http://pear.oops.org/package/Lunar
  55.  * @since       File available since release 0.0.1
  56.  * @example     Lunar/tests/test.php Sample code
  57.  * @filesource
  58.  */
  59.  
  60. /**
  61.  * Namespace oops
  62.  */
  63. namespace oops;
  64.  
  65. /**
  66.  * import myException class
  67.  */
  68. require_once 'myException.php';
  69. set_error_handler('myException::myErrorHandler');
  70.  
  71.  
  72. /**
  73.  * import Lunar API
  74.  */
  75. require_once 'Lunar/Lunar_API.php';
  76.  
  77. /**
  78.  * 양력/음력 변환 클래스
  79.  *
  80.  * 이 패키지는 양력/음력간의 변환을 제공한다.
  81.  *
  82.  * 1852년 10월 15일 이전의 양력 날자는 율리우스력으로 취급을 하며, 내부
  83.  * 계산시에 그레고리력으로 변환을 하여 계산을 한다.
  84.  *
  85.  * 제공 되는 기능은 다음과 같다.
  86.  *
  87.  * 1. 양력/음력 변환 API
  88.  * 2. 절기 API
  89.  * 3. 합삭/막 정보 API
  90.  * 4. 세차/월간/일진 API 등
  91.  *
  92.  * 이 변환 API의 유효기간은 다음과 같다.
  93.  *
  94.  * <pre>
  95.  *   * 32bit
  96.  *     + -2087-02-09(음력 -2087-01-01) ~ 6078-01-29(음 6077-12-29)
  97.  *     + -2087-07-05(음력 -2087-05-29) 이전은 계산이 무지 느려짐..
  98.  *
  99.  *   * 64bit
  100.  *     + -4712-02-08 ~ 9999-12-31
  101.  *     + API의 연도 체크가 4자리 까지이므로 10000년 이상은 확인 못함
  102.  *     + 64bit 계산이 가능한 시점까지 가능할 듯..
  103.  *     + 기원전의 경우 Julian date가 BC 4713년 1월 1일 부터이므로
  104.  *       Gregorian calendar 변환이 가능한 BC 4713년 2월 8일부터 가능
  105.  * </pre>
  106.  *
  107.  * 계산 처리 시간상, 과거 2000년전과 미래 100년후의 시간은 왠만하면 웹에서는
  108.  * 사용하는 것을 권장하지 않음!
  109.  *
  110.  * 참고!
  111.  *
  112.  * oops\KASI_Lunar pear package를 설치한 후에, KASI_Lunar.php 를 include 하면,
  113.  * 내부적으로 1391-02-05 ~ 2050-12-31 기간은 한국천문연구원의 음양력 DB를 이용하여
  114.  * 처리를 한다.
  115.  *
  116.  * @package     oops\Lunar
  117.  * @author      JoungKyun.Kim <http://oops.org>
  118.  * @copyright   (c) 2018, OOPS.org
  119.  * @license     BSD (Lunar.php) And 고영창(Lunar/Lunar_API.php)
  120.  * @example     Lunar/tests/test.php Sample code
  121.  */
  122. Class Lunar extends Lunar_API {
  123.     private $KASI null;
  124.  
  125.     // {{{ +-- public (array) toargs ($v, $lunar = fasle)
  126.     /**
  127.      * 입력된 날자 형식을 연/월/일의 멤버를 가지는 배열로 반환한다.
  128.      * 입력된 변수 값은 YYYY-MM-DD 형식으로 변환 된다.
  129.      *
  130.      * 예제:
  131.      * {@example Lunar/tests/sample.php 30 25}
  132.      *
  133.      * @access public
  134.      * @return array 
  135.      *    <pre>
  136.      *        Array
  137.      *        (
  138.      *            [0] => 2013
  139.      *            [1] => 7
  140.      *            [2] => 16
  141.      *        )
  142.      *    </pre>
  143.      * @param string|int날자형식
  144.      *
  145.      *    - unixstmap (1970년 12월 15일 이후부터 가능)
  146.      *    - Ymd or Y-m-d
  147.      *    - null data (현재 시간)
  148.      */
  149.     public function toargs (&$v$lunar false{
  150.         if $v == null {
  151.             $y = (int) date ('Y');
  152.             $m = (int) date ('m');
  153.             $d = (int) date ('d');
  154.         else {
  155.             if is_numeric ($v&& $v 30000000 {
  156.                 // unit stamp ?
  157.                 $y = (int) date ('Y'$v);
  158.                 $m = (int) date ('m'$v);
  159.                 $d = (int) date ('d'$v);
  160.             else {
  161.                 if preg_match ('/^(-?[0-9]{1,4})[\/-]?([0-9]{1,2})[\/-]?([0-9]{1,2})$/'trim ($v)$match) ) {
  162.                     array_shift ($match);
  163.                     list ($y$m$d$match;
  164.                 else {
  165.                     throw new \myException ('Invalid Date Format'E_USER_WARNING);
  166.                     return false;
  167.                 }
  168.             }
  169.  
  170.             // 넘어온 날자가 음력일 경우 아래가 실행되면 측정 날자가 달라질 수 있다.
  171.             if $lunar && $y 1969 && $y 2038 {
  172.                 $fixed mktime (000$m$d$y);
  173.                 $y = (int) date ('Y'$fixed);
  174.                 $m = (int) date ('m'$fixed);
  175.                 $d = (int) date ('d'$fixed);
  176.             else {
  177.                 if $m 12 || $d 31 {
  178.                     throw new \myException ('Invalid Date Format'E_USER_WARNING);
  179.                     return false;
  180.                 }
  181.             }
  182.         }
  183.         $v $this->regdate (array ($y$m$d));
  184.  
  185.         return array ($y$m$d);
  186.     }
  187.     // }}}
  188.  
  189.     // {{{ +-- public (string) human_year ($y)
  190.     /**
  191.      * 연도를 human readable하게 표시
  192.      *
  193.      * 예제:
  194.      * {@example Lunar/tests/sample.php 56 11}
  195.      *
  196.      * @access public
  197.      * @return string   AD/BC type의 연도
  198.      * @param int 연도
  199.      */
  200.     public function human_year ($y{
  201.         if $y {
  202.             $y ($y * -11;
  203.             $t 'BC';
  204.         else
  205.             $t 'AD';
  206.  
  207.         return sprintf ('%s %d'$t$y);
  208.     }
  209.     // }}}
  210.  
  211.     // {{{ +-- public (array) split_date ($date)
  212.     /**
  213.      * YYYY-MM-DD 또는 array ((string) YYYY, (string) MM, (string) DD)
  214.      * 입력값을 * array ((int) $y, (int) $m, (int) $d)으로 변환
  215.      *
  216.      * @access public
  217.      * @return array array ((int) $y, (int) $m, (int) $d)
  218.      * @param array|string
  219.      *      - YYYY-MM-DD
  220.      *      - array ((string) YYYY, (string) MM, (stirng) DD)
  221.      */
  222.     public function split_date ($date{
  223.         if is_array ($date) )
  224.             $date $this->regdate ($date);
  225.  
  226.         $minus ($date[0== '-'true false;
  227.         $date $minus substr ($date1$date;
  228.  
  229.         $r preg_split ('/-/'$date);
  230.         if $minus )
  231.             $r[0*= -1;
  232.  
  233.         foreach ($r as $k => $v )
  234.             $r[$k= (int) $v;
  235.  
  236.         return $r;
  237.     }
  238.     // }}}
  239.  
  240.     // {{{ +-- private (string) regdate ($v)
  241.     /**
  242.      * YYYY-MM-DD 형식의 날자를 반환
  243.      *
  244.      * @access private
  245.      * @return string   YYYY-MM-DD 형식으로 반환
  246.      * @param array     년월일 배열 - array ($year, $month, $day)
  247.      */
  248.     private function regdate ($v{
  249.         list ($year$month$day$v;
  250.  
  251.         return sprintf (
  252.             '%d-%s%d-%s%d',
  253.             $year,
  254.             ($month 10 '0' '',
  255.             (int) $month,
  256.             ($day 10 '0' '',
  257.             (int) $day
  258.         );
  259.     }
  260.     // }}}
  261.  
  262.     // {{{ +-- public (bool) is_leap ($y, $julian = false)
  263.     /**
  264.      * 윤년 체크
  265.      *
  266.      * 예제:
  267.      * {@example Lunar/tests/sample.php 68 14}
  268.      *
  269.      * @access public
  270.      * @return bool 
  271.      * @param int 년도
  272.      * @param bool Julian 여부
  273.      *  <p>
  274.      *  1582년 이전은 Julian calender로 판단하여 이 값이
  275.      *  false라도 율리우스력으로 간주하여 판단한다. (sinse 1.0.1)
  276.      *  </p>
  277.      */
  278.     public function is_leap ($y$julian false{
  279.         // Julian의 윤년은 4로 나누어지면 된다.
  280.         if $julian || $y 1583 )
  281.             return ($y 4false true;
  282.  
  283.         if ( ($y 400== )
  284.             return true;
  285.  
  286.         if ( ($y 4== && ($y 100!= )
  287.             return true;
  288.  
  289.         return false;
  290.     }
  291.     // }}}
  292.  
  293.     // {{{ +-- public (bool) is_gregorian ($y, $m, $d = 1)
  294.     /**
  295.      * 해당 날자가 gregorian 범위인지 체크
  296.      *
  297.      * @access public
  298.      * @return bool 
  299.      * @param int 연도
  300.      * @param int 
  301.      * @param int 
  302.      */
  303.     public function is_gregorian ($y$m$d 1{
  304.         if (int) $m 10 )
  305.             $m '0' . (int) $m;
  306.         if (int) $d 10 )
  307.             $d '0' . (int) $d;
  308.  
  309.         $chk $y $m $d;
  310.  
  311.         if $chk 15821015 )
  312.             return false;
  313.  
  314.         return true;
  315.     }
  316.     // }}}
  317.  
  318.     // {{{ +-- private (string) gregorian2julian ($v)
  319.     /**
  320.      * 그레고리력을 율리안력으로 변환
  321.      *
  322.      * @access private
  323.      * @return stdClass 
  324.      *
  325.      *    <pre>
  326.      *    stdClass Object
  327.      *    (
  328.      *        [fmt] => 2013-06-09          // YYYY-MM-DD 형식의 Julian 날자
  329.      *        [year] => 2013               // 연도
  330.      *        [month] => 6                 // 월
  331.      *        [day] => 9                   // 일
  332.      *        [week] => 화                 // 요일
  333.      *    )
  334.      *    </pre>
  335.      *
  336.      * @param array|intGregorian 연월일 배열 or Julian date count
  337.      */
  338.     private function gregorian2julian ($v{
  339.         if is_array ($v) ) {
  340.             $d $this->regdate ($v);
  341.             list ($y$m$d$this->split_date ($d);
  342.  
  343.             $v $this->cal2jd (array ($y$m$d));
  344.         }
  345.  
  346.         if extension_loaded ('calendar') ) {
  347.             $r = (object) cal_from_jd ($vCAL_JULIAN);
  348.             if $r->year )
  349.                 $r->year++;
  350.  
  351.             return (object) array (
  352.                 'fmt'   => $this->regdate (array ($r->year$r->month$r->day)),
  353.                 'year'  => $r->year,
  354.                 'month' => $r->month,
  355.                 'day'   => $r->day,
  356.                 'week'  => $r->dow
  357.             );
  358.         }
  359.  
  360.         if is_float ($v) ) {
  361.             list ($Z$Fpreg_split ('/\./'$v);
  362.         else {
  363.             $Z $v;
  364.             $F 0;
  365.         }
  366.  
  367.         if $v 2299161 )
  368.             $A $Z;
  369.         else {
  370.             $alpha = (int) ($Z 1867216.25 36524.25);
  371.             $A $Z $alpha - (int) ($alpha 4);
  372.         }
  373.  
  374.         $B $A 1524;
  375.         $C = (int) (($B 122.1365.25);
  376.         $D = (int) (365.25 $C);
  377.         $E = (int) ( ($B $D30.6001);
  378.  
  379.         $day $B $D - (int) (30.6001 $E$F;
  380.         $month ($E 14$E $E 13;
  381.         $year $C 4715;
  382.         if $month )
  383.             $year--;
  384.  
  385.         $week ($v 1.57;
  386.  
  387.         return (object) array (
  388.             'fmt'   => $this->regdate (array ($year$month$day)),
  389.             'year'  => $year,
  390.             'month' => $month,
  391.             'day'   => $day,
  392.             'week'  => $week
  393.         );
  394.     }
  395.     // }}}
  396.  
  397.     // {{{ +-- private mod ($x, $y)
  398.     private function mod ($x$y{
  399.         return ($x $y $y$y;
  400.     }
  401.     // }}}
  402.  
  403.     // {{{ +-- private (string) julian2gregorian ($v)
  404.     /**
  405.      * 율리안력을 그레고리안역으로 변환
  406.      *
  407.      * @access private
  408.      * @return stdClass 
  409.      *
  410.      *    <pre>
  411.      *    stdClass Object
  412.      *    (
  413.      *        [fmt]   => 2013-06-09        // YYYY-MM-DD 형식의 Julian 날자
  414.      *        [year]  => 2013              // 연도
  415.      *        [month] => 6                 // 월
  416.      *        [day]   => 9                 // 일
  417.      *        [week]  => 화                // 요일
  418.      *    )
  419.      *    </pre>
  420.      *
  421.      * @param array|intJulian 연월일 배열 or Julian date count
  422.      */
  423.     private function julian2gregorian ($jd$pure false{
  424.         if is_array ($jd) ) {
  425.             list ($y$m$d$this->split_date ($jd);
  426.             $jd $this->cal2jd (array ($y$m$d)true);
  427.         }
  428.  
  429.         if extension_loaded ('calendar'&& $pure == false {
  430.             $r = (object) cal_from_jd ($jdCAL_GREGORIAN);
  431.             if $r->year )
  432.                 $r->year++;
  433.  
  434.             return (object) array (
  435.                 'fmt'   => $this->regdate (array ($r->year$r->month$r->day)),
  436.                 'year'  => $r->year,
  437.                 'month' => $r->month,
  438.                 'day'   => $r->day,
  439.                 'week'  => $r->dow
  440.             );
  441.         }
  442.  
  443.         // https://en.wikipedia.org/wiki/Julian_day#Gregorian_calendar_from_Julian_day_number
  444.         // 01-01-02 부터 이전은 맞지 않는다 --;
  445.         #$f = (int) $jd + 1401;
  446.         #$f = (int) ($f + (((4 * $jd + 274277) / 146097) * 3) / 4 - 38);
  447.         #$e = 4 * $f + 3;
  448.         #$g = (int) (($e % 1461) / 4);
  449.         #$h = 5 * $g + 2;
  450.         #$day = (int) (($h % 153) / 5 + 1);
  451.         #$month = (int) ((($h / 153 + 2) % 12) + 1);
  452.         #$year = (int) ($e / 1461 - 4716 + (12 + 2 - $month) / 12);
  453.  
  454.         // http://www.fourmilab.ch/documents/calendar/
  455.         $wjd floor ($jd -  0.50.5;
  456.         # GREGORIAN_EPOCH 1721425.5
  457.         $depoch $wjd 1721425.5;
  458.         $quadricent floor ($depoch 146097);
  459.         $dqc $this->mod ($depoch146097);
  460.         $cent floor ($dqc 36524);
  461.         $dcent $this->mod ($dqc36524);
  462.         $quad floor ($dcent 1461);
  463.         $dquad $this->mod ($dcent1461);
  464.         $yindex floor ($dquad 365);
  465.  
  466.         $year ($quadricent 400($cent 100($quad 4$yindex;
  467.         if ($cent == || $yindex == 4) )
  468.             $year++;
  469.     
  470.         $yearday $wjd $this->cal2jd (array ($year11));
  471.         $leapadj (($wjd $this->cal2jd (array ($year31)))
  472.                     ? ($this->is_leap ($year2));
  473.         $month floor (((($yearday $leapadj12373367);
  474.         $day ceil ($wjd $this->cal2jd (array ($year$month1))) 1;
  475.  
  476.         $week ($jd 1.57;
  477.  
  478.         return (object) array (
  479.             'fmt'   => $this->regdate (array ($year$month$day)),
  480.             'year'  => $year,
  481.             'month' => $month,
  482.             'day'   => $day,
  483.             'week'  => $week
  484.         );
  485.     }
  486.     // }}}
  487.  
  488.     // {{{ +-- private (int) cal2jd_pure ($v, $julian = false)
  489.     /**
  490.      * Gregorian 날자를 Julian date로 변환 (by PURE PHP CODE)
  491.      *
  492.      * http://new.astronote.org/bbs/board.php?bo_table=prog&wr_id=29929
  493.      * 1. Y는 해당년도, M는 월(1월=1,2월=2), D는 해당 월의 날짜이다.
  494.      *    D는 시간값도 포함한 소수값으로 생각하자. 가령 3일 12시 UT라면
  495.      *    D=3.5이다.
  496.      * 2. M>2인 경우 Y,M은 변경하지 않는다. M = 1 또는 2인 경우 Y=Y-1,
  497.      *    M=M+12로 계산한다.
  498.      * 3. 그레고리력(Gregorian Calendar)의 경우 아래처럼 계산한다.
  499.      *    A = INT(Y/100), B = 2 – A + INT(A/4)
  500.      *    여기서 INT는 ()안에 들어간 값을 넘지않는 가장 큰 정수이다.
  501.      *    율리우스력(Julian Calendar)의 경우 B=0이다.
  502.      * 4. JD는 다음과 같이 계산된다.
  503.      *    JD = INT(365.25(Y+4716)) + INT(30.6001(M+1)) + D + B – 1524.5
  504.      *    여기서 30.6001은 정확히는 30.6을 써야한다. 하지만 컴퓨터 계산시
  505.      *    10.6이여 하는데 10.599999999 이런식으로 표현되는 경우가 발생하면
  506.      *    INT(10.6)과 INT(10.5999..)의 결과가 달라진다. 이 문제 대해 대처
  507.      *    하기 위해 30.6001을 사용한 것이다. 이러한 에러를 Round-off Error
  508.      *    라고 불린다.
  509.      *
  510.      * @access private
  511.      * @return int Julian date
  512.      * @param array 연월일 배열 : array ($y, $m, $d)
  513.      */
  514.     private function cal2jd_pure ($v$julian false{
  515.         list ($y$m$d$v;
  516.  
  517.         if $m <= {
  518.             $y--;
  519.             $m += 12;
  520.         }
  521.  
  522.         $A = (int) ($y 100);
  523.         $B $julian $A + (int) ($A 4);
  524.         $C = (int) (365.25 ($y 4716));
  525.         $D = (int) (30.6001 ($m 1));
  526.         return ceil ($C $D $d $B 1524.5);
  527.     }
  528.     // }}}
  529.  
  530.     // {{{ +-- private (int) cal2jd_ext ($v, $julian = false)
  531.     /**
  532.      * Gregorian 날자를 Julian date로 변환 (by Calendar Extension)
  533.      *
  534.      * @access private
  535.      * @return int Julian date
  536.      * @param array 연월일 배열 : array ($y, $m, $d)
  537.      */
  538.     private function cal2jd_ext ($v$julian false{
  539.         list ($y$m$d$v;
  540.  
  541.         $old date_default_timezone_get ();
  542.         date_default_timezone_set ('UTC');
  543.  
  544.         $func $julian 'JulianToJD' 'GregorianToJD';
  545.         if $y )
  546.             $y--;
  547.         $r $func ((int) $m(int) $d(int) $y);
  548.  
  549.         date_default_timezone_set ($old);
  550.         return $r;
  551.     }
  552.     // }}}
  553.  
  554.     // {{{ +-- public (int) cal2jd ($v)
  555.     /**
  556.      * Gregorian 날자를 Julian date로 변환
  557.      *
  558.      * @access public
  559.      * @return int Julian date
  560.      * @param array 연월일 배열 : array ($y, $m, $d)
  561.      */
  562.     public function cal2jd ($v$julian false{
  563.         if extension_loaded ('calendar') )
  564.             return $this->cal2jd_ext ($v$julian);
  565.  
  566.         return $this->cal2jd_pure ($v$julian);
  567.     }
  568.     // }}}
  569.  
  570.     // {{{ +-- private (string) toutc ($v)
  571.     /**
  572.      * Localtime을 UTC로 변환
  573.      *
  574.      * @access private
  575.      * @return string YYYY-MM-DD-HH-II-SS
  576.      * @param string date format (YYYY-MM-DD HH:II:SS)
  577.      */
  578.     private function toutc ($v{
  579.         $t strtotime ($v);
  580.         $old date_default_timezone_get ();
  581.         date_default_timezone_set ('UTC');
  582.         $r date ('Y-m-d-H-i-s'$t);
  583.         date_default_timezone_set ($old);
  584.  
  585.         return $r;
  586.     }
  587.     // }}}
  588.  
  589.     // {{{ +-- private (int) to_utc_julian ($v)
  590.     /**
  591.      * 합삭/망 절기 시간을 UTC로 변환 후, Julian date로 표현
  592.      *
  593.      * @access private
  594.      * @return int 
  595.      * @param string data format (YYYY-MM-DD HH:II:SS)
  596.      */
  597.     private function to_utc_julian ($v{
  598.         $buf $this->toutc ($v);
  599.         list ($y$m$d$h$i$s$this->split_date ($buf);
  600.  
  601.         $chk $y $m $d;
  602.  
  603.         //$julian = ( $chk < 18451015 ) ? $true : false;
  604.         $j $this->cal2jd (array ($y$m$d)$julian);
  605.  
  606.         if ( ($h 12{
  607.             $h 11 $h;
  608.             $i 60 $i;
  609.             $buf (($h 3600 $i 6086400* -1;
  610.         else
  611.             $buf (($h 123600 $i 6086400;
  612.  
  613.         return $j $buf;
  614.     }
  615.     // }}}
  616.  
  617.     // {{{ +-- private (array) fix_calendar ($y, $m, $d)
  618.     /**
  619.      * 1582년 10월 15일 이전의 date를 julian calendar로 변환
  620.      *
  621.      * @access private
  622.      * @return array 년월일 배열 (array ($y, $m, $d))
  623.      * @param int year
  624.      * @param int month
  625.      * @param int day
  626.      */
  627.     private function fix_calendar ($y$m$d{
  628.         if $m 10 )
  629.             $m '0' $m;
  630.         if $d 10 )
  631.             $d '0' $d;
  632.  
  633.         # 15821005 ~ 15821014 까지는 gregorian calendar에서는 존재
  634.         # 하지 않는다. 그러므로, 이 기간의 날자는 julian calendar
  635.         # 와 매치되는 날자로 변경한다. (10씩 빼준다.
  636.         $chk $y $m $d;
  637.         if $chk 15821004 && $chk 15821015 {
  638.             $julian $this->cal2jd (array ($y(int) $m(int) $d));
  639.             $julian -= 10;
  640.             $r $this->julian2gregorian ($julian);
  641.             list ($y$m$darray ($r->year$r->month$r->day);
  642.         }
  643.  
  644.         # 15821005 보다 과거의 날자는 gregorian calendar가 없다.
  645.         # 그러므로 julian calendar로 표현한다.
  646.         if $this->is_gregorian ($y(int) $m(int) $d=== false {
  647.             $r $this->julian2gregorian (array ($y(int) $m(int) $d));
  648.             list ($y$m$darray ($r->year$r->month$r->day);
  649.         }
  650.  
  651.         return array ($y$m$d);
  652.     }
  653.     // }}}
  654.  
  655.     // {{{ +-- public (object) tolunar ($v = null)
  656.     /**
  657.      * 양력 날자를 음력으로 변환
  658.      *
  659.      * 진짜 만세력은 1582/10/15(Gregorian calendar의 시작) 이전의 날자
  660.      * 역시 Gregorian으로 표기를 한다. 그러므로 Calendar의 오류로 보일
  661.      * 수도 있다. (실제로는 계산상의 오류는 없다고 봐야 한다.)
  662.      *
  663.      * 이런 부분을 보정하기 위하여, tolunar method는 1582/10/04 까지의
  664.      * 날자는 julian calendar로 변환을 하여 음력날자를 구한다. 이로 인
  665.      * 하여 1582/10/15 이전의 음력 날자는 original 진짜 만세력과 다른
  666.      * 값을 가지게 된다.)
  667.      *
  668.      * 이렇게 표현될 경우, 천문우주 지식정보의 값과 비슷하게 나올 수는
  669.      * 있으나, 평달/큰달 계산은 진짜 만세력의 것을 이용하므로 오차는
  670.      * 발생할 수 있다.
  671.      * http://astro.kasi.re.kr/Life/ConvertSolarLunarForm.aspx?MenuID=115
  672.      *
  673.      * 2.0 부터는 이러한 오차를 줄이기 위하여 oops\KASI_Lunar package가
  674.      * 설치되어 있을 경우, 1392-02-05 ~ 2050-12-31 기간에 대해서는
  675.      * 천문과학연구원의 데이터를 이용할 수 있도록 지원한다.
  676.      *
  677.      * 예제:
  678.      * {@example Lunar/tests/sample.php 83 35}
  679.      *
  680.      * @access public
  681.      * @return stdClass    음력 날자 정보 반환
  682.      *
  683.      *    <pre>
  684.      *    stdClass Object
  685.      *    (
  686.      *        [fmt] => 2013-06-09          // YYYY-MM-DD 형식의 음력 날자
  687.      *        [dangi] => 4346              // 단기
  688.      *        [hyear] => AD 2013           // AD/BC 형식의 연도
  689.      *        [year] => 2013               // 연도
  690.      *        [month] => 6                 // 월
  691.      *        [day] => 9                   // 일
  692.      *        [leap] =>                    // 음력 윤달 여부
  693.      *        [largemonth] => 1            // 평달/큰달 여부
  694.      *        [week] => 화                 // 요일
  695.      *        [hweek] => 火                // 한자 요일
  696.      *        [unixstamp] => 1373900400    // unixstamp (양력 날자)
  697.      *        [ganji] => 계사              // 세차(년)
  698.      *        [hganji] => 癸巳             // 한자 세차
  699.      *        [gan] => 계                  // 세차 10간
  700.      *        [hgan] => 癸                 // 세차 한자 10간
  701.      *        [ji] => 사                   // 세차 12지
  702.      *        [hji] => 巳                  // 세차 한자 12지
  703.      *        [ddi] => 뱀                  // 띠
  704.      *    )
  705.      *    </pre>
  706.      *
  707.      * @param int|string  날자형식
  708.      *    - unixstmap (1970년 12월 15일 이후부터 가능)
  709.      *    - Ymd or Y-m-d
  710.      *    - null data (현재 시간)
  711.      *    - 1582년 10월 15일 이전의 날자는 율리우스력의 날자로 취급함.
  712.      */
  713.     public function tolunar ($v null{
  714.         list ($y$m$d$this->toargs ($v);
  715.         #printf ("** %4s.%2s.%2s ... ", $y, $m, $d);
  716.  
  717.         $kasi false;
  718.         $cdate preg_replace ('/-/'''$v);
  719.         // 1391-02-05 ~ 2050-12-31 까지는 KASI data로 처리를 한다.
  720.         if $cdate 13910204 && $cdate 20510101 {
  721.             if class_exists ('oops\KASI\Lunar') ) {
  722.                 $kasi true;
  723.                 if $this->KASI == null )
  724.                     $this->KASI new \oops\KASI\Lunar;
  725.                 $r $this->KASI->tolunar ($v);
  726.                 if $r === false )
  727.                     return false;
  728.  
  729.                 $year   $r->year;
  730.                 $month  $r->month;
  731.                 $day    $r->day;
  732.                 $leap   $r->leap;
  733.                 $lmonth $r->lmoon;
  734.                 $w      $r->week;
  735.  
  736.                 unset ($r);
  737.                 $r array ($year$month$day);
  738.             }
  739.         }    
  740.  
  741.         if $kasi === false {
  742.             list ($y$m$d$this->fix_calendar ($y$m$d);
  743.             #printf ("%4s.%2s.%2s<br>", $y, $m, $d);
  744.  
  745.             $r $this->solartolunar ($y$m$d);
  746.             list ($year$month$day$leap$lmonth$r;
  747.  
  748.             $w $this->getweekday ($y$m$d);
  749.         }
  750.  
  751.         $k1 ($year 610;
  752.         $k2 ($year 812;
  753.  
  754.         if $k1 $k1 += 10;
  755.         if $k2 $k2 += 12;
  756.  
  757.         return (object) array (
  758.             'fmt'        => $this->regdate ($r),
  759.             'dangi'      => $year 2333,
  760.             'hyear'      => $this->human_year ($year),
  761.             'year'       => $year,
  762.             'month'      => $month,
  763.             'day'        => $day,
  764.             'leap'       => $leap,
  765.             'largemonth' => $lmonth,
  766.             'week'       => $this->week[$w],
  767.             'hweek'      => $this->hweek[$w],
  768.             'unixstamp'  => mktime (000$m$d$y),
  769.             'ganji'      => $this->gan[$k1$this->ji[$k2],
  770.             'hganji'     => $this->hgan[$k1$this->hji[$k2],
  771.             'gan'        => $this->gan[$k1],
  772.             'hgan'       => $this->hgan[$k1],
  773.             'ji'         => $this->ji[$k2],
  774.             'hji'        => $this->hji[$k2],
  775.             'ddi'        => $this->ddi[$k2]
  776.         );
  777.     }
  778.     // }}}
  779.  
  780.     // {{{ +-- public (object) tosolar ($v = null, $leap = false)
  781.     /**
  782.      * 음력 날자를 양력으로 변환.
  783.      *
  784.      * 구하는 음력월이 윤달인지 여부를 알 수 없을 경우, tosolar method
  785.      * 를 실행하여 얻은 양력 날자를 다시 tolunar로 변환하여 비교하여
  786.      * 동일하지 않다면, 윤달 파라미터 값을 주고 다시 구해야 한다!
  787.      *
  788.      * 진짜 만세력은 Gregorian으로 표기를 하기 때문에, 양력 1582-10-15
  789.      * 이전의 경우에는 return object의 julian member 값으로 비교를 해야
  790.      * 한다.
  791.      *
  792.      * 예제:
  793.      * {@example Lunar/tests/sample.php 119 42}
  794.      *
  795.      * @access public
  796.      * @return stdClass    양력 날자 정보 object 반환
  797.      *
  798.      *    <pre>
  799.      *    stdClass Object
  800.      *    (
  801.      *        [jd] => 2456527             // Julian Date Count
  802.      *        [fmt] => 2013-07-16         // YYYY-MM-DD 형식의 양력 날자 (15821015 이전은 율리우스력)
  803.      *        [gregory] => 2013-07-16     // Gregory Calendar
  804.      *        [julian] => 2013-08-09      // Julian Calendar
  805.      *        [dangi] => 4346             // 단기 (양력)
  806.      *        [hyear] => AD 2013          // AD/BC 형식 년도
  807.      *        [year] => 2013              // 양력 연도
  808.      *        [month] => 7                // 월
  809.      *        [day] => 16                 // 일
  810.      *        [week] => 화                // 요일
  811.      *        [hweek] => 火               // 한자 요일
  812.      *        [unixstamp] => 1373900400   // unixstamp (양력)
  813.      *        [ganji] => 계사             // 세차
  814.      *        [hganji] => 癸巳            // 세차 한자
  815.      *        [gan] => 계                 // 세차 10간
  816.      *        [hgan] => 癸                // 세차 한자 10간
  817.      *        [ji] => 사                  // 세차 12지
  818.      *        [hji] => 巳                 // 세차 한자 12지
  819.      *        [ddi] => 뱀                 // 띠
  820.      *    )
  821.      *    </pre>
  822.      *
  823.      * @param int|string날자형식
  824.      *
  825.      *    - unixstmap (1970년 12월 15일 이후부터 가능)
  826.      *    - Ymd or Y-m-d
  827.      *    - null data (현재 시간)
  828.      *
  829.      * @param bool 윤달여부
  830.      */
  831.     public function tosolar ($v null$leap false{
  832.         list ($y$m$d$this->toargs ($vtrue);
  833.  
  834.         $kasi false;
  835.         $cdate preg_replace ('/-/'''$v);
  836.         // 1391-01-01 ~ 2050-12-31 까지는 KASI data로 처리를 한다.
  837.         if $cdate 13910101 && $cdate 20501119 {
  838.             if class_exists ('oops\KASI\Lunar') ) {
  839.                 $kasi true;
  840.                 if $this->KASI == null )
  841.                     $this->KASI new \oops\KASI\Lunar;
  842.                 $r $this->KASI->tosolar ($v$leap);
  843.                 if $r === false )
  844.                     return false;
  845.  
  846.                 $year  $r->year;
  847.                 $month $r->month;
  848.                 $day   $r->day;
  849.                 $w     $r->week;
  850.  
  851.                 $jdate $r->jd
  852.                 $fmt   $r->fmt;
  853.  
  854.                 if $r->jd 2299160{
  855.                     $j    $this->gregorian2julian ($r->jd);
  856.                     $jfmt $j->fmt;
  857.                     $gfmt $r->fmt;
  858.                 else {
  859.                     $jfmt $r->fmt;
  860.                     $g    $this->julian2gregorian ($r->jd);
  861.                     $gfmt $g->fmt;
  862.                 }
  863.             }
  864.         }
  865.  
  866.         if $kasi === false {
  867.             $r $this->lunartosolar ($y$m$d$leap);
  868.             list ($year$month$day$r;
  869.  
  870.             $w $this->getweekday ($year$month$day);
  871.  
  872.             $jdate $this->cal2jd ($r);
  873.             //$julian = $this->gregorian2julian ($r);
  874.             $julian $this->gregorian2julian ($jdate);
  875.             $jfmt   $julian->fmt;
  876.             $gfmt   $this->regdate ($r);
  877.             $fmt ($jdate 2299161$jfmt $gfmt;
  878.         }
  879.  
  880.         $k1 ($y 610;
  881.         $k2 ($y 812;
  882.  
  883.         if $k1 $k1 += 10;
  884.         if $k2 $k2 += 12;
  885.  
  886.         return (object) array (
  887.             'jd'         => $jdate,
  888.             'fmt'        => $fmt,
  889.             'gregory'    => $gfmt,
  890.             'julian'     => $jfmt,
  891.             'dangi'      => $year 2333,
  892.             'hyear'      => $this->human_year ($year),
  893.             'year'       => $year,
  894.             'month'      => $month,
  895.             'day'        => $day,
  896.             'week'       => $this->week[$w],
  897.             'hweek'      => $this->hweek[$w],
  898.             'unixstamp'  => mktime (000$month$day$year),
  899.             'ganji'      => $this->gan[$k1$this->ji[$k2],
  900.             'hganji'     => $this->hgan[$k1$this->hji[$k2],
  901.             'gan'        => $this->gan[$k1],
  902.             'hgan'       => $this->hgan[$k1],
  903.             'ji'         => $this->ji[$k2],
  904.             'hji'        => $this->hji[$k2],
  905.             'ddi'        => $this->ddi[$k2]
  906.         );
  907.     }
  908.     // }}}
  909.  
  910.     // {{{ +-- public (object) dayfortune ($v = null)
  911.     /**
  912.      * 세차(년)/월건(월)/일진(일) 데이터를 구한다.
  913.      *
  914.      * 예제:
  915.      * {@example Lunar/tests/sample.php 163 56}
  916.      *
  917.      * @access public
  918.      * @return stdClass 
  919.      *
  920.      *    <pre>
  921.      *    stdClass Object
  922.      *    (
  923.      *        [data] => stdClass Object
  924.      *            (
  925.      *                 [y] => 29           // 세차 index
  926.      *                 [m] => 55           // 월건 index
  927.      *                 [d] => 19           // 일진 index
  928.      *            )
  929.      *
  930.      *        [year] => 계사               // 세차 값
  931.      *        [month] => 기미              // 월건 값
  932.      *        [day] => 계미                // 일진 값
  933.      *        [hyear] => 癸巳              // 한자 세차 값
  934.      *        [hmonth] => 己未             // 한자 월건 값
  935.      *        [hday] => 癸未               // 한자 일진 값
  936.      *    )
  937.      *    </pre>
  938.      *
  939.      * @param int|string날자형식
  940.      *
  941.      *     - unixstmap (1970년 12월 15일 이후부터 가능)
  942.      *     - Ymd or Y-m-d
  943.      *     - null data (현재 시간)
  944.      *     - 1582년 10월 15일 이전의 날자는 율리우스력의 날자로 취급함.
  945.      */
  946.     public function dayfortune ($v null{
  947.         list ($y$m$d$this->toargs ($v);
  948.         list ($y$m$d$this->fix_calendar ($y$m$d);
  949.  
  950.         list ($so24$year$month$day$hour)
  951.             = $this->sydtoso24yd ($y$m$d10);
  952.  
  953.         return (object) array (
  954.             'data' => (object) array ('y' => $year'm' => $month'd' => $day),
  955.             'year' => $this->ganji[$year],
  956.             'month' => $this->ganji[$month],
  957.             'day' => $this->ganji[$day],
  958.             'hyear' => $this->hganji[$year],
  959.             'hmonth' => $this->hganji[$month],
  960.             'hday' => $this->hganji[$day],
  961.         );
  962.     }
  963.     // }}}
  964.  
  965.     // {{{ +-- public (object) s28day ($v = null)
  966.     /**
  967.      * 특정일의 28수를 구한다.
  968.      *
  969.      * 예제:
  970.      * {@example Lunar/tests/sample.php 221 35}
  971.      *
  972.      * @access public
  973.      * @return stdClass 
  974.      *
  975.      *    <pre>
  976.      *    stdClass Object
  977.      *    (
  978.      *        [data] => 5    // 28수 index
  979.      *        [k] => 미      // 한글 28수 값
  980.      *        [h] => 尾      // 한자 28수 값
  981.      *    )
  982.      *    </pre>
  983.      *
  984.      * @param int|string  날자형식
  985.      *
  986.      *     - unixstmap (1970년 12월 15일 이후부터 가능)
  987.      *     - Ymd or Y-m-d
  988.      *     - null data (현재 시간)
  989.      *     - 1582년 10월 15일 이전의 날자는 율리우스력의 날자로 취급함.
  990.      *     - Recursion s28day return value:<br>
  991.      *       loop에서 s28day method를 반복해서 호출할 경우 return value를 이용할
  992.      *       경우, return value의 index값을 이용하여 계산을 하지 않아 속도가 빠름.
  993.      */
  994.     public function s28day ($v null{
  995.         if is_object ($v) ) {
  996.             $r $v->data 1;
  997.             if $r >= 28 )
  998.                 $r %= 28;
  999.  
  1000.             goto return_data;
  1001.         }
  1002.  
  1003.         list ($y$m$d$this->toargs ($v);
  1004.         list ($y$m$d$this->fix_calendar ($y$m$d);
  1005.         $r $this->get28sday ($y$m$d);
  1006.  
  1007.         return_data:
  1008.  
  1009.         return (object) array (
  1010.             'data' => $r,
  1011.             'k' => $this->s28days_hangul[$r],
  1012.             'h' => $this->s28days[$r]
  1013.         );
  1014.     }
  1015.     // }}}
  1016.  
  1017.     // {{{ +-- public (array) seasondate ($v = null)
  1018.     /**
  1019.      * 해당 양력일에 대한 음력 월의 절기 시간 구하기
  1020.      *
  1021.      * 예제:
  1022.      * {@example Lunar/tests/sample.php 257 52}
  1023.      *
  1024.      * @access public
  1025.      * @return stdClass   현달 초입/중기와 다음달 초입 데이터 반환
  1026.      *
  1027.      *    <pre>
  1028.      *    stdClass Object
  1029.      *    (
  1030.      *        [center] => stdClass Object      // 이번달 초입 데이터
  1031.      *            (
  1032.      *                [name] => 소서              // 절기 이름
  1033.      *                [hname] => 小暑             // 절기 한자 이름
  1034.      *                [hyear] => AD 2013          // AD/BC 형식 연도
  1035.      *                [year] => 2013              // 초입 연도
  1036.      *                [month] => 7                // 초입 월
  1037.      *                [day] => 7                  // 초입 일
  1038.      *                [hour] => 7                 // 초입 시간
  1039.      *                [min] => 49                 // 초입 분
  1040.      *                [julian] => 2456480.4506944 // Julian date (UTC)
  1041.      *            )
  1042.      *
  1043.      *        [ccenter] => stdClass Object     // 이번달 중기 데이터
  1044.      *            (
  1045.      *                [name] => 대서              // 절기 이름
  1046.      *                [hname] => 大暑             // 절기 한자 이름
  1047.      *                [hyear] => AD 2013          // AD/BC 형식 연도
  1048.      *                [year] => 2013              // 중기 연도
  1049.      *                [month] => 7                // 중기 월
  1050.      *                [day] => 23                 // 중기 일
  1051.      *                [hour] => 1                 // 중기 시간
  1052.      *                [min] => 11                 // 중기 분
  1053.      *                [julian] => 2456496.1743056 // Julian date (UTC)
  1054.      *            )
  1055.      *
  1056.      *        [nenter] => stdClass Object      // 다음달 초입 데이터
  1057.      *            (
  1058.      *                [name] => 입추              // 절기 이름
  1059.      *                [hname] => 立秋             // 절기 한자 이름
  1060.      *                [hyear] => AD 2013          // AD/BC 형식 연도
  1061.      *                [year] => 2013              // 초입 연도
  1062.      *                [month] => 8                // 초입 월
  1063.      *                [day] => 7                  // 초입 일
  1064.      *                [hour] => 17                // 초입 시간
  1065.      *                [min] => 36                 // 초입 분
  1066.      *                [julian] => 2456511.8583333 // Julian date (UTC)
  1067.      *            )
  1068.      *    )
  1069.      *    </pre>
  1070.      *
  1071.      * @param int|string  날자형식
  1072.      *
  1073.      *   - unixstmap (1970년 12월 15일 이후부터 가능)
  1074.      *   - Ymd or Y-m-d
  1075.      *   - null data (현재 시간
  1076.      *   - 1582년 10월 15일 이전의 날자는 율리우스력의 날자로 취급함.
  1077.      */
  1078.     public function seasondate ($v null{
  1079.         list ($y$m$d$this->toargs ($v);
  1080.         list ($y$m$d$this->fix_calendar ($y$m$d);
  1081.  
  1082.         list (
  1083.             $inginame$ingiyear$ingimonth$ingiday$ingihour$ingimin,
  1084.             $midname$midyear$midmonth$midday$midhour$midmin,
  1085.             $outginame$outgiyear$outgimonth$outgiday$outgihour$outgimin
  1086.         $this->solortoso24 ($y$m2010);
  1087.  
  1088.         $j_ce $this->to_utc_julian (
  1089.             sprintf (
  1090.                 '%s %s:%s:00',
  1091.                 $this->regdate (array ($ingiyear$ingimonth$ingiday)),
  1092.                 $ingihour 10 '0' $ingihour $ingihour,
  1093.                 $ingimin 10 '0' $ingimin $ingimin
  1094.             )
  1095.         );
  1096.  
  1097.         // 1852-10-15 이전이면 julian으로 변경
  1098.         if $this->is_gregorian ($ingiyear$ingimonth$ingiday=== false {
  1099.             $r $this->gregorian2julian (array ($ingiyear$ingimonth$ingiday));
  1100.             $ingiyear  $r->year;
  1101.             $ingimonth $r->month;
  1102.             $ingiday   $r->day;
  1103.         }
  1104.  
  1105.         $j_cc $this->to_utc_julian (
  1106.             sprintf (
  1107.                 '%s %s:%s:00',
  1108.                 $this->regdate (array ($midyear$midmonth$midday)),
  1109.                 $midhour 10 '0' $midhour $midhour,
  1110.                 $midmin 10 '0' $midmin $midmin
  1111.             )
  1112.         );
  1113.  
  1114.         // 1852-10-15 이전이면 julian으로 변경
  1115.         if $this->is_gregorian ($midyear$midmonth$midday=== false {
  1116.             $r $this->gregorian2julian (array ($midyear$midmonth$midday));
  1117.             $midyear  $r->year;
  1118.             $midmonth $r->month;
  1119.             $midday   $r->day;
  1120.         }
  1121.  
  1122.         $j_ne $this->to_utc_julian (
  1123.             sprintf (
  1124.                 '%s %s:%s:00',
  1125.                 $this->regdate (array ($outgiyear$outgimonth$outgiday)),
  1126.                 $outgihour 10 '0' $outgihour $outgihour,
  1127.                 $outgimin 10 '0' $outgimin $outgimin
  1128.             )
  1129.         );
  1130.  
  1131.         // 1852-10-15 이전이면 julian으로 변경
  1132.         if $this->is_gregorian ($outgiyear$outgimonth$outgiday=== false {
  1133.             $r $this->gregorian2julian (array ($outgiyear$outgimonth$outgiday));
  1134.             $outgiyear  $r->year;
  1135.             $outgimonth $r->month;
  1136.             $outgiday   $r->day;
  1137.         }
  1138.  
  1139.         return (object) array (
  1140.             'center'  => (object) array (
  1141.                 'name'   => $this->month_st[$inginame],
  1142.                 'hname'  => $this->hmonth_st[$inginame],
  1143.                 'hyear'  => $this->human_year ($ingiyear),
  1144.                 'year'   => $ingiyear,
  1145.                 'month'  => $ingimonth,
  1146.                 'day'    => $ingiday,
  1147.                 'hour'   => $ingihour,
  1148.                 'min'    => $ingimin,
  1149.                 'julian' => $j_ce
  1150.             ),
  1151.             'ccenter' => (object) array (
  1152.                 'name'   => $this->month_st[$midname],
  1153.                 'hname'  => $this->hmonth_st[$midname],
  1154.                 'hyear'  => $this->human_year ($midyear),
  1155.                 'year'   => $midyear,
  1156.                 'month'  => $midmonth,
  1157.                 'day'    => $midday,
  1158.                 'hour'   => $midhour,
  1159.                 'min'    => $midmin,
  1160.                 'julian' => $j_cc
  1161.             ),
  1162.             'nenter'  => (object) array (
  1163.                 'name'   => $this->month_st[$outginame],
  1164.                 'hname'  => $this->hmonth_st[$outginame],
  1165.                 'hyear'  => $this->human_year ($outgiyear),
  1166.                 'year'   => $outgiyear,
  1167.                 'month'  => $outgimonth,
  1168.                 'day'    => $outgiday,
  1169.                 'hour'   => $outgihour,
  1170.                 'min'    => $outgimin,
  1171.                 'julian' => $j_ne
  1172.             )
  1173.         );
  1174.     }
  1175.     // }}}
  1176.  
  1177.     // {{{ +-- public (object) moonstatus ($v = null)
  1178.     /**
  1179.      * 양력일에 대한 음력월 합삭/망 데이터 구하기
  1180.      *
  1181.      * 예제:
  1182.      * {@example Lunar/tests/sample.php 311 56}
  1183.      *
  1184.      * @access public
  1185.      * @return stdClass    합삭/망 object
  1186.      *
  1187.      *    <pre>
  1188.      *    stdClass Object
  1189.      *    (
  1190.      *        [new] => stdClass Object      // 합삭 (New Moon) 데이터
  1191.      *            (
  1192.      *                [hyear] => AD 2013          // 합삭 AD/BC 형식 연도
  1193.      *                [year] => 2013              // 합삭 연도
  1194.      *                [month] => 7                // 합삭 월
  1195.      *                [day] => 8                  // 합삭 일
  1196.      *                [hour] => 16                // 합삭 시간
  1197.      *                [min] => 15                 // 합삭 분
  1198.      *                [julian] => 2456481.8020833 // Julian date (UTC)
  1199.      *            )
  1200.      *
  1201.      *        [full] => stdClass Object     // 망 (Full Moon) 데이터
  1202.      *            (
  1203.      *                [hyear] => AD 2013          // 망 AD/BC 형식 연도
  1204.      *                [year] => 2013              // 망 연도
  1205.      *                [month] => 7                // 망 월
  1206.      *                [day] => 23                 // 망 일
  1207.      *                [hour] => 2                 // 망 시간
  1208.      *                [min] => 59                 // 망 분
  1209.      *                [julian] => 2456496.2493056 // Julian date (UTC)
  1210.      *            )
  1211.      *    )
  1212.      *    </pre>
  1213.      *
  1214.      * @param int|string  날자형식
  1215.      *
  1216.      *    - unixstmap (1970년 12월 15일 이후부터 가능)
  1217.      *    - Ymd or Y-m-d
  1218.      *    - null data (현재 시간)
  1219.      *    - 1582년 10월 15일 이전의 날자는 율리우스력의 날자로 취급함.
  1220.      */
  1221.     public function moonstatus ($v null{
  1222.         list ($y$m$d$this->toargs ($v);
  1223.         list ($y$m$d$this->fix_calendar ($y$m$d);
  1224.  
  1225.         list (
  1226.             $y1$mo1$d1$h1$mi1,
  1227.             $ym$mom$dm$hm$mim,
  1228.             $y2$m2$d2$h2$mi2
  1229.         $this->getlunarfirst ($y$m$d);
  1230.  
  1231.         $j_new $this->to_utc_julian (
  1232.             sprintf (
  1233.                 '%s %s:%s:00',
  1234.                 $this->regdate (array ($y1$mo1$d1)),
  1235.                 $h1 10 '0' $h1 $h1,
  1236.                 $mi1 10 '0' $mi1 $mi1
  1237.             )
  1238.         );
  1239.  
  1240.         // 1852-10-15 이전이면 julian으로 변경
  1241.         if $this->is_gregorian ($y1$mo1$d1=== false {
  1242.             $r $this->gregorian2julian (array ($y1$mo1$d1));
  1243.             $y1 $r->year;
  1244.             $mo1 $r->month;
  1245.             $d1 $r->day;
  1246.         }
  1247.  
  1248.         $j_full $this->to_utc_julian (
  1249.             sprintf (
  1250.                 '%s %s:%s:00',
  1251.                 $this->regdate (array ($ym$mom$dm)),
  1252.                 $hm 10 '0' $hm $hm,
  1253.                 $mim 10 '0' $mim $mim
  1254.             )
  1255.         );
  1256.  
  1257.         // 1852-10-15 이전이면 julian으로 변경
  1258.         if $this->is_gregorian ($ym$mom$dm=== false {
  1259.             $r $this->gregorian2julian (array ($ym$mom$dm));
  1260.             $ym $r->year;
  1261.             $mom $r->month;
  1262.             $dm $r->day;
  1263.         }
  1264.  
  1265.         return (object) array (
  1266.             'new' => (object) array (
  1267.                 'hyear'  => $this->human_year ($y1),
  1268.                 'year'   => $y1,
  1269.                 'month'  => $mo1,
  1270.                 'day'    => $d1,
  1271.                 'hour'   => $h1,
  1272.                 'min'    => $mi1,
  1273.                 'julian' => $j_new
  1274.             ),   // 합삭 (New Moon)
  1275.             'full' => (object) array (
  1276.                 'hyear'  => $this->human_year ($ym),
  1277.                 'year'   => $ym,
  1278.                 'month'  => $mom,
  1279.                 'day'    => $dm,
  1280.                 'hour'   => $hm,
  1281.                 'min'    => $mim,
  1282.                 'julian' => $j_full
  1283.             )    // 망 (Full Moon)
  1284.         );
  1285.     }
  1286.     // }}}
  1287.  
  1288.     // {{{ +-- public (string) ganji_ref ($no, $mode = false)
  1289.     /**
  1290.      * dayfortune method의 ganji index 반환값을 이용하여, ganji
  1291.      * 값을 구함
  1292.      *
  1293.      * 예제:
  1294.      * {@example Lunar/tests/sample.php 163 56}
  1295.      *
  1296.      * @access public
  1297.      * @return string 
  1298.      * @param int ganji index number
  1299.      * @param bool 출력 모드 (false => 한글, true => 한자)
  1300.      */
  1301.     public function ganji_ref ($no$mode false{
  1302.         if $no 59 )
  1303.             $no -= 60;
  1304.  
  1305.         $m $mode 'hganji' 'ganji';
  1306.         return $this->{$m}[$no];
  1307.     }
  1308.     // }}}
  1309.  
  1310. }
  1311.  
  1312. /*
  1313.  * Local variables:
  1314.  * tab-width: 4
  1315.  * c-basic-offset: 4
  1316.  * End:
  1317.  * vim: set filetype=php noet sw=4 ts=4 fdm=marker:
  1318.  * vim600: noet sw=4 ts=4 fdm=marker
  1319.  * vim<600: noet sw=4 ts=4
  1320.  */
  1321. ?>

Documentation generated on Tue, 14 May 2019 02:00:27 +0900 by phpDocumentor 1.4.4