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

Source for file Lunar_API.php

Documentation is available at Lunar_API.php

  1. <?php
  2. /**
  3.  * Project: Lunar_API :: 양력/음력 변환 코어 클래스<br>
  4.  * File:    Lunar_API.php
  5.  *
  6.  * 이 패키지는 양력/음력간의 변환을 제공하는 API로, 고영창님의 '진짜만세력'
  7.  * 0.92(Perl version)와 0.93(Pascal version)버전을 PHP로 포팅한 것이다.
  8.  *
  9.  * 이 변환 API의 유효기간은 다음과 같다.
  10.  *
  11.  * <pre>
  12.  *   * 32bit
  13.  *     + -2087-02-09(음력 -2087-01-01) ~ 6078-01-29(음 6077-12-29)
  14.  *     + -2087-07-05(음력 -2087-05-29) 이전은 계산이 무지 느려짐..
  15.  *
  16.  *   * 64bit
  17.  *     + -4712-02-08 ~ 9999-12-31
  18.  *     + -9999-01-01 ~ 9999-12-31
  19.  *     + 64bit 계산이 가능한 시점까지 가능할 듯..
  20.  *
  21.  * </pre>
  22.  *
  23.  * @category    Calendar
  24.  * @package     oops\Lunar
  25.  * @subpackage    Lunar Core API
  26.  * @author      JoungKyun.Kim <http://oops.org>
  27.  * @copyright   (c) 2018, OOPS.org
  28.  * @license     고영창 (http://afnmp3.homeip.net/~kohyc/calendar/index.cgi)
  29.  * @link        http://pear.oops.org/package/Lunar
  30.  * @filesource
  31.  */
  32.  
  33. /**
  34.  * Namespace oops
  35.  */
  36. namespace oops;
  37.  
  38. /**
  39.  * Lunar Core API
  40.  *
  41.  * 이 패키지는 양력/음력간의 변환을 제공하는 API로, 고영창님의 '진짜만세력'
  42.  * 0.92(Perl version)와 0.93(Pascal version)버전을 PHP로 포팅한 것이다.
  43.  *
  44.  * 이 변환 API의 유효기간은 다음과 같다.
  45.  *
  46.  * <pre>
  47.  *   * 32bit
  48.  *     + -2087-02-09(음력 -2087-01-01) ~ 6078-01-29(음 6077-12-29)
  49.  *     + -2087-07-05(음력 -2087-05-29) 이전은 계산이 무지 느려짐..
  50.  *
  51.  *   * 64bit
  52.  *     + -4712-02-08 ~ 9999-12-31
  53.  *     + -9999-01-01 ~ 9999-12-31
  54.  *     + 64bit 계산이 가능한 시점까지 가능할 듯..
  55.  *
  56.  * </pre>
  57.  *
  58.  * @package     oops\Lunar
  59.  * @subpackage    Lunar Core API
  60.  * @author      JoungKyun.Kim <http://oops.org>
  61.  * @copyright   (c) 2018, OOPS.org
  62.  * @license     고영창 (http://afnmp3.homeip.net/~kohyc/calendar/index.cgi)
  63.  * @filesource
  64.  */
  65. Class Lunar_API {
  66.     // {{{ +-- protected prpperties
  67.     /**#@+
  68.      * @access protected
  69.      */
  70.     /**
  71.      * @var array 
  72.      */
  73.     protected $month = array (
  74.         021355428436449886335108366130578152958,
  75.         175471198077220728243370265955288432310767,
  76.         332928354903376685398290419736441060462295,
  77.         483493504693525949
  78.     );
  79.  
  80.     /**
  81.      * 십간(十干) 데이터
  82.      * @var array 
  83.      */
  84.     protected $gan = array ('갑''을''병''정''무''기''경''신''임''계');
  85.     /**
  86.      * 십간(十干) 한자 데이터
  87.      * @var array 
  88.      */
  89.     protected $hgan = array ('甲''乙''丙''丁''戊''己''庚''辛''壬''癸');
  90.     /**
  91.      * 십이지(十二支) 데이터
  92.      * @var array 
  93.      */
  94.     protected $ji = array ('자''축''인''묘''진''사''오''미''신''유''술''해');
  95.     /**
  96.      * 십이지(十二支) 한자 데이터
  97.      * @var array 
  98.      */
  99.     protected $hji = array ('子''丑''寅''卯''辰''巳''午''未''申''酉''戌''亥');
  100.     /**
  101.      * 띠 데이터
  102.      * @var array 
  103.      */
  104.     protected $ddi = array ('쥐''소''호랑이''토끼''용''뱀''말''양''원숭이''닭''개''돼지');
  105.  
  106.     /**#@+
  107.      * 병자년 경인월 신미일 기해시 입춘 데이터
  108.      * @var integer
  109.      */
  110.     protected $unityear  = 1996;
  111.     protected $unitmonth = 2;
  112.     protected $unitday   = 4;
  113.     protected $unithour  = 22;
  114.     protected $unitmin   = 8;
  115.     protected $unitsec   = 0;
  116.     /**#@-*/
  117.  
  118.     /**#@+
  119.      * 병자년 데이터
  120.      * @var integer
  121.      */
  122.     protected $uygan = 2;
  123.     protected $uyji  = 0;
  124.     protected $uysu  = 12;
  125.     /**#@-*/
  126.  
  127.     /**#@+
  128.      * 경인년 데이터
  129.      * @var integer
  130.      */
  131.     protected $umgan = 6;
  132.     protected $umji  = 2;
  133.     protected $umsu  = 26;
  134.     /**#@-*/
  135.  
  136.     /**#@+
  137.      * 신미일 데이터
  138.      * @var integer
  139.      */
  140.     protected $udgan = 7;
  141.     protected $udji  = 7;
  142.     protected $udsu  = 7;
  143.     /**#@-*/
  144.  
  145.     /**#@+
  146.      * 기해시 데이터
  147.      * @var integer
  148.      */
  149.     protected $uhgan = 5;
  150.     protected $uhji  = 11;
  151.     protected $uhsu  = 35;
  152.     /**#@-*/
  153.  
  154.     /**#@+
  155.      * 정월 초하루 합삭 시간
  156.      * @var integer
  157.      */
  158.     protected $unitmyear  = 1996;
  159.     protected $unitmmonth = 2;
  160.     protected $unitmday   = 19;
  161.     protected $unitmhour  = 8;
  162.     protected $unitmmin   = 30;
  163.     protected $unitmsec   = 0;
  164.     protected $moonlength = 42524;
  165.     /**#@-*/
  166.     /**#@-*/
  167.     // }}}
  168.  
  169.     // {{{ +-- public prpperties
  170.     /**#@+
  171.      * @access public
  172.      */
  173.     /**
  174.      * 절기 데이터
  175.      * @var array 
  176.      */
  177.     protected $month_st = array (
  178.         '입춘''우수''경칩''춘분''청명''곡우',
  179.         '입하''소만''망종''하지''소서''대서',
  180.         '입추''처서''백로''추분''한로''상강',
  181.         '입동''소설''대설''동지''소한''대한',
  182.         '입춘'
  183.     );
  184.  
  185.     /**
  186.      * 절기(한자) 데이터
  187.      * @var array 
  188.      */
  189.     protected $hmonth_st = array (
  190.         '立春''雨水''驚蟄''春分''淸明''穀雨',
  191.         '立夏''小滿''芒種''夏至''小暑''大暑',
  192.         '立秋''處暑''白露''秋分''寒露''霜降',
  193.         '立冬''小雪''大雪''冬至''小寒''大寒',
  194.         '立春'
  195.     );
  196.  
  197.     /**
  198.      * 60간지 데이터
  199.      * @var array 
  200.      */
  201.     protected $ganji = array (
  202.         '갑자''을축''병인''정묘''무진''기사''경오''신미''임신''계유''갑술''을해',
  203.         '병자''정축''무인''기묘''경진''신사''임오''계미''갑신''을유''병술''정해'
  204.         '무자''기축''경인''신묘''임진''계사''갑오''을미''병신''정유''무술''기해'
  205.         '경자''신축''임인''계묘''갑진''을사''병오''정미''무신''기유''경술''신해',
  206.         '임자''계축''갑인''을묘''병진''정사''무오''기미''경신''신유''임술''계해'
  207.     );
  208.     /**
  209.      * 60간지 한자 데이터
  210.      * @var array 
  211.      */
  212.     protected $hganji = array (
  213.         '甲子','乙丑','丙寅','丁卯','戊辰','己巳','庚午','辛未','壬申','癸酉','甲戌','乙亥',
  214.         '丙子','丁丑','戊寅','己卯','庚辰','辛巳','壬午','癸未','甲申','乙酉','丙戌','丁亥',
  215.         '戊子','己丑','庚寅','辛卯','壬辰','癸巳','甲午','乙未','丙申','丁酉','戊戌','己亥',
  216.         '庚子','辛丑','壬寅','癸卯','甲辰','乙巳','丙午','丁未','戊申','己酉','庚戌','辛亥',
  217.         '壬子','癸丑','甲寅','乙卯','丙辰','丁巳','戊午','己未','庚申','辛酉','壬戌','癸亥'
  218.     );
  219.  
  220.     /**
  221.      * 요일 데이터
  222.      * @var array 
  223.      */
  224.     protected $week = array ('일','월','화','수','목','금','토');
  225.     /**
  226.      * 요일 한자 데이터
  227.      * @var array 
  228.      */
  229.     protected $hweek = array ('日','月','火','水','木','金','土');
  230.     /**
  231.      * 28일 데이터
  232.      * @var array 
  233.      */
  234.     protected $s28days = array (
  235.         '角','亢','氐','房','心','尾','箕',
  236.         '斗','牛','女','虛','危','室','壁',
  237.         '奎','婁','胃','昴','畢','觜','參',
  238.         '井','鬼','柳','星','張','翼','軫'
  239.     );
  240.     protected $s28days_hangul = array (
  241.         '각''항''저''방''심''미''기',
  242.         '두''우''녀''허''위''실''벽',
  243.         '규''수''위''묘''필''자''삼',
  244.         '정''귀''류''성''장''익''진'
  245.     );
  246.     /**#@-*/
  247.     // }}}
  248.  
  249.     // {{{ +-- protected (int) div ($a, $b)
  250.     /**
  251.      * 정수 몫을 반환
  252.      *
  253.      * @access protected
  254.      * @return int 
  255.      * @param int 
  256.      * @param int 
  257.      */
  258.     protected function div ($a$b{
  259.         return (int) ($a $b);
  260.     }
  261.     // }}}
  262.  
  263.     // {{{ +-- protected (int) disptimeday ($year, $month, $day)
  264.     /**
  265.      * year의 1월 1일부터 해당 일자까지의 날자수
  266.      *
  267.      * @access public
  268.      * @return int 날자수
  269.      * @param  int 
  270.      * @param  int 
  271.      * @param  int 
  272.      */
  273.     protected function disptimeday ($year$month$day{
  274.         $e $i 0;
  275.  
  276.         for $i=1$i<$month$i++ {
  277.             $e += 31;
  278.             if $i == || $i == || $i == || $i == || $i == 11 )
  279.                 $e--;
  280.  
  281.             if $i == {
  282.                 $e -= 2;
  283.                 if ( ($year 4== $e++;
  284.                 if ( ($year 100== $e--;
  285.                 if ( ($year 400== $e++;
  286.                 if ( ($year 4000== $e--;
  287.             }
  288.         }
  289.         $e += $day;
  290.  
  291.         return $e;
  292.     }
  293.     // }}}
  294.  
  295.     // {{{ +-- protected (int) disp2days ($y1, $m1, $d1, $y2, $m2, $d2)
  296.     /**
  297.      * y1,m1,d1일부터 y2,m2,d2까지의 일수 계산
  298.      *
  299.      * @access protected
  300.      * @return int 날자수
  301.      * @param int from year
  302.      * @param int from month
  303.      * @param int from day
  304.      * @param int until year
  305.      * @param int until month
  306.      * @param int until day
  307.      */
  308.     protected function disp2days ($y1$m1$d1$y2$m2$d2{
  309.         $p1 $p2 $pn1 $pp1 $pp2 $pr $dis $ppp1 $ppp2 $k 0;
  310.  
  311.         if $y2 $y1 {
  312.             $p1  $this->disptimeday ($y1$m1$d1);
  313.             $p1n $this->disptimeday ($y11231);
  314.             $p2  $this->disptimeday ($y2$m2$d2);
  315.             $pp1 $y1;
  316.             $pp2 $y2;
  317.             $pr  = -1;
  318.         else {
  319.             $p1  $this->disptimeday ($y2$m2$d2);
  320.             $p1n $this->disptimeday ($y21231);
  321.             $p2  $this->disptimeday ($y1$m1$d1);
  322.             $pp1 $y2;
  323.             $pp2 $y1;
  324.             $pr  1;
  325.         }
  326.  
  327.         if $y2 == $y1 )
  328.             $dis $p2 $p1;
  329.         else {
  330.             $dis $p1n $p1;
  331.             $ppp1 $pp1 1;
  332.             $ppp2 $pp2 1;
  333.  
  334.             for $k $ppp1$k <= $ppp2$k++ {
  335.                 if $k == -2000 && $ppp2 1990 {
  336.                     $dis += 1457682;
  337.                     $k 1991;
  338.                 else if $k == -1750 && $ppp2 1990 {
  339.                     $dis += 1366371;
  340.                     $k 1991;
  341.                 else if $k ==-1500 && $ppp2 1990 {
  342.                     $dis += 1275060;
  343.                     $k 1991;
  344.                 else if $k ==-1250 && $ppp2 1990 {
  345.                     $dis += 1183750;
  346.                     $k 1991;
  347.                 else if $k ==-1000 && $ppp2 1990 {
  348.                     $dis += 1092439;
  349.                     $k 1991;
  350.                 else if $k == -750 && $ppp2 1990 {
  351.                     $dis += 1001128;
  352.                     $k 1991;
  353.                 else if $k == -500 && $ppp2 1990 {
  354.                     $dis += 909818;
  355.                     $k 1991;
  356.                 else if $k == -250 && $ppp2 1990 {
  357.                     $dis += 818507;
  358.                     $k 1991;
  359.                 else if $k == && $ppp2 1990 {
  360.                     $dis += 727197;
  361.                     $k 1991;
  362.                 else if $k == 250 && $ppp2 1990 {
  363.                     $dis += 635887;
  364.                     $k 1991;
  365.                 else if $k == 500 && $ppp2 1990 {
  366.                     $dis += 544576;
  367.                     $k 1991;
  368.                 else if $k == 750 && $ppp2 1990 {
  369.                     $dis += 453266;
  370.                     $k 1991;
  371.                 else if $k == 1000 && $ppp2 1990 {
  372.                     $dis += 361955;
  373.                     $k 1991;
  374.                 else if $k == 1250 && $ppp2 1990 {
  375.                     $dis += 270644;
  376.                     $k 1991;
  377.                 else if $k == 1500 && $ppp2 1990 {
  378.                     $dis += 179334;
  379.                     $k 1991;
  380.                 else if $k == 1750 && $ppp2 1990 {
  381.                     $dis += 88023;
  382.                     $k 1991;
  383.                 }
  384.  
  385.                 $dis += $this->disptimeday ($k1231);
  386.             }
  387.  
  388.             $dis += $p2;
  389.             $dis *= $pr;
  390.         }
  391.  
  392.         return $dis;
  393.     }
  394.     // }}}
  395.  
  396.     // {{{ +-- protected (int) getminbytime ($uy, $umm, $ud, $uh, $umin, $y1, $mo1, $d1, $h1, $mm1)
  397.     /**
  398.      * uy,umm,ud,uh,umin과 y1,mo1,d1,h1,mm1사이의 시간(분)
  399.      * 
  400.      * @access protected
  401.      * @return int 
  402.      * @param int 
  403.      * @param int 
  404.      * @param int 
  405.      * @param int 
  406.      * @param int 
  407.      * @param int 
  408.      * @param int 
  409.      * @param int 
  410.      * @param int 
  411.      * @param int 
  412.      */
  413.     function getminbytime ($uy$umm$ud$uh$umin$y1$mo1$d1$h1$mm1{
  414.         $t 0;
  415.  
  416.         $dispday $this->disp2days ($uy$umm$ud$y1$mo1$d1);
  417.         $t $dispday 24 60 ($uh $h160 ($umin $mm1);
  418.  
  419.         return $t;
  420.     }
  421.     // }}}
  422.  
  423.     // {{{ +-- protected (array) getdatebymin ($tmin, $uyear, $umonth, $uday, $uhour, $umin)
  424.     /**
  425.      * uyear,umonth,uday,uhour,umin으로부터 tmin(분)떨이진 시점의
  426.      * 년월일시분(태양력) 구하는 프로시져
  427.      *
  428.      * @access public
  429.      * @return array 
  430.      * @param int 
  431.      * @param int 
  432.      * @param int 
  433.      * @param int 
  434.      * @param int 
  435.      * @param int 
  436.      */
  437.     protected function getdatebymin ($tmin$uyear$umonth$uday$uhour$umin{
  438.         $y1 $mo1 $d1 $h1 $mi1 $t 0;
  439.  
  440.         $y1 $uyear $this->div ($tmin525949);
  441.  
  442.         if $tmin {
  443.             $y1 += ;
  444.             do {
  445.                 $y1--;
  446.                 $t $this->getminbytime ($uyear$umonth$uday$uhour$umin$y11100);
  447.             while $t $tmin );
  448.  
  449.             $mo1 13 ;
  450.             do {
  451.                 $mo1--;
  452.                 $t $this->getminbytime ($uyear$umonth$uday$uhour$umin$y1$mo1100);
  453.             while $t $tmin );
  454.  
  455.             $d1 32;
  456.             do {
  457.                 $d1--;
  458.                 $t $this->getminbytime ($uyear$umonth$uday$uhour$umin$y1$mo1$d100);
  459.             while $t $tmin );
  460.  
  461.             $h1 24 ;
  462.             do {
  463.                 $h1--;
  464.                 $t $this->getminbytime ($uyear$umonth$uday$uhour$umin$y1$mo1$d1$h10);
  465.             while $t $tmin );
  466.  
  467.             $t $this->getminbytime $uyear$umonth$uday$uhour$umin$y1$mo1$d1$h10);
  468.             $mi1 =  $t $tmin;
  469.         else {
  470.             $y1 -= 2;
  471.             do {
  472.                 $y1++;
  473.                 $t $this->getminbytime ($uyear$umonth$uday$uhour$umin$y11100);
  474.             while $t >= $tmin );
  475.  
  476.             $y1--;
  477.             $mo1 0;
  478.             do {
  479.                 $mo1++;
  480.                 $t $this->getminbytime ($uyear$umonth$uday$uhour$umin$y1$mo1100);
  481.             while $t >= $tmin );
  482.  
  483.             $mo1--;
  484.             $d1 0;
  485.             do {
  486.                 $d1 $d1 1;
  487.                 $t $this->getminbytime ($uyear$umonth$uday$uhour$umin$y1$mo1$d100);
  488.             while $t >= $tmin );
  489.  
  490.             $d1--;
  491.             $h1 = -;
  492.             do {
  493.                 $h1++;
  494.                 $t $this->getminbytime ($uyear$umonth$uday$uhour$umin$y1$mo1$d1$h10);
  495.             while $t >= $tmin );
  496.  
  497.             $h1--;
  498.             $t $this->getminbytime ($uyear$umonth$uday$uhour$umin$y1$mo1$d1$h10);
  499.             $mi1 $t $tmin;
  500.         }
  501.  
  502.         return array ($y1$mo1$d1$h1$mi1);
  503.     }
  504.     // }}}
  505.  
  506.     // {{{ +-- protected (array) sydtoso24yd ($soloryear, $solormonth, $solorday, $solorhour, $solormin)
  507.     /**
  508.      * 그레고리력의 년월시일분으로 60년의 배수, 세차, 월건(태양력),
  509.      * 일진, 시주를 구함
  510.      *
  511.      * @access public
  512.      * @return array 
  513.      *
  514.      *    <pre>
  515.      *    Array
  516.      *    (
  517.      *        [0] => -17  // 60년의 배수
  518.      *        [1] => 29   // 60간지의 연도 배열 index
  519.      *        [2] => 55   // 60간지의 월 배열 index
  520.      *        [3] => 11   // 60간지의 일 배열 index
  521.      *        [4] => 20   // 60간지의 시 배열 index
  522.      *    )
  523.      *    </pre>
  524.      * 
  525.      * @param int 
  526.      * @param int 
  527.      * @param int 
  528.      * @param int 
  529.      * @param int 
  530.      */
  531.     protected function sydtoso24yd ($soloryear$solormonth$solorday$solorhour$solormin{
  532.         $displ2min $this->getminbytime (
  533.             $this->unityear$this->unitmonth$this->unitday$this->unithour$this->unitmin,
  534.             $soloryear$solormonth$solorday$solorhour$solormin
  535.         );
  536.         $displ2day $this->disp2days (
  537.             $this->unityear$this->unitmonth$this->unitday$soloryear,
  538.             $solormonth$solorday
  539.         );
  540.  
  541.         // 무인년(1996)입춘시점부터 해당일시까지 경과년수
  542.         $so24 $this->div ($displ2min525949);
  543.  
  544.         if $displ2min >= )
  545.             $so24++;
  546.  
  547.         // 년주 구하기
  548.         $so24year ($so24 60* -1;
  549.         $so24year += 12;
  550.         if $so24year )
  551.             $so24year += 60;
  552.         else if $so24year 59 )
  553.             $so24year -= 60;
  554.  
  555.         $monthmin100 $displ2min 525949;
  556.         $monthmin100 525949 $monthmin100;
  557.  
  558.         if $monthmin100 )
  559.             $monthmin100 += 525949;
  560.         else if $monthmin100 >= 525949 )
  561.             $monthmin100 -= 525949;
  562.  
  563.         for $i=0$i<=11$i++ {
  564.             $j $i 2;
  565.             if ( ($this->month[$j<= $monthmin100&& ($monthmin100 $this->month[$j+2]))
  566.                 $so24month $i;
  567.         };
  568.  
  569.         // 월주 구하기
  570.         $i $so24month;
  571.         $t $so24year 10 ;
  572.         $t %= ;
  573.         $t $t 12 $i;
  574.         $so24month $t ;
  575.         if $so24month 59 
  576.             $so24month -= 60;
  577.  
  578.         $so24day $displ2day 60;
  579.  
  580.         // 일주 구하기
  581.         $so24day *= -1;
  582.         $so24day += 7;
  583.         if $so24day )
  584.             $so24day += 60;
  585.         else if $so24day 59 )
  586.             $so24day -= 60;
  587.  
  588.         if ( ($solorhour == || $solorhour == 1&& $solormin 30 )
  589.             $i 0;
  590.  
  591.         else if ( ($solorhour == && $solormin >= 30|| $solorhour == 2
  592.             || ($solorhour == && $solormin 30) )
  593.             $i 1;
  594.  
  595.         else if ( ($solorhour == && $solormin >= 30|| $solorhour == 4
  596.             || ($solorhour == && $solormin 30) )
  597.             $i 2;
  598.  
  599.         else if ( ($solorhour == && $solormin >= 30|| $solorhour == 6
  600.             || ($solorhour == && $solormin 30) )
  601.             $i 3;
  602.  
  603.         else if ( ($solorhour == && $solormin >= 30|| $solorhour == 8
  604.             || ($solorhour == && $solormin 30) )
  605.             $i 4;
  606.  
  607.         else if ( ($solorhour == && $solormin >= 30|| $solorhour == 10
  608.             || ($solorhour == 11 && $solormin 30) )
  609.             $i 5;
  610.  
  611.         else if ( ($solorhour == 11 && $solormin >= 30|| $solorhour == 12
  612.             || ($solorhour == 13 && $solormin 30) )
  613.             $i 6;
  614.  
  615.         else if ( ($solorhour == 13 && $solormin >= 30|| $solorhour == 14
  616.             || ($solorhour == 15 && $solormin 30) )
  617.             $i 7;
  618.  
  619.         else if ( ($solorhour == 15 && $solormin >= 30|| $solorhour == 16
  620.             || ($solorhour == 17 && $solormin 30) )
  621.             $i 8;
  622.  
  623.         else if ( ($solorhour == 17 && $solormin >= 30|| $solorhour == 18
  624.             || ($solorhour == 19 && $solormin 30) )
  625.             $i 9;
  626.  
  627.         else if ( ($solorhour == 19 && $solormin >= 30|| $solorhour == 20
  628.             || ($solorhour == 21 && $solormin 30) )
  629.             $i 10;
  630.  
  631.         else if ( ($solorhour == 21 && $solormin >= 30|| $solorhour == 22
  632.             || ($solorhour == 23 && $solormin 30) )
  633.             $i 11;
  634.  
  635.         else if $solorhour == 23 && $solormin >= 30 )
  636.         {
  637.             $so24day++;
  638.             if $so24day == 60 )
  639.                 $so24day 0;
  640.             $i=0;
  641.         }
  642.  
  643.         $t $so24day 10;
  644.         $t %= 5;
  645.         $t $t 12 $i;
  646.         $so24hour $t;
  647.  
  648.         return array ($so24$so24year$so24month$so24day$so24hour);
  649.     }
  650.     // }}}
  651.  
  652.     // {{{ +-- protected (array) solortoso24 ($soloryear, $solormonth, $solorday, $solorhour, $solormin)
  653.     /**
  654.      * 절기 시간 구하기
  655.      *
  656.      * 그레고리력의 년월일시분이 들어있는 절기의 이름번호,
  657.      * 년월일시분을 얻음
  658.      *
  659.      * @access protected
  660.      * @return array 
  661.      * @param int 
  662.      * @param int 
  663.      * @param int 
  664.      * @param int 
  665.      * @param int 
  666.      */
  667.     protected function solortoso24 ($soloryear$solormonth$solorday$solorhour$solormin{
  668.         list ($so24$so24year$so24month$so24day$so24hour=
  669.             $this->sydtoso24yd ($soloryear$solormonth$solorday$solorhour$solormin);
  670.  
  671.         $displ2min $this->getminbytime (
  672.             $this->unityear$this->unitmonth$this->unitday$this->unithour$this->unitmin,
  673.             $soloryear$solormonth$solorday$solorhour$solormin
  674.         );
  675.  
  676.         # 이거 고민좀 해 봐야 할 듯!!
  677.         #$monthmin100 = $displ2min % 525949;
  678.         #$monthmin100 = 525949 - $monthmin100;
  679.         $monthmin100 ($displ2min 525949* -1;
  680.  
  681.         if $monthmin100 )
  682.             $monthmin100 += 525949;
  683.         else if $monthmin100 >= 525949 )
  684.             $monthmin100 $monthmin 525949;
  685.  
  686.         $i $so24month 12 2;
  687.         if $i == -$i 10;
  688.         else if $i == -$i 11;
  689.  
  690.         $inginame  $i ;
  691.         $midname   $i 1;
  692.         $outginame $i 2;
  693.  
  694.         $j $i 2;
  695.         $tmin $displ2min ($monthmin100 $this->month[$j]);
  696.  
  697.         list ($y1$mo1$d1$h1$mi1=
  698.             $this->getdatebymin ($tmin$this->unityear$this->unitmonth$this->unitday$this->unithour$this->unitmin);
  699.  
  700.         $ingiyear  $y1;
  701.         $ingimonth $mo1;
  702.         $ingiday   $d1;
  703.         $ingihour  $h1;
  704.         $ingimin   $mi1;
  705.  
  706.         $tmin $displ2min ($monthmin100 $this->month[$j+1]);
  707.         list ($y1$mo1$d1$h1$mi1=
  708.             $this->getdatebymin ($tmin$this->unityear$this->unitmonth$this->unitday$this->unithour$this->unitmin);
  709.  
  710.         $midyear  $y1;
  711.         $midmonth $mo1;
  712.         $midday   $d1;
  713.         $midhour  $h1;
  714.         $midmin   $mi1;
  715.  
  716.         $tmin $displ2min ($monthmin100 $this->month[$j+2]);
  717.         list ($y1$mo1$d1$h1$mi1=
  718.             $this->getdatebymin ($tmin$this->unityear$this->unitmonth$this->unitday$this->unithour$this->unitmin);
  719.  
  720.         $outgiyear  $y1;
  721.         $outgimonth $mo1;
  722.         $outgiday   $d1;
  723.         $outgihour  $h1;
  724.         $outgimin   $mi1;
  725.  
  726.         return array (
  727.             $inginame$ingiyear$ingimonth$ingiday$ingihour$ingimin,
  728.             $midname$midyear$midmonth$midday$midhour$midmin,
  729.             $outginame$outgiyear$outgimonth$outgiday$outgihour$outgimin
  730.         );
  731.     }
  732.     // }}}
  733.  
  734.     // {{{ +-- protected (int) degreelow ($d)
  735.     /**
  736.      * 미지의 각도를 0~360도 이내로 만듬
  737.      *
  738.      * @access protected
  739.      * @return int 
  740.      * @param int 
  741.      */
  742.     protected function degreelow ($d{
  743.         $di $d;
  744.         $i $this->div ((int) $d360);
  745.         $di $d ($i 360);
  746.  
  747.         while $di >= 360 || $di {
  748.             if $di )
  749.                 $di -= 360;
  750.             else
  751.                 $di += 360;
  752.         }
  753.  
  754.         return $di;
  755.     }
  756.     // }}}
  757.  
  758.     // {{{ +-- protected (int) moonsundegree ($day)
  759.     /**
  760.      * 태양황력과 달황경의 차이 (1996 기준)
  761.      *
  762.      * @access protected
  763.      * @return int 
  764.      * @param int 
  765.      */
  766.     protected function moonsundegree ($day{
  767.         $sl = (float) ($day 0.98564736 278.956807);                // 평균 황경
  768.         $smin 282.869498 0.00004708 $day;                        // 근일점 황경
  769.         $sminangle 3.14159265358979 ($sl $smin180;           // 근점이각
  770.         $sd 1.919 sin ($sminangle0.02 sin ($sminangle);  // 황경차
  771.         $sreal $this->degreelow ($sl $sd);                         // 진황경
  772.  
  773.         $ml 27.836584 13.17639648 $day;                          // 평균 황경
  774.         $mmin 280.425774 0.11140356 $day;                        // 근지점 황경
  775.         $mminangle 3.14159265358979 ($ml $mmin180;           // 근점이각
  776.         $msangle 202.489407 0.05295377 $day;                     // 교점황경
  777.         $msdangle 3.14159265358979 ($ml $msangle180;
  778.         $md 5.06889 sin ($mminangle)
  779.             + 0.146111 sin ($mminangle)
  780.             + 0.01 sin ($mminangle)
  781.             - 0.238056 sin ($sminangle)
  782.             - 0.087778 sin ($mminangle $sminangle)
  783.             + 0.048889 sin ($mminangle $sminangle)
  784.             - 0.129722 sin ($msdangle)
  785.             - 0.011111 sin ($msdangle $mminangle)
  786.             - 0.012778 sin ($msdangle $mminangle);             // 황경차
  787.         $mreal $this->degreelow ($ml $md);                         // 진황경
  788.         $re $this->degreelow ($mreal $sreal);
  789.  
  790.         return $re;
  791.     }
  792.     // }}}
  793.  
  794.     // {{{ +-- protected (array) getlunarfirst ($syear, $smonth, $sday)
  795.     /**
  796.      * 그레고리력 년월일이 들어있는 태음월의 시작합삭일지, 망일시,
  797.      * 끝합삭일시를 구함
  798.      *
  799.      * @access protected
  800.      * @return array 
  801.      *
  802.      *    <pre>
  803.      *    Array
  804.      *    (
  805.      *        [0] => 2013    // 시작 합삭 년도
  806.      *        [1] => 7       // 시작 합삭 월
  807.      *        [2] => 8       // 시작 합삭 일
  808.      *        [3] => 16      // 시작 합삭 시
  809.      *        [4] => 15      // 시작 합삭 분
  810.      *        [5] => 2013    // 망 연도
  811.      *        [6] => 7       // 망 월
  812.      *        [7] => 23      // 망 일
  813.      *        [8] => 2       // 망 시
  814.      *        [9] => 59      // 망 분
  815.      *        [10] => 2013   // 끝 합삭 년도
  816.      *        [11] => 8      // 끝 합삭 월
  817.      *        [12] => 7      // 끝 합삭 일
  818.      *        [13] => 6      // 끝 합삭 시
  819.      *        [14] => 50     // 끝 합삭 분
  820.      *    )
  821.      *    </pre>
  822.      *
  823.      * @param int 
  824.      * @param int 
  825.      * @param int 
  826.      */
  827.     protected function getlunarfirst ($syear$smonth$sday{
  828.         $dm  $this->disp2days ($syear$smonth$sday19951231);
  829.         $dem $this->moonsundegree ($dm);
  830.  
  831.         $d  $dm;
  832.         $de $dem;
  833.  
  834.         while $de 13.5 {
  835.             $d--;
  836.             $de $this->moonsundegree ($d);
  837.         };
  838.  
  839.         while $de {
  840.             $d -= 0.04166666666;
  841.             $de $this->moonsundegree ($d);
  842.         };
  843.  
  844.         while $de 359.99 {
  845.             $d -= 0.000694444;
  846.             $de $this->moonsundegree ($d);
  847.         };
  848.  
  849.         $d += 0.375;
  850.         $d *= 1440;
  851.         $i= (int) $d * -1;
  852.         list ($year$month$day$hour$min)$this->getdatebymin ($i1995123100);
  853.  
  854.         $d  $dm;
  855.         $de $dem;
  856.  
  857.         while $de 346.5 {
  858.             $d++;
  859.             $de $this->moonsundegree ($d);
  860.         };
  861.  
  862.         while $de 359 {
  863.             $d += 0.04166666666;
  864.             $de $this->moonsundegree ($d);
  865.         };
  866.  
  867.         while $de 0.01 {
  868.             $d += 0.000694444;
  869.             $de $this->moonsundegree ($d);
  870.         };
  871.  
  872.         $pd $d;
  873.         $d  += 0.375;
  874.         $d  *= 1440;
  875.         $i  = (int) $d * -1;
  876.         list ($year2$month2$day2$hour2$min2$this->getdatebymin ($i1995123100);
  877.  
  878.         if $smonth == $month2 && $sday == $day2 {
  879.             $year  $year2;
  880.             $month $month2;
  881.             $day   $day2;
  882.             $hour  $hour2;
  883.             $min   $min2;
  884.  
  885.             $d $pd 26;
  886.  
  887.             $de $this->moonsundegree ($d);      
  888.             while $de 346.5{
  889.                 $d++;
  890.                 $de $this->moonsundegree ($d);
  891.             };
  892.  
  893.             while $de 359 {
  894.                 $d += 0.04166666666;
  895.                 $de $this->moonsundegree ($d);
  896.             };
  897.  
  898.             while $de 0.01 {
  899.                 $d += 0.000694444;
  900.                 $de $this->moonsundegree ($d);
  901.             };
  902.  
  903.             $d += 0.375;
  904.             $d *= 1440;
  905.             $i = (int) $d * -1;
  906.             list ($year2$month2$day2$hour2$min2$this->getdatebymin ($i1995123100);
  907.         };
  908.  
  909.         $d $this->disp2days ($year$month$day19951231);
  910.         $d += 12;
  911.  
  912.         $de $this->moonsundegree ($d);
  913.         while $de 166.5 {
  914.             $d++;
  915.             $de $this->moonsundegree ($d);
  916.         };
  917.         while $de 179 {
  918.             $d += 0.04166666666;
  919.             $de $this->moonsundegree ($d);
  920.         };
  921.         while $de 179.999 {
  922.             $d += 0.000694444;
  923.             $de $this->moonsundegree ($d);
  924.         };
  925.  
  926.         $d += 0.375;
  927.         $d *= 1440;
  928.         $i = (int) $d * -1;
  929.         list ($year1$month1$day1$hour1$min1$this->getdatebymin ($i1995123100);
  930.  
  931.         return array (
  932.             $year$month$day$hour$min,
  933.             $year1$month1$day1$hour1$min1,
  934.             $year2$month2$day2$hour2$min2
  935.         );
  936.     }
  937.     // }}}
  938.  
  939.     // {{{ +-- protected (array) solartolunar ($solyear,$solmon,$solday)
  940.     /**
  941.      * 양력 날자를 음력 날자로 변환
  942.      *
  943.      * @access protected
  944.      * @return array 
  945.      *
  946.      *    <pre>
  947.      *    Array
  948.      *    (
  949.      *        [0] => 2013   // 음력 연도
  950.      *        [1] => 6      // 음력 월
  951.      *        [2] => 9      // 음력 일
  952.      *        [3] =>        // 음력 윤달 여부 (boolean)
  953.      *        [4] => 1      // 평달(false)/큰달(true) 여부 (boolean)
  954.      *    )
  955.      *    </pre>
  956.      *
  957.      * @param int 
  958.      * @param int 
  959.      * @param int 
  960.      */
  961.     protected function solartolunar ($solyear$solmon$solday{
  962.         list ($smoyear$smomonth$smoday$smohour$smomin,
  963.             $y0$mo0$d0$h0$mi0$y1$mo1$d1$h1$mi1)
  964.             = $this->getlunarfirst ($solyear$solmon$solday);
  965.  
  966.         $lday $this->disp2days ($solyear$solmon$solday$smoyear$smomonth$smoday)+1;
  967.  
  968.         $i=abs ($this->disp2days ($smoyear$smomonth$smoday$y1$mo1$d1));
  969.         if $i==30 )
  970.             $largemonth 1# 대월
  971.         if $i==29 )
  972.             $largemonth 0# 소월
  973.  
  974.         list ($inginame$ingiyear$ingimonth$ingiday$ingihour$ingimin,
  975.             $midname1$midyear1$midmonth1$midday1$midhour1$midmin1,
  976.             $outginame$outgiyear$outgimonth$outgiday$outgihour$outgimin)
  977.             = $this->solortoso24 ($smoyear$smomonth$smoday$smohour$smomin);
  978.  
  979.         $midname2 $midname1 2;
  980.         if $midname2 24 )
  981.             $midname2=1;
  982.         $s0 $this->month[$midname2$this->month[$midname1];
  983.         if $s0 )
  984.             $s0 += 525949;
  985.         $s0 *= -1;
  986.  
  987.         list ($midyear2$midmonth2$midday2$midhour2$midmin2)
  988.             = $this->getdatebymin ($s0$midyear1$midmonth1$midday1$midhour1$midmin1);
  989.  
  990.         if ( ($midmonth1 == $smomonth && $midday1 >= $smoday|| ($midmonth1 == $mo1 && $midday1 $d1) ) {
  991.             $lmonth  ($midname1 11;
  992.             $leap 0;
  993.         else {
  994.             if ( ($midmonth2 == $mo1 && $midday2<$d1|| ($midmonth2 == $smomonth && $midday2 >= $smoday) ) {
  995.                 $lmonth   ($midname2 11;
  996.                 $leap 0;
  997.             else {
  998.                 if (  $smomonth $midmonth2 && $midmonth2 $mo1 {
  999.                     $lmonth   ($midname2 1/1;
  1000.                     $leap 0;
  1001.                 else {
  1002.                     $lmonth   ($midname1 11;
  1003.                     $leap =1;
  1004.                 }
  1005.             }
  1006.         }
  1007.  
  1008.  
  1009.         $lyear $smoyear;
  1010.         if $lmonth == 12 && $smomonth == )
  1011.             $lyear--;
  1012.  
  1013.         if ( ($lmonth == 11 && $leap == 1|| $lmonth == 12 || $lmonth {
  1014.             list ($midyear1$midmonth1$midday1$midhour1$midmin1)
  1015.                 = $this->getdatebymin (2880$smoyear$smomonth$smoday$smohour$smomin);
  1016.  
  1017.             list ($outgiyear$outgimonth$outgiday$lnp$lnp2)
  1018.                 = $this->solartolunar ($midyear1$midmonth1$midday1);
  1019.  
  1020.             $outgiday $lmonth 1;
  1021.             if $outgiday== )
  1022.                 $outgiday 12;
  1023.  
  1024.             if $outgiday == $outgimonth {
  1025.                 if $leap == )
  1026.                     $leap=0;
  1027.             else {
  1028.                 if $leap == {
  1029.                     if $lmonth != $outgimonth {
  1030.                         $lmonth--;
  1031.                         if $lmonth == 
  1032.                             $lyear--;
  1033.                             $lmonth 12;
  1034.                         };
  1035.                         $leap 0;
  1036.                     };
  1037.                 else {
  1038.                     if $lmonth == $outgimonth {
  1039.                         $leap 1;
  1040.                     else {  
  1041.                         $lmonth--;
  1042.                         if $lmonth == {
  1043.                             $lyear--;
  1044.                             $lmonth 12;
  1045.                         }
  1046.                     }
  1047.                 }
  1048.             }
  1049.  
  1050.         }
  1051.  
  1052.         return array ($lyear$lmonth$lday$leap true false$largemonth true false);
  1053.     }
  1054.     // }}}
  1055.  
  1056.     // {{{ +-- protected (array) lunartosolar ($lyear, $lmonth, $lday, $leap)
  1057.     /**
  1058.      * 음력 날자를 양력 날자로 변환
  1059.      *
  1060.      * @access protected
  1061.      * @return array 
  1062.      *
  1063.      *    <pre>
  1064.      *    Array
  1065.      *    (
  1066.      *        [0] => 2013   // 양력 연도
  1067.      *        [1] => 6      // 양력 월
  1068.      *        [2] => 9      // 양력 일
  1069.      *    )
  1070.      *    </pre>
  1071.      *
  1072.      * @param int  년
  1073.      * @param int  월
  1074.      * @param int  일
  1075.      * @param bool 음력 윤달 여부
  1076.      */
  1077.     protected function lunartosolar ($lyear$lmonth$lday$leap false{
  1078.         list ($inginame$ingiyear$ingimonth$ingiday$ingihour$ingimin,
  1079.             $midname$midyear$midmonth$midday$midhour$midmin,
  1080.             $outginame$outgiyear$outgimonth$outgiday$outgihour$outgimin)
  1081.             = $this->solortoso24 ($lyear,2,15,0,0);
  1082.  
  1083.         $midname $lmonth ;
  1084.         $tmin $this->month[$midname* -1;
  1085.         list ($midyear$midmonth$midday$midhour$midmin
  1086.             = $this->getdatebymin ($tmin$ingiyear$ingimonth$ingiday$ingihour$ingimin);
  1087.  
  1088.         list $outgiyear$outgimonth$outgiday$hour$min,
  1089.             $yearm$monthm1$daym$hourm$minm,
  1090.             $year1$month1$day1$hour1$min1 )
  1091.             = $this->getlunarfirst ($midyear$midmonth$midday);
  1092.  
  1093.         list ($lyear2$lmonth2$lday2$lnp$lnp2
  1094.             = $this->solartolunar ($outgiyear$outgimonth$outgiday);
  1095.  
  1096.         if $lyear2 == $lyear && $lmonth == $lmonth2 {
  1097.             // 평달, 윤달
  1098.             $tmin = -1440 $lday 10;
  1099.             list ($syear$smonth$sday$hour$min)
  1100.                 = $this->getdatebymin ($tmin$outgiyear$outgimonth$outgiday00);
  1101.  
  1102.  
  1103.             if $leap {
  1104.                 list ($lyear2$lmonth2$lday2$lnp$lnp2)
  1105.                     = $this->solartolunar ($year1$month1$day1);
  1106.                 if $lyear2==$lyear && $lmonth==$lmonth2 {
  1107.                     $tmin = -1440 $lday 10;
  1108.                     list ($syear$smonth$sday$hour$min)
  1109.                         = $this->getdatebymin ($tmin$year1$month1$day100);
  1110.                 }
  1111.             }
  1112.         else {
  1113.             // ㅈ우기가 두번든 달의 전후
  1114.             list ($lyear2$lmonth2$lday2$lnp$lnp2)
  1115.                 = $this->solartolunar ($year1$month1$day1);
  1116.             if $lyear2 == $lyear && $lmonth == $lmonth2 {
  1117.                 $tmin = -1440 $lday 10;
  1118.                 list ($syear$smonth$sday$hour$min)
  1119.                     = $this->getdatebymin ($tmin$year1$month1$day100);
  1120.             }
  1121.         }
  1122.  
  1123.         return array ($syear$smonth$sday);
  1124.     }
  1125.     // }}}
  1126.  
  1127.     // {{{ +-- protected (int) getweekday ($syear, $smonth, $sday)
  1128.     /**
  1129.      * 그레고리력 날자를 요일의 배열 번호로 변환
  1130.      *
  1131.      * @access protected
  1132.      * @return int 
  1133.      * @param int 
  1134.      * @param int 
  1135.      * @param int 
  1136.      */
  1137.     protected function getweekday ($syear$smonth$sday{
  1138.         $d $this->disp2days (
  1139.             $syear$smonth$sday,
  1140.             $this->unityear$this->unitmonth$this->unitday
  1141.         );
  1142.  
  1143.         $i $this->div ($d7);
  1144.         $d -= $i 7;
  1145.  
  1146.         while $d || $d {
  1147.             if ($d 6)
  1148.                 $d -= 7;
  1149.             else
  1150.                 $d += 7;
  1151.         }
  1152.  
  1153.         if $d )
  1154.             $d += 7;
  1155.  
  1156.         return $d;
  1157.     }
  1158.     // }}}
  1159.  
  1160.     // {{{ +-- protected (int) get28sday ($syear, $smonth, $sday)
  1161.     /**
  1162.      * 그레고리력의 날자에 대한 28수를 구함
  1163.      *
  1164.      * @access protected
  1165.      * @return int 
  1166.      * @param int 
  1167.      * @param int 
  1168.      * @param int 
  1169.      */
  1170.     protected function get28sday ($syear$smonth$sday{
  1171.         $d $this->disp2days (
  1172.             $syear$smonth$sday,
  1173.             $this->unityear$this->unitmonth$this->unitday
  1174.         );
  1175.  
  1176.         $i $this->div ($d28);
  1177.         $d -= $i 28;
  1178.  
  1179.         while $d 27 || $d {
  1180.             if ($d 27)
  1181.                 $d -= 28;
  1182.             else
  1183.                 $d += 28;
  1184.         }
  1185.  
  1186.         if $d )
  1187.             $d += 7;
  1188.  
  1189.         $d -= 11;
  1190.  
  1191.         if $d )
  1192.             $d += 28;
  1193.  
  1194.         return $d;
  1195.     }
  1196.     // }}}
  1197. }
  1198.  
  1199. /*
  1200.  * Local variables:
  1201.  * tab-width: 4
  1202.  * c-basic-offset: 4
  1203.  * End:
  1204.  * vim: set filetype=php noet sw=4 ts=4 fdm=marker:
  1205.  * vim600: noet sw=4 ts=4 fdm=marker
  1206.  * vim<600: noet sw=4 ts=4
  1207.  */
  1208. ?>

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