{@ $link_path = getUrl('','mid',$mid,'dummy',1)} {@ $XE_path = getUrl('')} {@ $today_bgcolor=yellow} {@ $day_bgcolor=aliceblue} {@ $day_bgcolor=beige} link_path; $xepath = $__Context->XE_path; $skinpath = $xepath."modules/board/skins/xe_board_planner123/"; // 스킨 설치 경로지정 //echo $linkpath; //echo $skinpath; ?>
3 ) { $pOption=1; // 간지옵션 } //require_once 'class.calendar.php'; //require_once 'class.solar.php'; //require_once 'class.lunar.php'; //include 'function_calendar_month.php'; ?> ## - http://linuxchannel.net/ ## ## [changes] ## - 2009.06.08: some ## - 2007.07.28 : support win32 PHP4(on Microsoft Windows) and Unix ## - 2005.04.12 : new build ## ## [valid date] ## - unix timestamp base: 1902-01-01 00:00:00 <= date <= 2037-12-31 23:59:59 (guess) ## - JD(Julian Day) base: BC 4713-01-01 12:00 GMT <= Gregorian date <= AD 9999 (guess) ## ## [download & online source view] ## - http://ftp.linuxchannel.net/devel/php_calendar/ ## ## [demo] ## - http://linuxchannel.net/gaggle/calendar.php ## ## [references] ## - http://www.linuxchannel.net/docs/solar-24terms.txt ## - http://www.linuxchannel.net/docs/lunar.txt ## - http://ftp.linuxchannel.net/devel/php_solar/ ## - http://ftp.linuxchannel.net/devel/php_lunar/ ## - http://www.merlyn.demon.co.uk/ // Astronomy and Astronautics ## - http://www.boogle.com/info/cal-overview.html ## ## [unit and format] ## - date(ZONE) <-> JD(TT) : calcurated that date to JD(+64), JD to date(-64) ## - utime(ZONE) <-> JD(TT): calcurated that utime to JD(-64), JD to utime(+64) ## - date(ZONE) <-> utime(ZONE) : none ## * ZONE is local system time zone, such as KST, GMT ## * KST - 9H = GMT, GMT + 12H = UT, UT - delta T = TT ## * JD(TT) is adapted delta 'T(J2000.0 is -64)' from UT(= GMT + 12H) ## ## [compare 1. PHP4(win32) internal functions VS this method(object)] ## - time() - ## - date() _date() // private, base on unix timestamp, BC 4313 ~ AD 9999(guess) ## - mktime() _mktime() // private, support native value, BC 4313 ~ AD 9999(guess) ## ## [compare 2. PHP4(win32) calendar module VS this method(object)] ## - gregoriantojd() mkjd() // public, support hour, minute, seconds, BC 4313 ~ AD 9999(guess) ## - jdtogregorian() date() // public, same above, but same as `date()' ## - jddayofweek() jddayofweek // public, similar ## - cal_days_in_month() days_in_month() // public, similar ## - unixtojd() _utime2jd() // private, same above ## - jdtounix() _jd2utime() // private, same above ## ## [usage] -- see that last row of this source ## $jd = calendar123::mkjd(23,59,59,12,31,1901); ## echo calendar123::date('Y-m-d H:i:s T',$jd); ## class calendar123 { ## private, get Julian day -- same as gregoriantojd() ## ## http://en.wikipedia.org/wiki/Julian_day ## http://ko.wikipedia.org/wiki/%EC%9C%A8%EB%A6%AC%EC%9A%B0%EC%8A%A4%EC%9D%BC ## ftp://ssd.jpl.nasa.gov/pub/eph/export/C-versions/hoffman/ ## http://blog.jidolstar.com/482 ## ## Julian date ## JD 0.0 => BC 4713-01-01 12:00 GMT <= BC 4713-01-01 21:00 KST ## function &_getjd($Y, $M=1, $D=1, $H=21, $I=0, $S=0, $tojulian=FALSE) { $H -= date('Z')/3600; // local zone to GMT if(func_num_args() < 3) // Y is unix_timestamp { list($Y,$M,$D,$H,$I,$S) = explode(' ',calendar123::_date('Y n j G i s',$Y-date('Z'))); } if($M < 3) { $M += 12; $Y--; } $S += 64; // is J2000.0 delta 'T', patch san2@2007.07.28 $D += ($H/24.0) + ($I/1440.0) + ($S/86400.0); $A = floor($Y/100.0); $B = $tojulian ? 0 : (2.0 - $A + floor($A/4.0)); // juliantojd() $B = 0 $JD= sprintf('%.13f',floor(365.25*($Y+4716.0))+floor(30.6001*($M+1.0))+$D+$B-1524.5); $D = sprintf('%.13f',$JD-2451545.0); // float, number of days $J = sprintf('%.4f',2000.0+($D/365.25)); // // Jxxxx.xxxx format $T = sprintf('%.13f',$D/36525.0); // // Julian century return array($JD,$J,$D,$T); } ## private, get date(gregorian) from JD -- same as jdtogregorian() ## ## JD to `YYYY MM DD HH II SS', JD is UT ## function &_todate($JD) { // JD >= 2299160.5 gregorian $JD += date('Z')/86400; // JD to local zone(JD) $JD -= 64/86400; // is J2000.0 delta 'T', patch san2@2007.07.28 $Z = $JD + 0.5; // float $W = (int)(($Z-1867216.25) / 36524.25); $X = (int)($W / 4); $A = (int)($Z + 1 + $W - $X); $B = (int)($A + 1524); $C = (int)(($B-122.1) / 365.25); $D = (int)(365.25 * $C); // is not $D = ($B - 122.1) $E = (int)(($B-$D) / 30.6001); $F = (int)(30.6001 * $E); // is not $F = ($B -$D) $_d = $B - $D - $F; $_m = $E - 1; $_y = $C - 4716; $JD -= 0.5; // UT to GMT -12.0H $JD = ($JD - (int)$JD) * 24.0; $_h = (int)$JD; $JD = ($JD - $_h) * 60.0; $_i = (int)$JD; $JD = ($JD - $_i) * 60.0; $_s = round($JD); if($_s > 59) { $_s -= 60; $_i++; } else if($_s < 0) { $_s += 60; $_i--; } if($_i > 59) { $_i -= 60; $_h++; } else if($_i < 0) { $_i += 60; $_h--; } if($_h > 23) { $_h -= 24; $_d++; } else if($_h < 0) { $_h +=24; $_d--; } if($_m > 12) { $_m -= 12; $_y++; } else if($_m < 0) { $_m +=12; $_y--; } return array($_y,$_m,$_d,$_h,$_i,$_s); } ## private, get JD(julian day) from unix timestamp -- same as unixtojd() ## ## D -- get the number of days from base JD ## D = JD(Julian Day) - 2451545.0, base JD(J2000.0) ## ## base position (J2000.0), 2000-01-01 12:00:00 GMT ## as mktime(12,0,0-64,1,1,2000) == 946695536 unix timestamp at KST, -64 is delta 'T' ## as gmmktime(12,0,0-64,1,1,2000) == 946727936 unix timestamp at GMT, -64 is delta 'T' ## ## valid JD: 1902-01-01 00:00:00 ZONE <= JD <= 2037-12-31 23:59:59 ZONE ## function &_utime2jd($utime) { $D = $utime - 946727936; // number of time $D = sprintf('%.13f',$D/86400); // float, number of days $JD= sprintf('%.13f',$D+2451545.0); // float, Julian Day //$J = sprintf('%.4f',2000.0+($D/365.25)); // Jxxxx.xxxx format //$T = sprintf('%.13f',$D/36525.0); // Julian century return $JD; // float } ## private, get unix timestamp from JD -- same as jdtounix() ## ## 1970-01-01 12:00:00 GMT = 2440587.6257407409139 JD = J1970.0 ## valid JD: 1902-01-01 00:00:00 ZONE <= JD <= 2037-12-31 23:59:59 ZONE ## function &_jd2utime($JD) { $JD -= 2440587.6257407409139; // convert to base JD(J1970.0), J2000.0 delta 'T', but it's not need $seconds = round($JD*86400); // convert to time seconds base on 1970-01-01 00:00:00 $seconds += 43200; // to GMT -12H(43200 seconds) $seconds -= date('Z'); // to local time zone return $seconds; } ## private, check datetime that it's null or not null ## function &__check_datetime($argc, &$Y, &$M, &$D, &$H, &$I, &$S) { if($argc >= 6) return TRUE; list($Y,$_M,$_D,$_H,$_I,$_S) = explode(' ',date('Y n j G i s',time())); if($argc < 5) $D = $_D; if($argc < 4) $M = $_M; if($argc < 3) $S = $_S; if($argc < 2) $I = $_I; if($argc < 1) $H = $_H; } ## public, make JD -- match to mktime() ## ## Julian date ## J0.0 = BC 4713-01-01 12:00 GMT = BC 4713-01-01 21:00 KST ~ AD 9999 ## function &mkjd($H=21, $I=0, $S=0, $M=1, $D=1, $Y=NULL) { calendar123::__check_datetime(func_num_args(),&$Y,&$M,&$D,&$H,&$I,&$S); list($JD) = calendar123::_getjd($Y,$M,$D,$H,(int)$I,(int)$S); return $JD; // folat, JD is UT base } ## private, get unix timestamp from date -- same as mktime() ## ## valid date: 1902-01-01 00:00:00 ZONE <= date <= 2037-12-31 23:59:59 ZONE ## function &_mktime($H=9, $I=0, $S=0, $M=1, $D=1, $Y=NULL) { if($Y>1970 && $Y<2038) return mktime($H,$I,$S,$M,$D,$Y); calendar123::__check_datetime(func_num_args(),&$Y,&$M,&$D,&$H,&$I,&$S); $JD = calendar123::mkjd($H,$I,$S,$M,$D,$Y); $utime = calendar123::_jd2utime($JD); return $utime; } ## private, same as `date()' function, base on unix timestamp(support Microsoft Windows PHP4) ## ## valid date: 1902-01-01 00:00:00 ZONE <= date <= 2037-12-31 23:59:59 ZONE ## function &_date($format, $utime=NULL) { if($utime === NULL) $utime = time(); if($utime>=0 && $utime<2145884400) return date($format,$utime); $JD = calendar123::_utime2jd($utime); $str = calendar123::date($format,$JD); return $str; } ## public, same as `date()' function, but base on JD by UT(delta T) ## ## valid JD: BC 4713-01-01 12:00 GMT ~ AD 9999 ## function &date($format, $JD=NULL) { static $_weeks = array('Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday'); static $_months = array('January','February','March','April','May','June','July','August', 'September','Octorber','November','December'); static $_ordinals = array(1=>'st',21=>'st',31=>'st',2=>'nd',22=>'nd',3=>'rd',23=>'rd'); if(func_num_args()<2 || $JD==NULL) $JD = calendar123::mkjd(); // current JD(UT) if(!$format || is_array($format)) return calendar123::_todate($JD); // array list($Y,$M,$D,$H,$I,$S) = calendar123::_todate($JD); $_Y = sprintf('%04d',$Y); $_M = sprintf('%02d',$M); $_D = sprintf('%02d',$D); $_H = sprintf('%02d',$H); $_I = sprintf('%02d',$I); $_S = sprintf('%02d',$S); $_Z = date('Z'); $_W = calendar123::jddayofweek($JD + ($_Z/86400)); // JD apply to local TimeZone $_O = date('O'); // example +0900 $_R = substr($_weeks[$_W],0,3).", $_D ".substr($_months[$M-1],0,3)." $H:$I:$S $_O"; $_C = "${_Y}-${_M}-${_D}T${_H}:${_I}:${_S}".$_O{0}.$_O{1}.$_O{2}.':'.$_O{3}.$_O{4}; $l = strlen($format); for($i=0; $i<$l; $i++) { $char = $format[$i]; switch($char) { case 'a': $r .= ($H<12) ? 'am' : 'pm'; break; case 'A': $r .= ($H<12) ? 'AM' : 'PM'; break; case 'B': $r .= calendar123::itime($H,$I,$S); break; case 'c': $r .= $_C; break; // ISO 8601 date (added in PHP5) case 'd': $r .= $_D; break; case 'D': $r .= substr($_weeks[$_W],0,3); break; case 'F': $r .= $_months[$M-1]; break; case 'g': $r .= (($H-1) % 12) + 1; break; case 'G': $r .= $H; break; case 'h': $r .= sprintf('%02d',(($H-1)%12)+1); break; case 'H': $r .= $_H; break; case 'i': $r .= $_I; break; //case 'I': $r .= 0; break; case 'j': $r .= $D; break; case 'l': $r .= $_weeks[$_W]; break; case 'L': $r .= calendar123::isleap($Y); break; case 'm': $r .= $_M; break; case 'M': $r .= substr($_months[$M-1],0,3); break; case 'n': $r .= $M; break; case 'O': $r .= date('O'); break; case 'r': $r .= $_R; break; case 's': $r .= $_S; break; case 'S': $r .= $_ordinals[$D] ? $_ordinals[$D] : 'th'; break; case 't': $r .= calendar123::days_in_month($Y,$M); break; case 'T': $r .= date('T'); break; case 'U': $r .= time(); break; case 'w': $r .= $_W; break; // JD to local zone case 'W': $r .= calendar123::weeknumber($Y,$M,$D); break; // ISO-8601 case 'y': $r .= substr($_Y,-2); break; case 'Y': $r .= $Y; break; case 'z': $r .= calendar123::dayofyear($Y,$M,$D); break; case 'Z': $r .= $_Z; break; // KST zone +9H, in seconds default : $r .= $char; break; } } return $r; // string } ## public, get leap year ## ## #define isleap(y) ((((y) % 4) == 0 && ((y) % 100) != 0) || ((y) % 400) == 0) ## ## +-- 4*Y ! // normal ## `-- 4*Y ## |-- 100*Y ! // leap ## `-- 100*Y ## |-- 400*Y ! // normal ## `-- 400*Y // leap ## ## but, 4000*Y is not normal year, is leap year ## http://user.chollian.net/~kimdbin/re/leap_year.html ## function &isleap($year) { if($year%4) return FALSE; else if($year%100) return TRUE; else if($year%400) return FALSE; return TRUE; // else 400*Y } ## public, get week idx ## ## 0(sun), 1(mon), 2(tue), 3(wed), 4(thu), 5(fri), 6(sat) ## function &jddayofweek($JD) { return floor($JD+1.5)%7; // integer } function &dayofyear($Y, $M, $D) { list($JDE) = calendar123::_getjd($Y,$M,$D); list($JDS) = calendar123::_getjd($Y,1,1); return (int)($JDE - $JDS); } ## ISO-8601, start on Thurday ## function &weeknumber($Y, $M, $D) { list($JD) = calendar123::_getjd($Y,1,1); $widx = calendar123::jddayofweek($JD) - 1; $days = calendar123::dayofyear($Y,$M,$D); $midx = ($widx<0) ? 6 : $widx; $days = ($midx<4) ? ($days+$midx) : ($days+$midx-7); $n = floor($days/7) + 1; if($n == 0) { list($JD) = calendar123::_getjd($Y-1,1,1); $widx = calendar123::jddayofweek($JD); $n = ($widx>4) ? 52 : 53; } return $n; // integer } ## public, get swatch internet time, base BMT = GMT + 1 ## same as date('B') ## function &itime($H, $I, $S) { $B = ($H-(date('Z')/3600)+1)*41.666 + $I*0.6944 + $S*0.01157; $B = ($B>0) ? $B : $B+1000.0; return sprintf('%03d',$B); } /*** function &days_in_month($year, $month, $JDS=0) { list($JDS) = calendar123::_getjd($year,$month,1); list($JDE) = calendar123::_getjd($year,$month+1,1); $term = (int)($JDE - $JDS); return $term; // integer } ***/ ## public ## function &days_in_month($year, $month) { static $months = array(31,0,31,30,31,30,31,31,30,31,30,31); $n = $months[$month-1]; $n = $n ? $n : (calendar123::isleap($year) ? 29 : 28); return $n; // integer } ## public ## function &month_info($year, $month) { if($year<1902 || $year>2037) { list($JD) = calendar123::_getjd($year,$month,1); $term = calendar123::days_in_month($year,$month); $week = calendar123::jddayofweek($JD); // week idx $minfo = array($week,$term); } else { $utime = mktime(23,59,59,$month,1,$year); $minfo = explode(' ',date('w t',$utime)); } return $minfo; // array($week,$term) } /*** function &_calendar($year, $month) { list($week,$term) = calendar123::month_info($year,$month); $eidx = 3; $sat = 7 - $week; $chk = $sat + 28; $sats = array($sat,$sat+7,$sat+14,$sat+21); $suns = array($sat-6,$sat+1,$sat+8,$sat+15); $refs = range(1,$term); if($chk <= $term) { $eidx++; $sats[] = $chk; $suns[] = $sat + 22; } ## check last sunday ## if($term-$sats[$eidx] > 0) { $sats[] = $sats[$eidx] + 7; $suns[] = $sats[$eidx] + 1; $eidx++; } ## rewrite array ## for($i=0; $i<=$eidx; $i++) { for($j=$suns[$i]; $j<=$sats[$i]; $j++) $r[$i][] = &$refs[$j-1]; } //ksort($r); echo "$week;$term\n"; print_r($suns); print_r($sats); print_r($r); } ***/ ## public ## function &calendar($year, $month) { list($week,$term) = calendar123::month_info($year,$month); $eidx = 3; $refs = range(1,$term); // reference of days $fsat = 7 - $week; // first Saturday ## make index array such as (Sun,Sat) ## for($i=0; $i<=3; $i++) { $isat = $fsat + ($i*7); // index of Saturday $idxs[] = array($isat-6,$isat); } ## check last Saturday and Sunday ## if(($fsat+28) <= $term) $idxs[++$eidx] = array($fsat+22,$fsat+28); if(($term-$idxs[$eidx][1]) > 0) { $idxs[] = array($idxs[$eidx][0]+7,$idxs[$eidx][1]+7); $eidx++; } ## rewrite days ## for($i=0; $i<=$eidx; $i++) { for($j=$idxs[$i][0]; $j<=$idxs[$i][1]; $j++) $r[$i][] = &$refs[$j-1]; } return $r; // array } } // end of class /**** example ********* $_y = 2040; $_m = 12; $r = calendar123::calendar($_y,$_m); echo '
';
echo "      $_m $_y\n";
echo "Su Mo Tu We Th Fr Sa\n";

$size = sizeof($r);
for($i=0; $i<$size; $i++)
{
  printf("%2s",$r[$i][0]);
  for($j=1; $j<7; $j++) printf("%3s",$r[$i][$j]);
  echo "\n";
}
print_r($r);
**********************/
?>




##  - http://linuxchannel.net/
##
## [changes]
##  - 2009.06.08 : extended, date() to calendar123::_date() of class.caledar.php
##  - 2005.04.17 : add sunrise_sunset()
##  - 2005.02.06 : rebuid deg2valid(), add zodiac()
##  - 2005.01.24 : rebuild time2stime(), atan2()
##  - 2005.01.18 : bug fixed:$RA
##  - 2003.09.08 : bug fixed
##  - 2003.09.06 : new build
##
## [근사식에 대한 신뢰]
##  - 표준편차 : 1289.7736 = 21.5 minutes (standard deviation)
##  - 평균오차 : 817.57409541246 = 13.6 minutes
##  - 최대오차 : +4102.7340(68.4 minutes), -4347.2395(72.5 minutes)
##
## [근사식으로 계산한 24절기 실제 오차] 1902 ~ 2037 년
##  - 표준편차 : 1122.1921 = 18.7 분
##  - 평균오차 : +686.08382175161 = +11.4 분
##  - 최대오차 : +4297.252300024 = +71.6 분, -4278.048699975 = -71.3 분
##  - 최소오차 : +0.16999998688698 = 0 초
##
## [근사식 + 년도 보정으로 계산한 24절기 실제 오차] 1902 ~ 2037 년
##  - 표준편차 : 450.8534 = 7.5 분
##  - 평균오차 : +305.38638890903 = 5.0 분
##  - 최대오차 : +3028.2343000174 = +50.5 분, -1982.9391000271 = -33.1 분
##  - 최소오차 : +0.0085000991821289 = 0 초
##
## [valid date]
##  - 1902.01.01 00:00:00 <= utime <= 2037.12.31 23:59:59
##
## [support date]
##  - unix timestamp base: 1902-01-01 00:00:00 <= date <= 2037-12-31 23:59:59 (guess)
##  - JD(Julian Day) base: BC 4713-01-01 12:00 GMT <= Gregorian date <= AD 9999 (guess)
##
## [download & online source view]
##  - http://ftp.linuxchannel.net/devel/php_solar/
##  - http://ftp.linuxchannel.net/devel/php_calendar/
##
## [demo]
##  - http://linuxchannel.net/gaggle/solar.php
##
## [docs]
##  - http://linuxchannel.net/docs/solar-24terms.txt
##
## [references]
##  - http://cgi.chollian.net/~kohyc/
##  - http://user.chollian.net/~kimdbin/
##  - http://user.chollian.net/~kimdbin/re/calendar.html
##  - http://user.chollian.net/~kimdbin/re/suncoord.html
##  - http://user.chollian.net/~kimdbin/qna/al138.html
##  - http://ruby.kisti.re.kr/~manse/contents-3.html
##  - http://ruby.kisti.re.kr/~anastro/sub_index.htm
##  - http://www-ph.postech.ac.kr/~obs/lecture/lec1/elementary/nakedeyb.htm
##  - http://ruby.kisti.re.kr/~anastro/calendar/etime/ETime.html
##  - http://www.sundu.co.kr/5-information/5-3/5f3-3-5-04earth-1.htm
##  - http://www-ph.postech.ac.kr/~obs/lecture/lec1/elementary/nakedeya.htm
##  - http://upgradename.com/calm.php
##  - http://aa.usno.navy.mil/faq/docs/SunApprox.html
##  - http://aa.usno.navy.mil/data/docs/JulianDate.html
##
## [usage]
##
## [example]
##  require_once 'class.calendar.php';
##  require_once 'class.solar.php';
##  $sun = array();
##  $terms = solar::terms(date('Y'),1,12,&$sun);
##  print_r($terms);
##  print_r($sun);
##  print_r(solar::sun(time()));
##

class solar
{
  ## check solar terms in today or tomorrow
  ##
  function &solar($utime=0, $GMT=FALSE)
  {
    return solar::today($utime,$GMT);
  }

  function &today($utime=0, $GMT=FALSE)
  {
    if($utime == '') $utime = time();
    if($GMT) $utime -= 32400;

    list($year,$moon,$moonday) = explode(' ',date('Y n nd',$utime));

    $terms = solar::terms($year,$moon,0);

    if($term = $terms[$moonday])
    {
        $str = '오늘은 '.$term.'입니다.';
    }
    else if($term = $terms[date('nd',$utime+86400)])
    {
        $str = '내일은 '.$term.'입니다.';
    }

    return $str;
  }

  ## get sun position at unix timestamp
  ##
  ## [limit]
  ##  - mktime(0,0,0,1,1,1902) < $utime < mktime(23,59,59,12,31,2037)
  ##
  ## [study]
  ##  - w = 23.436
  ##  - tan RA = (sin L * cos w - tan e * sin w ) / cos L
  ##  - sin d = (sin e * cos w) + (cos e * sin w * sin L)
  ##
  ## [example]
  ##  - print_r(solar::sun(mktime(  10,0,0,3,21,2003)  ));
  ##  - print_r(solar::sun(mktime(10-9,0,0,3,21,2003),1)); // same as
  ##
  function &sun($utime, $GMT=FALSE)
  {
    $L = $D = $JD = 0; $J = '';
    $deg2rad = array();

    /***
    if($utime<-2145947400 || $utime>2145884399)
    {
        echo "\nerror: invalid input $utime, 1902.01.01 00:00:00 <= utime <= 2037.12.31 23:59:59\n";
        return -1;
    }
    ***/

    list($L,$atime) = solar::sunl($utime,$GMT,&$D,&$JD,&$J,&$deg2rad);

    ## Sun's ecliptic, in degress
    ##
    $e = sprintf('%.10f',23.439 - (0.00000036*$D)); // degress

    $cosg = cos($deg2rad['g']); // degress
    $cos2g = cos($deg2rad['2g']); // degress

    ## R == AU (sun ~ earth)
    ## The distance of the Sun from the Earth, R, in astronomical units (AU)
    ##
    $R = sprintf('%.10f',1.00014 - (0.01671*$cosg) - (0.00014*$cos2g));

    ## convert
    ##
    $deg2rad['e'] = deg2rad($e); // radian
    $deg2rad['L'] = deg2rad($L); // radian

    $cose = cos($deg2rad['e']); // degress
    $sinL = sin($deg2rad['L']); // degress
    $cosL = cos($deg2rad['L']); // degress
    $sine = sin($deg2rad['e']); // degress

    ## the Sun's right ascension(RA)
     ##
    //$tanRA = sprintf('%.10f',$cose * $sinL / $cosL); // degress
    //$RA = sprintf('%.10f',rad2deg(atan($tanRA)));
    //$RA = $cosL<0 ? $RA+180 : ($sinL<0 ? $RA+360 : $RA); // patch 2005.01.18
    $RA = sprintf('%.10f',rad2deg(atan2($cose*$sinL,$cosL)));
    $RA = solar::deg2valid($RA);

    ## the Sun's declination(d)
    ##
    $sind = sprintf('%.10f',$sine * $sinL); // degress
    $d = sprintf('%.10f',rad2deg(asin($sind))); // Sun's declination, degress

    $solartime = solar::deg2solartime($L);
    $daytime = solar::deg2daytime($RA);

    //if(!($L1=round($L) % 15))
    //{
    //    $idx = $L1 / 15;
    //    list($hterms) = solar::gterms();
    //}

    ## all base degress or decimal
    ##
     return array
    (
    'JD' => $JD,    /*** Julian Day ***/
    'J'  => 'J'.$J, // Jxxxx.xxxx format
    'L'  => $L,    /*** Sun's geocentric apparent ecliptic longitude ***/
    'e'  => $e,    /*** Sun's ecliptic ***/
    'R'  => $R,    /*** Sun from the Earth, astronomical units (AU) ***/
    'RA' => $RA,    /*** Sun's right ascension ***/
    'd'  => $d,    /*** Sun's declination ***/
    'stime'  => $solartime,        /*** solar time ***/
    'dtime'  => $daytime,        /*** day time ***/
    'atime'  => $atime,        /*** append time for integer degress **/
    'utime'  => $utime,        /*** unix timestamp ***/
    'date'   => calendar123::_date('D, d M Y H:i:s T',$utime),    /*** KST date ***/
    'gmdate' => calendar123::_date('D, d M Y H:i:s ',$utime-date('Z')).'GMT',    /*** GMT date ***/
    '_L'  => solar::deg2angle($L),
    '_e'  => solar::deg2angle($e,1),
    '_RA' => solar::deg2angle($RA),
    '_d'  => solar::deg2angle($d,1),
    '_stime' => solar::time2stime($solartime),
    '_dtime' => solar::time2stime($daytime),
    '_atime' => solar::time2stime($atime,TRUE),
    );
  }

  function &sunl($utime, $GMT=FALSE, $D=0, $JD=0, $J='', $deg2rad=array())
  {
    if($GMT) $utime += 32400; // force GMT to static KST, see 946727936

    ## D -- get the number of days from base JD
    ## D = JD(Julian Day) - 2451545.0, base JD(J2000.0)
    ##
    ## base position (J2000.0), 2000-01-01 12:00:00, UT
    ## as   mktime(12,0,0-64,1,1,2000) == 946695536 unix timestamp at KST
    ## as gmmktime(12,0,0-64,1,1,2000) == 946727936 unix timestamp at GMT
    ##
    $D = $utime - 946727936; // number of time
    $D = sprintf('%.10f',$D/86400); // float, number of days
    $JD = sprintf('%.10f',$D+2451545.0); // float, Julian Day
    $J = sprintf('%.4f',2000.0 + ($JD-2451545.0)/365.25); // Jxxxx.xxxx format

    $g = sprintf('%.10f',357.529 + (0.98560028 * $D));
    $q = sprintf('%.10f',280.459 + (0.98564736 * $D));

    ## fixed
    ##
    $g = solar::deg2valid($g); // to valid degress
    $q = solar::deg2valid($q); // to valid degress

    ## convert
    ##
    $deg2rad = array();
    $deg2rad['g'] = deg2rad($g); // radian
    $deg2rad['2g'] = deg2rad($g*2); // radian

    $sing = sin($deg2rad['g']); // degress
    $sin2g = sin($deg2rad['2g']); // degress

    ## L is an approximation to the Sun's geocentric apparent ecliptic longitude
    ##
    $L = sprintf('%.10f',$q + (1.915 * $sing) + (0.020*$sin2g)); 
    $L = solar::deg2valid($L); // degress
    $atime = solar::deg2solartime(round($L)-$L); // float

    return array($L,$atime); // array, float degress, float seconds
  }

  /***
  function &_atime($utime)
  {
    static $unit = 87658.1256;

    list($L) = solar::sunl($utime);
    $td = round($L) - $L;

    while(abs($td) > 0.0000114) // 1/$unit
    {
        $utime += $unit * $td;
        list($L) = solar::sunl($utime);
        $td = round($L) - $L;
    }

    return $utime;
  }
  ***/

  /***
  function &sinl($f, $v)
  {
    return sin(deg2rad($f+$v));
  }

  ## http://linux-sarang.net/board/?p=read&table=qa&no=198189
  ## -2 < sin x < + 2
  ## sin (77 + L) ==> (77 + L - 1.915 sin (77 + L))
  ##
  function &l2d($L)
  {
    $L = (int)$L; // 0 <= $L <= 345
    //$sinl  = sin(deg2rad(77+$L));
    $sinl = solar::sinl($L,77);
    //$sinl = solar::sinl($L-(1.915)*$sinl,77);

    //$sin2l = sin(deg2rad(154+($L*2)));
    $sin2l = solar::sinl($L*2,154);
    $sin2l = solar::sinl($L-(0.020*$L*2*$sin2l),154);
    $sin2l = solar::sinl($L-(0.020*$L*2*$sin2l),154);

    $D = sprintf('%.10f',($L - 280.459 - (1.915 * $sinl) - (0.020 * $sin2l)) / 0.98564736);

    return $D; // float
  }

  function &l2jd($L)
  {
    $D  = solar::l2d($L);
    $JD = sprintf('%.10f',$D+2451545.0);
    //$JD = $JD + ($i * 360 / 0.98564736) 

    return $JD; // float
  }

  function &l2utime($year, $L, $GMT=FLASE)
  {
    $i = (int)$year - 2000 + 1;
    $D = solar::l2d($L);

    $utime = ($D * 86400) + 946727936 + (31556925.216 * $i);
    $utime = round($utime);

    return $utime - ($GMT ? 32400 : 0); // integer
  }
  ***/

  ## 1 hour == 15 degress
  ## 1 degress == 4 minute == 240 seconds
  ##
  function °2daytime($deg)
  {
    return sprintf('%.4f',$deg*240); // seconds
  }

  ## 1 solar year == 365.242190 days == 31556925.216 seconds
  ## 1 degress == 31556925.216 seconds / 360 degress == 87658.1256 seconds
  ##
  function °2solartime($deg)
  {
    return sprintf('%.4f',$deg*87658.1256); // seconds
  }

  function °2angle($deg, $singed=FALSE)
  {
    if($singed) $singed = '+';
    if($deg <0) { $singed = '-'; $deg = abs($deg); }

    $time = sprintf('%.4f',$deg*3600);
    $degr = (int)$deg.chr(161).chr(198); //sprintf('%d',$deg);
    $time = sprintf('%.4f',$time-($degr*3600)); // fmod
    $mins = sprintf('%02d',$time/60).chr(161).chr(199);
    $secs = sprintf('%.4f',$time-($mins*60)).chr(161).chr(200); // fmod

    return $singed.$degr.$mins.$secs;
  }

  function °2valid($deg)
  {
    //if($deg <= 360 && $deg >=0) return $deg;
    $deg = ($deg>=0) ? fmod($deg,360) : fmod($deg,360)+360.0;

    return (float)$deg; // float degress
  }

  function &moon2valid($moon)
  {
    //$moon = max($moon,1);
    //$moon = min($moon,12);

    if($moon < 1) $moon = 1;
    else if($moon > 12) $moon = 12;

    return (int)$moon;
  }

  function &time2stime($time, $singed=FALSE)
  {
    if($singed) $singed = '+';
    if($time<0) { $singed = '-'; $time = abs($time); }

    return $singed.calendar123::_date('z H i s',$time-date('Z'));
  }

  function >erms()
  {
    static $hterms = array
    (
    '소한','대한','입춘','우수','경칩','춘분','청명','곡우',
    '입하','소만','망종','하지','소서','대서','입추','처서',
    '백로','추분','한로','상강','입동','소설','대설','동지'
    );

    static $tterms = array
    (
    -6418939, -5146737, -3871136, -2589569, -1299777,        0,
     1310827,  2633103,  3966413,  5309605,  6660762,  8017383,
     9376511, 10735018, 12089855, 13438199, 14777792, 16107008,
    17424841, 18731368, 20027093, 21313452, 22592403, 23866369
    );

    ## mktime(7+9,36,19-64,3,20,2000), 2000-03-20 16:35:15(KST)
    ##
    if(!defined('__SOLAR_START__'))
    {
    define('__SOLAR_START__',953537715); // start base unix timestamp
    define('__SOLAR_TYEAR__',31556940); // tropicalyear to seconds
    define('__SOLAR_BYEAR__',2000); // start base year
    }

    return array($hterms,$tterms);
  }

  function &tterms($year)
  {
    static $addstime = array
    (
    1902=> 1545, 1903=> 1734, 1904=> 1740, 1906=>  475, 1907=>  432,
    1908=>  480, 1909=>  462, 1915=> -370, 1916=> -332, 1918=> -335,
    1919=> -263, 1925=>  340, 1927=>  344, 1928=> 2133, 1929=> 2112,
    1930=> 2100, 1931=> 1858, 1936=> -400, 1937=> -400, 1938=> -342,
    1939=> -300, 1944=>  365, 1945=>  380, 1946=>  400, 1947=>  200,
    1948=>  244, 1953=> -266, 1954=> 2600, 1955=> 3168, 1956=> 3218,
    1957=> 3366, 1958=> 3300, 1959=> 3483, 1960=> 2386, 1961=> 3015,
    1962=> 2090, 1963=> 2090, 1964=> 2264, 1965=> 2370, 1966=> 2185,
    1967=> 2144, 1968=> 1526, 1971=> -393, 1972=> -430, 1973=> -445,
    1974=> -543, 1975=> -393, 1980=>  300, 1981=>  490, 1982=>  400,
    1983=>  445, 1984=>  393, 1987=>-1530, 1988=>-1600, 1990=> -362,
    1991=> -366, 1992=> -400, 1993=> -449, 1994=> -321, 1995=> -344,
    1999=>  356, 2000=>  480, 2001=>  483, 2002=>  504, 2003=>  294,
    2007=> -206, 2008=> -314, 2009=> -466, 2010=> -416, 2011=> -457,
    2012=> -313, 2018=>  347, 2020=>  257, 2021=>  351, 2022=>  159,
    2023=>  177, 2026=> -134, 2027=> -340, 2028=> -382, 2029=> -320,
    2030=> -470, 2031=> -370, 2032=> -373, 2036=>  349, 2037=>  523,
    );

    static $addttime = array
    (
    1919=> array(14=>-160), 1939=> array(10=> -508),
    1953=> array( 0=> 220), 1954=> array( 1=>-2973),
    1982=> array(18=> 241), 1988=> array(13=>-2455),
    2013=> array( 6=> 356), 2031=> array(20=>  411),
    2023=> array( 0=>  399, 11=>-571),
    );

    return array($addstime[$year],$addttime[$year]);
  }

  ## get the 24 solar terms, 1902 ~ 2037
  ##
  ## [usage]
  ##  - array solar::terms(int year [, int smoon [, int length [, array &sun]]] )
  ##
  function &terms($year=0, $smoon=1, $length=12, $sun=array())
  {
    $year  = (int)$year;
    $sun = array();
    $smoon = (int)$smoon;
    $length = (int)$length;
    $times = array();

    if(!$year) $year = date('Y');

    /***
    if($year<1902 || $year>2037)
    {
        echo "\nerror: invalid input $year, 1902 <= year <= 2037\n";
        return -1;
    }
    ***/

    list($hterms,$tterms) = solar::gterms();
    list($addstime,$addttime) = solar::tterms($year);

    ## mktime(7+9,36,19-64,3,20,2000), 2000-03-20 16:35:15(KST)
    ##
    $start = __SOLAR_START__; // start base unix timestamp
    $tyear = __SOLAR_TYEAR__; // tropicalyear to seconds
    $byear = __SOLAR_BYEAR__; // start base year

    $start += ($year - $byear) * $tyear;

    if($length < -12) $length = -12;
    else if($length > 12) $length = 12;

    $smoon = solar::moon2valid($smoon);
    $emoon = solar::moon2valid($smoon+$length);

    $sidx =  (min($smoon,$emoon) - 1) * 2;
    $eidx = ((max($smoon,$emoon) - 1) * 2) + 1;

    for($i=$sidx; $i<=$eidx; $i++)
    {
        $time = $start + $tterms[$i];
        list(,$atime) = solar::sunl($time,FALSE);
        $time += $atime + $addstime + $addttime[$i]; // re-fixed
        $terms[calendar123::_date('nd',$time)] = &$hterms[$i];
        $times[] = $time; // fixed utime
    }

    ## for detail information
    ##
    if(func_num_args() > 3)
    {
        $i = $sidx;
        foreach($times AS $time)
        {
            $sun[$i] = solar::sun($time,FALSE);
            $sun[$i]['_avgdate'] = calendar123::_date('D, d M Y H:i:s ',$start+$tterms[$i]-date('Z')).'GMT';
            $sun[$i]['_name'] = &$hterms[$i];
            $i++;
        }
    }

    unset($times);

    return $terms; // array
  }

  ## public, get a Constellation of zodiac
  ##
  function &zodiac($y, $m, $d)
  {
    static $ffd = array // patch day
    (
    19030622 => -24, 19221222 =>   4, 19540420 => -61, 19550723 => -48,
    19551222 => -57, 19560320 => -48, 19580823 => -52, 19600219 => -55,
    19610221 => -59, 19620823 => -37, 19651023 => -42, 19870525 =>  64,
    19880722 =>  61, 20230621 =>   4, 20300218 =>   7
    );

    $horoscope = array // do not set `static' variable, it's a bug?
    (
    array(chr(191).chr(176).chr(188).chr(210),'Capricon'),
    array(chr(200).chr(178).chr(188).chr(210),'Taurus'),
    array(chr(189).chr(214).chr(181).chr(213).chr(192).chr(204),'Gemini'),
    array(chr(176).chr(212),'Cancer'),
    array(chr(187).chr(231).chr(192).chr(218),'Leo'),
    array(chr(195).chr(179).chr(179).chr(224),'Virgo'),
    array(chr(195).chr(181).chr(196).chr(170),'Libra'),
    array(chr(192).chr(252).chr(176).chr(165),'Scorpius'),
    array(chr(177).chr(195).chr(188).chr(246),'Sagittarius'),
    array(chr(187).chr(234).chr(190).chr(231),'Aries'),
    array(chr(185).chr(176).chr(186).chr(180),'Aquarius'),
    array(chr(185).chr(176).chr(176).chr(237).chr(177).chr(226),'Pisces')
    );

    //list(,$nd) = _solar::_terms($y,$m,0);
    //$idx = ($m.$d<$nd) ? $m-2 : $m-1;
    //if($idx < 0) $idx += 12;

    $fk = sprintf('%d%02d%d',$y,$m,$d);
    list($L) = solar::sunl(calendar123::_mktime(23,59+(int)$ffd[$fk],59,$m,$d,$y));

    return $horoscope[floor($L/30)];
  }

  ## public, get sunrise, sunset on Korea
  ##
  ## same as PHP5 `date_sunrise()', `date_sunset()'
  ## http://williams.best.vwh.net/sunrise_sunset_example.htm
  ## http://kr.php.net/manual/en/function.date-sunrise.php
  ##
  ## [zenith]
  ##  offical      = 90 degrees 50'
  ##  civil        = 96 degrees
  ##  nautical     = 102 degrees
  ##  astronomical = 108 degrees
  ##
  function sunrise_sunset($_y, $_m, $_d, $_location=0, $_zenith=0)
  {
    static $_locations = array
    (
    array(126.95,37.55)/* 서울 */, array(131.87,37.24)/* 독도 */,
    array(129.37,36.04)/* 포항 */, array(126.35,36.52)/* 안면 */,
    );

    static $_zeniths = array(90.8333, 96.0, 102.0, 108.0);
    static $_timezone = 9.0; // KST +9H

    ## check arguments
    ##
    if(!preg_match('/^[0-3]$/',$_location)) $_location = 0;
    if(!preg_match('/^[0-3]$/',$_zenith)) $_zenith = 0;

    ## inital configurations
    ##
    $location  = $_locations[$_location];
    $longitude = $location[0];
    $latitude  = deg2rad($location[1]);
    $zenith    = deg2rad($_zeniths[$_zenith]);

    ## 1. first calculate the day of the year
    ##
    $N = floor(275*$_m/9) - (floor(($_m+9)/12) * (1+floor(($_y-4*floor($_y/4)+2)/3))) + $_d - 30;

    ## 2. convert the longitude to hour value and calculate an approximate time
    ##
    $lhour = $longitude / 15;
    $t['r'] = sprintf('%.8f',$N+((6-$lhour)/24.0)); // sunrise
    $t['s'] = sprintf('%.8f',$N+((18-$lhour)/24.0)); // sunrise

    ## 3. calculate the Sun's mean anomaly
    ##
    $M['r'] = (0.9856*$t['r']) - 3.289;
    $M['s'] = (0.9856*$t['s']) - 3.289;

    ## 4. calculate the Sun's true longitude
    ## to be adjusted into the range [0,360) by adding/subtracting 360
    ##
    $L['r'] = $M['r'] + (1.916*sin(deg2rad($M['r']))) + (0.020*sin(deg2rad(2*$M['r']))) + 282.634;
    $L['s'] = $M['s'] + (1.916*sin(deg2rad($M['s']))) + (0.020*sin(deg2rad(2*$M['s']))) + 282.634;
    $L['r'] = ($L['r']>=0) ? fmod($L['r'],360) : fmod($L['r'],360)+360.0;
    $L['s'] = ($L['s']>=0) ? fmod($L['s'],360) : fmod($L['s'],360)+360.0;
    $l['r'] = deg2rad($L['r']);
    $l['s'] = deg2rad($L['s']);

    ## 5a. calculate the Sun's right ascension
    ## to be adjusted into the range [0,360) by adding/subtracting 360
    ##
    $RA['r'] = rad2deg(atan(0.91764*tan($l['r'])));
    $RA['s'] = rad2deg(atan(0.91764*tan($l['s'])));
    $RA['r'] = ($RA['r']>=0) ? fmod($RA['r'],360) : fmod($RA['r'],360)+360.0;
    $RA['s'] = ($RA['s']>=0) ? fmod($RA['s'],360) : fmod($RA['s'],360)+360.0;

    ## 5b. right ascension value needs to be in the same quadrant as L
    ##
    $RA['r'] += (floor($L['r']/90.0)*90.0) - (floor($RA['r']/90.0)*90.0);
    $RA['s'] += (floor($L['s']/90.0)*90.0) - (floor($RA['s']/90.0)*90.0);

    ## 5c. right ascension value needs to be converted into hours
    ##
    $RA['r'] /= 15;
    $RA['s'] /= 15;

    ## 6. calculate the Sun's declination
    ##
    $sindec['r'] = 0.39782 * sin($l['r']);
    $sindec['s'] = 0.39782 * sin($l['s']);
    $cosdec['r'] = cos(asin($sindec['r']));
    $cosdec['s'] = cos(asin($sindec['s']));

    ## 7a. calculate the Sun's local hour angle
    ## (cosH> 1) the sun never rises on this location (on the specified date)
    ## (cosH<-1) the sun never sets on this location (on the specified date)
    ##
    $cosH['r'] = (cos($zenith) - ($sindec['r']*sin($latitude))) / ($cosdec['r']*cos($latitude));
    $cosH['s'] = (cos($zenith) - ($sindec['s']*sin($latitude))) / ($cosdec['s']*cos($latitude));

    ## 7b. finish calculating H and convert into hours
    ##
    $H['r'] = 360.0 - rad2deg(acos($cosH['r']));
    $H['s'] = rad2deg(acos($cosH['s']));
    $H['r'] /= 15;
    $H['s'] /= 15;

    ## 8. calculate local mean time of rising/setting
    ##
    $T['r'] = $H['r'] + $RA['r'] - (0.06571*$t['r']) - 6.622;
    $T['s'] = $H['s'] + $RA['s'] - (0.06571*$t['s']) - 6.622;

    ## 9. adjust back to UTC
    ## to be adjusted into the range [0,24) by adding/subtracting 24
    ##
    $UT['r'] = $T['r'] - $lhour;
    $UT['s'] = $T['s'] - $lhour;
    $UT['r'] = ($UT['r']>=0) ? fmod($UT['r'],24.0) : fmod($UT['r'],24.0) + 24.0;
    $UT['s'] = ($UT['s']>=0) ? fmod($UT['s'],24.0) : fmod($UT['s'],24.0) + 24.0;

    ## 10. convert UT value to local time zone of latitude/longitude
    ##
    $localT['r'] = fmod($UT['r']+$_timezone,24.0);
    $localT['s'] = fmod($UT['s']+$_timezone,24.0);

    ## last convert localT to human time
    ##
    $sunrise['H'] = floor($localT['r']);
    $sunrise['m'] = (int)(($localT['r']-$sunrise['H'])*60);
    $sunset['H'] = floor($localT['s']);
    $sunset['m'] = (int)(($localT['s']-$sunset['H'])*60);

    return array
    (
    sprintf('%02d',$sunrise['H']).':'.sprintf('%02d',$sunrise['m']), // sunrise HH:MM
    sprintf('%02d',$sunset['H']).':'.sprintf('%02d',$sunset['m']), // sunset HH:MM
    );
  }
} // end of class

/*** example ***
require_once 'class.calendar.php';
require_once 'class.solar.php';
$sun = array();
$terms = solar::terms(date('Y'),1,12,&$sun);
print_r($terms);
print_r($sun);
print_r(solar::sun(time()));
echo solar::today()."\n";
echo solar::solar(mktime(0,0,0,3,20))."\n";
echo solar::solar(mktime(0,0,0,3,21))."\n";
echo solar::solar(mktime(0,0,0,3,22))."\n";
echo "\n\n";
print_r(solar::terms(2023));
***/
?>



 0 and $pYear % 4 == 0) or $pYear % 400 == 0) {
        $fn_leapmonth = true;
	}
    else {
        $fn_leapmonth = false;
	}
	return $fn_leapmonth;

	// 또는 단순히 date()를 이용 하거나....("L" : 윤년여부 윤년엔 1, 그 외엔 0)
	// return date("L", mktime(0, 0, 0, $pMonth, 1, $pYear)); 
}
 
//--------------------------------------------------------------------------------

    /**
     * @function: fn_monthcount($pYear,$pMonth)
     * @return  : integer
     * @brief:    해당월의 마지막 일을 반환한다 
     **/
function fn_monthcount($pYear,$pMonth) {
    $aMonthNum = explode("-","31-0-31-30-31-30-31-31-30-31-30-31-");
     //2월달은 예외

    if (fn_leapmonth($pYear)) {
        $aMonthNum[1] = 29;
	}
    else {
        $aMonthNum[1] = 28;
	}   
//    return $aMonthNum;  
    return $aMonthNum[$pMonth-1];  

	// 또는 단순히 date()를 이용 하거나....("t" : 주어진 월의 일수)
	// return date("t", mktime(0, 0, 0, $pMonth, 1, $pYear)); 
}
 
//--------------------------------------------------------------------------------

    /**
     * @function: fn_firstweek($pYear,$pMonth)
     * @return  : integer
     * @brief:    해당년/월의 첫번째일의 위치를 반환 ("w" : 0=일요일, 6=토요일)
     **/
function fn_firstweek($pYear,$pMonth) {
    return date("w", mktime(0, 0, 0,$pMonth, 1, $pYear));
}

//--------------------------------------------------------------------------------

    /**
     * @function: fn_nowweek($pYear,$pMonth,$pDay)
     * @return  : integer
     * @brief:    해당년/월/일의 요일 위치를 반환 ("w" : 0=일요일, 6=토요일)
     **/
function fn_nowweek($pYear,$pMonth,$pDay) {
    return date("w", mktime(0, 0, 0,$pMonth, $pDay, $pYear));
}

//------------------------------------------------------------------------------
    /**
     * @function: fn_lastweek($pYear,$pMonth)
     * @return  : integer
     * @brief:    해당년/월의 마지막날 위치를 반환  ("w" : 0=일요일, 6=토요일)
     **/
function fn_lastweek($pYear,$pMonth) {
    return date("w", mktime(0, 0, 0,$pMonth, fn_monthcount($pYear,$pMonth), $pYear));
}
//-----------------------------------------------------------------------------------
    /**
     * @function: fn_blankweekfirst($pYear,$pMonth)
     * @return  : integer
     * @brief:    해당년/월의 첫번째주 빈값을 구한다.
	 * @brief:    해당 년/월의 일수시작이 수요일(3) 이라면 일(0)/월(1)/화(2) 즉 3개는 빈값이다.
     **/
function fn_blankweekfirst($pYear,$pMonth) {
    return fn_firstweek($pYear,$pMonth);
}

//--------------------------------------------------------------------------------------

    /**
     * @function: fn_blankweeklast($pYear,$pMonth)
     * @return  : integer
     * @brief:    해당년/월의 마지막주 빈값을 구한다.
	 * @brief:    해당 년/월의 일수끝이 목요일(4) 이라면 금(5)/토(6) 즉 2개는 빈값이다.
     **/
function fn_blankweeklast($pYear,$pMonth) {
    return 6 - fn_lastweek($pYear,$pMonth);
}

//--------------------------------------------------------------------------------------

    /**
     * @function: fn_weekcountofmonth($pYear,$pMonth,$pDay)
     * @return  : integer
     * @brief:    해당 년/월/일이 당월 몇번째 주에 해당 되는지를 구한다.
	 * @brief:    해당 년/월/일이 당월 2번째 주에 포함된다면 2를 반환.
     **/
function fn_weekcountofmonth($pYear,$pMonth,$pDay) {
    $wrkday = $pDay + date("w", mktime(0, 0, 0,$pMonth, 1, $pYear)); //1일의 요일번호(일=0, 토=6)
	$weekcount = floor($wrkday, 7);	//소숫점이하 절사
	if ( $wrkday % 7 > 0 ) {
		$weekcount = $weekcount + 1;	
	}
    return $weekcount;		// n번째 주
}

//--------------------------------------------------------------------------------------

    /**
     * @function: fn_weekdaycountofmonth($pYear,$pMonth,$pDay)
     * @return  : integer
     * @brief:    해당 년/월/일의 요일이 당월 몇번째 요일에 해당되는지 구한다.
	 * @brief:    해당 년/월/일의 요일이 당월 2번째요일 이면 2를 반환.
     **/
function fn_weekdaycountofmonth($pYear,$pMonth,$pDay) {
	$k=0;		// 카운터
    $pYoil = date("w", mktime(0, 0, 0,$pMonth, $pDay, $pYear)); //해당일의 요일번호(일=0, 토=6)

	for ($i=1; $i<=$pDay; $i++) {								// 1일 부터 말일까지 수행
		$wrk1 = date("w", mktime(0, 0, 0,$pMonth, $i, $pYear));
		if ($wrk1 == $pYoil) {				// 요일 일치
			$k=$k+1;
		}
	}
    return $k;		// n번째 요일
}

//--------------------------------------------------------------------------------------

    /**
     * @function: fn_nsweekday($pYear, $pMonth, $pCount, $pYoil)
     * @return  : string
     * @brief:    해당년/월 n번째 x요일의 일자를 구한다
	 * @brief:     pCount: 숫자, pYoil: 숫자 (일요일(0) ... 토요일(6)).
     **/
function fn_nsweekday($pYear, $pMonth, $pCount, $pYoil) {
	$k=0;		// 카운터
	$j = date("t", mktime(0, 0, 0, $pMonth, 1, $pYear));	// 해당월의 날자수(말일) 값
	for ($i=1; $i<=$j; $i++) {								// 1일 부터 말일까지 수행
		$wrk1 = date("w", mktime(0, 0, 0,$pMonth, $i, $pYear));
		if ($wrk1 == $pYoil) {				// 요일 일치
			$k=$k+1;
			if ($k == $pCount) {			// 횟수 일치
				$wrkYmd =date("Y-n-j", mktime(0, 0, 0,$pMonth, $i, $pYear));
			}
		}
	}
    return $wrkYmd;
}

//--------------------------------------------------------------------------------------

    /**
     * @function: fn_nsweeknsweekday($pYear, $pMonth, $pCount, $pYoil)
     * @return  : string
     * @brief:    해당년/월 n번째 주 x요일의 일자를 구한다
	 * @brief:    pCount: 숫자, pYoil: 숫자 (일요일(0) ... 토요일(6)).
     **/
function fn_nsweeknsweekday($pYear, $pMonth, $pCount, $pYoil) {
	$k=1;		//  주 카운터
	$j = date("t", mktime(0, 0, 0, $pMonth, 1, $pYear));	// 해당월의 날자수(말일) 값
	for ($i=1; $i<=$j; $i++) {								// 1일 부터 말일까지 수행
		$wrk1 = date("w", mktime(0, 0, 0,$pMonth, $i, $pYear));	// 요일
		if ($i != 1 and $wrk1==0) {			// 첫날이 아니면서 일요일 이면 주 카운터 증가
			$k = $k + 1;
		}
		if ($wrk1 == $pYoil) {				// 요일 일치
			if ($k == $pCount) {			// 횟수 일치
				$wrkYmd =date("Y-n-j", mktime(0, 0, 0,$pMonth, $i, $pYear));
			}
		}
	}
    return $wrkYmd;
}

//--------------------------------------------------------------------------------------

    /**
     * @function: fn_nslastweekday($pYear, $pMonth, $pCount, $pYoil)
     * @return  : string
     * @brief:    해당년/월 끝에서 n번째 x요일의 일자를 구한다
	 * @brief:     pCount: 숫자, pYoil: 숫자 (일요일(0) ... 토요일(6)).
     **/
function fn_nslastweekday($pYear, $pMonth, $pCount, $pYoil) {
	$k=0;		//  주 카운터
	$j = date("t", mktime(0, 0, 0, $pMonth, 1, $pYear));	// 해당월의 날자수(말일) 값
	for ($i=$j; $i>=1; $i--) {								// 말일 부터 1일까지 수행
		$wrk1 = date("w", mktime(0, 0, 0,$pMonth, $i, $pYear));	// 요일
		if ($wrk1 == $pYoil) {				// 요일 일치
			$k = $k + 1;
			if ($k == $pCount) {			// 횟수 일치
				$wrkYmd =date("Y-n-j", mktime(0, 0, 0,$pMonth, $i, $pYear));
			}
		}
	}
    return $wrkYmd;
}

//--------------------------------------------------------------------------------
    /**
     * @function: fn_CalMain($pYear,$pMonth)
     * @return  : array
     * @brief:    주어진 년/월의 달력을 만든다.
	 * @brief:     2차원배열을 사용하여 틀을 만든다.
     * @brief:     가로(1주)는 무조건 7이 되므로 세로값만 알면 된다.
     * @brief:     빈칸은 null 값으로한다
     * @brief:     형태예제
     * @brief:     |일|월|화|수|목|금|토|
     * @brief:     | n| n| n| n| n| n| 1|
     * @brief:     | 2| 3| 4| 5| 6| 7| 8|
     * @brief:     | 9|10|11|12|13|14|15|
     * @brief:     |16|17|18|19|20|21|22|
     * @brief:     |23|24|25|26|27|28|29|
     * @brief:     |30|31| n| n| n| n| n|
     **/
function fn_CalMain($pYear,$pMonth) {
 
    //$aCal[][];       //달력의 틀을 위한 2차원배열
    //$intVertical;  //세로줄값
    //$intWeekcnt;   //주일수
    //$i;
	//$j; 
    //$k;            //루프전체 합
    //$intDay;       //일수 값
 
    //초기값 셋팅
    $k=0;
    $intDay=1;      //일

	//세로값얻는 방법 (그달의 일수 + 첫째주빈값 + 마지막주빈값)/7=세로값
    $intVertical = (fn_monthcount($pYear,$pMonth)+fn_blankweekfirst($pYear,$pMonth)+fn_blankweeklast($pYear,$pMonth))/7;
    $intWeekcnt = 7;
 
    //배열셋팅
    // array[세로사이즈][가로사이즈]
    $aCal[$intVertical][$intWeekcnt];
 
    //배열에 값 삽입
    for ($i=0; $i<$intVertical; $i++ ) { 
        for ($j=0; $j<$intWeekcnt; $j++ ){
            $k=$k+1;
            //k의값이 첫번째주 빈값보다 작거나 같을경우는 *을 삽입
            if ($k<=fn_blankweekfirst($pYear,$pMonth)) {
                $aCal[$i][$j] = "*";
			}
            //k의값이 첫번째주빈값이상이며, 일자가 해당월의 마지막 일자 값과 작거나같을경우는 일수를 삽입
            else {
				if ($intDay<=fn_monthcount($pYear,$pMonth)) {
                $aCal[$i][$j] = $intDay;
                $intDay = $intDay+1;
				}

				//이외의 값은 *로 채운다
				else {
					$aCal[$i][$j] = "*";
				}
			}
		}
	}
    return $aCal;
}

//--------------------------------------------------------------------------------------

    /**
     * @function: fn_smallcalendar()
     * @return  : string
     * @brief:    소형 당월 칼런다 HTML코드 출력
	 * @brief:     
     **/

function fn_smallcalendar(){
    $year = date("Y");
    $month = date("n");
    $day = date("d");
    $day_max = date("t",mktime(0,0,0,$month,1,$year));
    $week_start = date("w",mktime(0,0,0,$month,1,$year));
    $i = 0;
    $j = 0;
    $html = "
".sprintf("%d-%02d-%02d",$year,$month,$day)."
"; while ($j<$day_max){ if ($i<$week_start) { $html .= "
·
"; } else { if ($i%7==0) $font_color = " RED"; else if ($i%7==6) $font_color = " BLUE"; else $font_color = ""; if ($day == ($j+1)) $font_weight = " B"; else $font_weight = ""; $html .= "
" . ($j+1) . "
"; $j ++; } $i ++; } while ($i%7!==0){ $html .= "
·
"; $i ++; } $html .= "
"; return $html; } //-------------------------------------------------------------------------------------- /** * @function: fn_sunlunar_data() * @return : string(13자리-13자리-... 170개) * @brief: 음력-양력 변환위한 자료 **/ function fn_sunlunar_data() { return "1212122322121-1212121221220-1121121222120-2112132122122-2112112121220-2121211212120-2212321121212-2122121121210-2122121212120-1232122121212-1212121221220-1121123221222-1121121212220-1212112121220-2121231212121-2221211212120-1221212121210-2123221212121-2121212212120-1211212232212-1211212122210-2121121212220-1212132112212-2212112112210-2212211212120-1221412121212-1212122121210-2112212122120-1231212122212-1211212122210-2121123122122-2121121122120-2212112112120-2212231212112-2122121212120-1212122121210-2132122122121-2112121222120-1211212322122-1211211221220-2121121121220-2122132112122-1221212121120-2121221212110-2122321221212-1121212212210-2112121221220-1231211221222-1211211212220-1221123121221-2221121121210-2221212112120-1221241212112-1212212212120-1121212212210-2114121212221-2112112122210-2211211412212-2211211212120-2212121121210-2212214112121-2122122121120-1212122122120-1121412122122-1121121222120-2112112122120-2231211212122-2121211212120-2212121321212-2122121121210-2122121212120-1212142121212-1211221221220-1121121221220-2114112121222-1212112121220-2121211232122-1221211212120-1221212121210-2121223212121-2121212212120-1211212212210-2121321212221-2121121212220-1212112112210-2223211211221-2212211212120-1221212321212-1212122121210-2112212122120-1211232122212-1211212122210-2121121122210-2212312112212-2212112112120-2212121232112-2122121212110-2212122121210-2112124122121-2112121221220-1211211221220-2121321122122-2121121121220-2122112112322-1221212112120-1221221212110-2122123221212-1121212212210-2112121221220-1211231212222-1211211212220-1221121121220-1223212112121-2221212112120-1221221232112-1212212122120-1121212212210-2112132212221-2112112122210-2211211212210-2221321121212-2212121121210-2212212112120-1232212122112-1212122122110-2121212322122-1121121222120-2112112122120-2211231212122-2121211212120-2122121121210-2124212112121-2122121212120-1212121223212-1211212221220-1121121221220-2112132121222-1212112121220-2121211212120-2122321121212-1221212121210-2121221212120-1232121221212-1211212212210-2121123212221-2121121212220-1212112112220-1221231211221-2212211211220-1212212121210-2123212212121-2112122122120-1211212322212-1211212122210-2121121122120-2212114112122-2212112112120-2212121211210-2212232121211-2122122121210-2112122122120-1231212122212-1211211221220-2121121321222-2121121121220-2122112112120-2122141211212-1221221212110-2121221221210-2114121221221"; //1881-2050 } //------------------------------------------------------------------------ /** * @function: fn_lun2sol($pYear,$pMonth,$pDay) * @return : string(yyyy-mm-dd-요일) * @brief: 음력을 양력으로 변환하는 함수 **/ function fn_lun2sol($pYear,$pMonth,$pDay) { $getYEAR = (int)$pYear; $getMONTH = (int)$pMonth; $getDAY = (int)$pDay; //$getYEAR = (int)substr($yyyymmdd,0,4); //$getMONTH = (int)substr($yyyymmdd,4,2); //$getDAY = (int)substr($yyyymmdd,6,2); $arrayDATASTR = fn_sunlunar_data(); $arrayDATA = explode("-",$arrayDATASTR); $arrayLDAYSTR="31-0-31-30-31-30-31-31-30-31-30-31"; $arrayLDAY = explode("-",$arrayLDAYSTR); $arrayYUKSTR="갑-을-병-정-무-기-경-신-임-계"; $arrayYUK = explode("-",$arrayYUKSTR); $arrayGAPSTR="자-축-인-묘-진-사-오-미-신-유-술-해"; $arrayGAP = explode("-",$arrayGAPSTR); $arrayDDISTR="쥐-소-호랑이-토끼-용-뱀-말-양-원숭이-닭-개-돼지"; $arrayDDI = explode("-",$arrayDDISTR); $arrayWEEKSTR="일-월-화-수-목-금-토"; $arrayWEEK = explode("-",$arrayWEEKSTR); if ($getYEAR <= 1881 || $getYEAR >= 2050) { //년수가 해당일자를 넘는 경우 $YunMonthFlag = 0; return false; //년도 범위가 벗어남.. } if ($getMONTH > 12) { // 달수가 13이 넘는 경우 $YunMonthFlag = 0; return false; //달수 범위가 벗어남.. } $m1 = $getYEAR - 1881; if (substr($arrayDATA[$m1],12,1) == 0) { // 윤달이 없는 해임 $YunMonthFlag = 0; } else { if (substr($arrayDATA[$m1],$getMONTH, 1) > 2) { $YunMonthFlag = 1; } else { $YunMonthFlag = 0; } } //------------- $m1 = -1; $td = 0; if ($getYEAR > 1881 && $getYEAR < 2050) { $m1 = $getYEAR - 1882; for ($i=0;$i<=$m1;$i++) { for ($j=0;$j<=12;$j++) { $td = $td + (substr($arrayDATA[$i],$j,1)); } if (substr($arrayDATA[$i],12,1) == 0) { $td = $td + 336; } else { $td = $td + 362; } } } else { $gf_lun2sol = 0; } $m1++; $n2 = $getMONTH - 1; $m2 = -1; while(1) { $m2++; if (substr($arrayDATA[$m1], $m2, 1) > 2) { $td = $td + 26 + (substr($arrayDATA[$m1], $m2, 1)); $n2++; } else { if ($m2 == $n2) { if ($gf_yun) { $td = $td + 28 + (substr($arrayDATA[$m1], $m2, 1)); } break; } else { $td = $td + 28 + (substr($arrayDATA[$m1], $m2, 1)); } } } $td = $td + $getDAY + 29; $m1 = 1880; while(1) { $m1++; if ($m1 % 400 == 0 || $m1 % 100 != 0 && $m1 % 4 == 0) { $leap = 1; } else { $leap = 0; } if ($leap == 1) { $m2 = 366; } else { $m2 = 365; } if ($td < $m2) break; $td = $td - $m2; } $syear = $m1; $arrayLDAY[1] = $m2 - 337; $m1 = 0; while(1) { $m1++; if ($td <= $arrayLDAY[$m1-1]) { break; } $td = $td - $arrayLDAY[$m1-1]; } $smonth = $m1; $sday = $td; $y = $syear - 1; $td = intval($y*365) + intval($y/4) - intval($y/100) + intval($y/400); if ($syear % 400 == 0 || $syear % 100 != 0 && $syear % 4 == 0) { $leap = 1; } else { $leap = 0; } if ($leap == 1) { $arrayLDAY[1] = 29; } else { $arrayLDAY[1] = 28; } for ($i=0;$i<=$smonth-2;$i++) { $td = $td + $arrayLDAY[$i]; } $td = $td + $sday; $w = $td % 7; $sweek = $arrayWEEK[$w]; $gf_lun2sol = 1; return($syear."-".$smonth."-".$sday."-".$sweek); } //-------------------------------------------------------------------------------------- /** * @function: fn_sol2lun($pYear,$pMonth,$pDay) * @return : string(yyyy-mm-dd-간지-띠) * @brief: 양력을 음력으로 변환하는 함수 **/ function fn_sol2lun($pYear,$pMonth,$pDay) { $getYEAR = $pYear; $getMONTH = $pMonth; $getDAY = $pDay; //$getYEAR = (int)substr($yyyymmdd,0,4); //$getMONTH = (int)substr($yyyymmdd,4,2); //$getDAY = (int)substr($yyyymmdd,6,2); $arrayDATASTR = fn_sunlunar_data(); $arrayDATA = explode("-",$arrayDATASTR); $arrayLDAYSTR="31-0-31-30-31-30-31-31-30-31-30-31"; $arrayLDAY = explode("-",$arrayLDAYSTR); $arrayYUKSTR="갑-을-병-정-무-기-경-신-임-계"; $arrayYUK = explode("-",$arrayYUKSTR); $arrayGAPSTR="자-축-인-묘-진-사-오-미-신-유-술-해"; $arrayGAP = explode("-",$arrayGAPSTR); $arrayDDISTR="쥐-소-호랑이-토끼-용-뱀-말-양-원숭이-닭-개-돼지"; $arrayDDI = explode("-",$arrayDDISTR); $arrayWEEKSTR="일-월-화-수-목-금-토"; $arrayWEEK = explode("-",$arrayWEEKSTR); $dt = $arrayDATA; for ($i=0;$i<=168;$i++) { $dt[$i] = 0; for ($j=0;$j<12;$j++) { switch (substr($arrayDATA[$i],$j,1)) { case 1: $dt[$i] += 29; break; case 3: $dt[$i] += 29; break; case 2: $dt[$i] += 30; break; case 4: $dt[$i] += 30; break; } } switch (substr($arrayDATA[$i],12,1)) { case 0: break; case 1: $dt[$i] += 29; break; case 3: $dt[$i] += 29; break; case 2: $dt[$i] += 30; break; case 4: $dt[$i] += 30; break; } } $td1 = 1880 * 365 + (int)(1880/4) - (int)(1880/100) + (int)(1880/400) + 30; $k11 = $getYEAR - 1; $td2 = $k11 * 365 + (int)($k11/4) - (int)($k11/100) + (int)($k11/400); if ($getYEAR % 400 == 0 || $getYEAR % 100 != 0 && $getYEAR % 4 == 0) { $arrayLDAY[1] = 29; } else { $arrayLDAY[1] = 28; } if ($getMONTH > 13) { $gf_sol2lun = 0; } if ($getDAY > $arrayLDAY[$getMONTH-1]) { $gf_sol2lun = 0; } for ($i=0;$i<=$getMONTH-2;$i++) { $td2 += $arrayLDAY[$i]; } $td2 += $getDAY; $td = $td2 - $td1 + 1; $td0 = $dt[0]; for ($i=0;$i<=168;$i++) { if ($td <= $td0) { break; } $td0 += $dt[$i+1]; } $ryear = $i + 1881; $td0 -= $dt[$i]; $td -= $td0; if (substr($arrayDATA[$i], 12, 1) == 0) { $jcount = 11; } else { $jcount = 12; } $m2 = 0; for ($j=0;$j<=$jcount;$j++) { // 달수 check, 윤달 > 2 (by harcoon) if (substr($arrayDATA[$i],$j,1) <= 2) { $m2++; $m1 = substr($arrayDATA[$i],$j,1) + 28; $gf_yun = 0; $yundal = null; // add ksc } else { $m1 = substr($arrayDATA[$i],$j,1) + 26; $gf_yun = 1; $yundal = "윤달"; // add ksc } if ($td <= $m1) { break; } $td = $td - $m1; } $k1=($ryear+6) % 10; $syuk = $arrayYUK[$k1]; $k2=($ryear+8) % 12; $sgap = $arrayGAP[$k2]; $sddi = $arrayDDI[$k2]; $gf_sol2lun = 1; return ($ryear."-".$m2."-".$td."-".$syuk.$sgap."년-".$sddi."띠-".$yundal); } //------------------------------------------------------------------------ /** * @function: fn_sol2lun_ary($pYear, $pMonth) * @return : array * @brief: 년간 양력 일자에 대응되는 음력일자 어레이 리턴 **/ Function fn_sol2lun_ary($pYear, $pMonth) { /****************************************************** *년간 양력 일자에 대응되는 음력일자 어레이 (예:2009-7-15-윤달) *******************************************************/ // For ($i = 0; $i<13; $i++) { // For ($j = 0; $j <32; $j++ ) { // $aHoli[$i][$j] = null; // } // } $aHoli = null; for ($i=$pMonth; $i < $pMonth+1; $i++ ) { //당월만 for ($j=0; $j < 32; $j++ ) { if ($i > 0 and $j>0 and $j < 32) { // 1-12 $temp01 = explode("-",fn_sol2lun($pYear,$i,$j)); $iSunYmd =$temp01[0]."-".$temp01[1]."-".$temp01[2]; if ($temp01[5] != null) { //윤달일 경우 - 붙여서 출력 $Yundal = "-".$temp01[5]; } else { $Yundal = null; } $aHoli[$i][$j] = $iSunYmd.$Yundal; } } } return $aHoli; } //------------------------------------------------------------------------ /** * @function: fn_ganji_ary($pYear, $pMonth, $pDay) * @return : array * @brief: 간지가 새로 시작되는 새해 시작일을 입력받아 양력에 대응되는 세차, 일진 어레이 리턴 * @brief: 유효기간 1902 - 2037 **/ Function fn_ganji_ary($pYear, $pMonth, $pDay) { //***************************************************** // 년간 양력 일자에 대응되는 간지 어레이 (세차, 일진) 계산 // // 새해의 시작을 구분 할때 사람에 따라 이론이 있으니 아래 내용 참고 하세요. // // "주역을 하시는 분들은 새해의 시작을 동지로 보고, // 명리학이나 사주를 보는 분들은 새해의 시작을 입춘으로 보는것 같습니다만, // 새해의 시작은 정월 초하루입니다." - (한국천문연구원 홈페이지내 질문답변 게시판에서 발췌) // // 위와 같이 새해 시작점은 사람에 따라 기준점이 다르다고 합니다. // // 그러나, 기준일이 바뀌면 일자의 간지(일진)는 변하지 않지만 년의 간지(세차)와 월의 간지(월권)는 // 변경이 되니 얼마나 난감한 일인지 모르겠습니다. // 사실 어느 기준을 적용하느냐에 따라 달라지는 자료(팔자)를 이용해 흔히들 사주를 본다거나 하는 일이 // 조금은 황당하다는 생각도 듭니다. // // 그러나 간지는 우리 선조들이 계속 사용해 왔고 그중 일진은 과거 수천년 동안 그 주기가 변하지 않고 // 계속 이어져 내려 왔다고 하니 나름 매우 중요한 자료라고 생각 합니다. // // 본 함수는 날짜를 고정 하지 않고 호출시 넘어온 일자를 새해 시작일로 하여 세차와 일진을 계산 합니다. // 넘어온 날이 8월 보다 적을 경우는 설날과, 입춘이라고 가정 햇습니다. // // 또 고려 할 다른 문제점은 입춘이나 동지를 시작일로 할경우는 입춘이나 동지 일자를 강제로 지정하지 않고 // 계산을 할 경우(본 함수) 그 계산이 정확해야 되는데 정확한 24절기 계산이 쉬운일이 아니라고 합니다. // 현재 구할 수 있는 24절기 계산 함수들은 천체 운동 계산에 약간의 오차가 있는듯 하며, // 그 결과 24절기가 간혹 하루 정도 차이가 나는 경우가 있음을 염두에 두시고 이용 하시기 바랍니다. //(실제 계산상 차이가 몇 시간 이라고 해도 이것이 24:00시 기준 전날인지 다음날 인지에 따라서도 날자가 바뀜니다.) // //참고로 한국천문연구원이 게시한 24절기는 http://www.kasi.re.kr/Knowledge/almanac.aspx 에서 확인할 수 있습니다. //****************************************************** if ($pYear<1902 or $pYear>2037) { // 유효기간 1902-2037 return; } // For ($i = 0; $i<13; $i++) { // For ($j = 0; $j <32; $j++ ) { // $aHoli[$i][$j] = null; // } // } $aHoli = null; $arr_gan = array("甲","乙","丙","丁","戊","己","庚","辛","壬","癸"); $arr_ji = array("子","丑","寅","卯","辰","巳","午","未","申","酉","戌","亥"); $arr_ganji = array('甲子','乙丑','丙寅','丁卯','戊辰','己巳','庚午','辛未','壬申','癸酉','甲戌','乙亥', '丙子','丁丑','戊寅','己卯','庚辰','辛巳','壬午','癸未','甲申','乙酉','丙戌','丁亥', '戊子','己丑','庚寅','辛卯','壬辰','癸巳','甲午','乙未','丙申','丁酉','戊戌','己亥', '庚子','辛丑','壬寅','癸卯','甲辰','乙巳','丙午','丁未','戊申','己酉','庚戌','辛亥', '壬子','癸丑','甲寅','乙卯','丙辰','丁巳','戊午','己未','庚申','辛酉','壬戌','癸亥'); // 월건을 위해 세차의 간지중 간만 출력을 위해 $arr_ganji_WG = array('甲','乙','丙','丁','戊','己','庚','辛','壬','癸','甲','乙', '丙','丁','戊','己','庚','辛','壬','癸','甲','乙','丙','丁', '戊','己','庚','辛','壬','癸','甲','乙','丙','丁','戊','己', '庚','辛','壬','癸','甲','乙','丙','丁','戊','己','庚','辛', '壬','癸','甲','乙','丙','丁','戊','己','庚','辛','壬','癸'); $baseYear = 1902; // 1902년 1월 1일: 세차-"임인壬寅", 일진-"갑신甲申" 인데 // 어레이 arr_ganji 값으로 세차는 "38, 일진은 "20"에 해당 $base_date = "1902-1-1"; // ---세차계산 (절기의 새해 시작점)--- $k = ($pYear - $baseYear+38) % 60 ; // 60으로 나눈 나머지 // 해당년의 세차를 arr_ganji 어레이에 맞게 조정 (38) if ($pMonth < 8 ) { // 기준월 이 8월 보다 작은경우(설날과 입춘이 기준일경우) if ($k-1 < 0 ) { $Secha1=$arr_ganji_WG[59]."-".$arr_ganji[59]; // 기준일 이전의 세차 } else { $Secha1=$arr_ganji_WG[$k-1]."-".$arr_ganji[$k-1]; } $Secha2 =$arr_ganji_WG[$k]."-".$arr_ganji[$k]; // 기준일 부터의 세차 } else { // 동지일 경우 if ($k+1 > 59 ) { $Secha2=$arr_ganji_WG[0]."-".$arr_ganji[0]; // 기준일 부터의 세차 } else { $Secha2=$arr_ganji_WG[$k+1]."-".$arr_ganji[$k+1]; } $Secha1 = $arr_ganji_WG[$k]."-".$arr_ganji[$k]; // 기준일 이전의 세차 } // ---일진 추가 --- for ($i=1; $i < 13; $i++ ) { // 입력받은 월 일은 새해 시작일임. for ($j=1; $j < 32; $j++ ) { if ($i > 0 and $j>0 and $j < 32) { $startdate = date("Y-n-j", mktime(0, 0, 0, $i, $j, $pYear)); $pastdays = (strtotime($startdate)-strtotime($base_date))/86400; // 1902-1-1 부터 해당년 1월 1일 직전 까지 경과일 $k = ($pastdays+21) % 60; // 해당일의 일진을 arr_ganji 어레이에 맞게 조정 (21) if ($i < $pMonth or $i == $pMonth and $j < $pDay) { $aHoli[$i][$j] = $Secha1."年-".$arr_ganji[$k]."日"; } else { $aHoli[$i][$j] = $Secha2."年-".$arr_ganji[$k]."日"; } } } } return $aHoli; } //------------------------------------------------------------------------ /** * @function: fn_jeolki_ganji_ary($pYear,$pJeolki=array(),$pOption) * @return : array * @brief: 년간 양력 일자에 대응되는 24절기, 간지 등을 입력한 어레이 리턴 **/ Function fn_jeolki_ganji_ary($pYear,$pJeolki,$pOption) { /****************************************************** * 년간 양력 일자에 대응되는 절기 어레이 * class.solar.php function에서 나온 어레이를 입력받아 양력 일자에 해당하는 * 어레이에 절기 이름을 입력. * 절기 일자를 얻은 함수는 $terms = solar::terms(date('Y'),1,12,&$sun) * $terms 어레이는 1232 개의 요소를 가짐(0월0일 부터 12월 31일) * 예로 4월 5일이 청명 이라면 $terms[405]에 "청명" 이 들어있음. *******************************************************/ // For ($i = 0; $i<13; $i++) { // For ($j = 0; $j <32; $j++ ) { // $aHoli[$i][$j] = null; // } // } $aHoli = null; //---어레이 구조조정 ------- For ($i = 0; $i<13; $i++) { For ($j = 0; $j <32; $j++ ) { if ($j<10) { //1-9일 $k = "0".$j; $jeolki[$i][$j] = $pJeolki[$i.$k]; } else { $jeolki[$i][$j] = $pJeolki[$i.$j]; } } } // 간지 시작 기준날자 설정 : 입력 받은 option에 의해. switch ($pOption) { case (1): $ganjioption = "설날"; // 설날을 새해 첫날로 간주. break; case (2): $ganjioption = "입춘"; // 명리학, 사주 위주 (입춘을 새해 첫날로 간주). break; case (3): $ganjioption = "동지"; // 주자학 위주 (동지를 새해 첫날로 간주). break; default: // option 없을때 $ganjioption = "설날"; // 설날을 새해 첫날로 간주. break; } // 음력 1월 1일 양력날자 구하기 (세차 계산을 위해)------------------------ $lunfirstday = explode("-",fn_lun2sol($pYear,1,1)); $SeolMM = $lunfirstday[1]; // 세차(년 간지)가 바뀌는 일자 월 (음력 1월 1일) $SeolDD = $lunfirstday[2]; // 세차(년 간지)가 바뀌는 일자 일 (음력 1월 1일) //---option에따른 월권을 위한 임시 절기 어레이 생성 설날은 음력 월로 구분하니 필요 없음----- For ($i = 1; $i<13; $i++) { For ($j = 1; $j <32; $j++ ) { //설날기점: 매월 음력 1일에 구분으로 절기와 무관 if ($ganjioption == "설날" ) { for ($i=1; $i < 13; $i++ ) { for ($j=1; $j < 32; $j++ ) { $wrklunday = explode("-",fn_sol2lun($pYear,$i,$j)); // 음력 날자 구하기 if ($wrklunday[2] == 1 and $wrklunday[5] == null) { // 월첫날이며 윤달이 아닐때 $WGjeolki[$i][$j] = $wrklunday[0]."-".$wrklunday[1]."-".$wrklunday[2]; } } } } } } //---24 절기 주석처리 및 주요날자 얻기----------------------- for ($i=1; $i < 13; $i++ ) { for ($j=1; $j < 32; $j++ ) { $aHoli[$i][$j] = $jeolki[$i][$j]; // 콤멘트 추가 switch ($aHoli[$i][$j]) { case ("소한"): $aHoli[$i][$j] = $aHoli[$i][$j].""; break; case ("대한"): $aHoli[$i][$j] = $aHoli[$i][$j].""; break; case ("입춘"): $aHoli[$i][$j] = $aHoli[$i][$j].""; $IpchunMM = $i; // 입춘 일자 월 (입춘) $IpchunDD = $j; // 입춘 일자 일 (입춘) break; case ("우수"): $aHoli[$i][$j] = $aHoli[$i][$j].""; break; case ("경칩"): $aHoli[$i][$j] = $aHoli[$i][$j].""; break; case ("춘분"): $aHoli[$i][$j] = $aHoli[$i][$j].""; $ChunbunMM = $i; // 춘분 일자 월 $ChunbunDD = $j; // 춘분 일자 일 break; case ("청명"): $aHoli[$i][$j] = $aHoli[$i][$j].""; break; case ("곡우"): $aHoli[$i][$j] = $aHoli[$i][$j].""; break; case ("입하"): $aHoli[$i][$j] = $aHoli[$i][$j].""; break; case ("소만"): $aHoli[$i][$j] = $aHoli[$i][$j].""; break; case ("망종"): $aHoli[$i][$j] = $aHoli[$i][$j].""; break; case ("하지"): $aHoli[$i][$j] = $aHoli[$i][$j].""; $HajiMM = $i; // 하지 일자 월 $HajiDD = $j; // 하지 일자 일 break; case ("소서"): $aHoli[$i][$j] = $aHoli[$i][$j].""; break; case ("대서"): $aHoli[$i][$j] = $aHoli[$i][$j].""; break; case ("입추"): $aHoli[$i][$j] = $aHoli[$i][$j].""; $IpchuMM = $i; // 입추 일자 월 $IpchuDD = $j; // 입추 일자 일 break; case ("처서"): $aHoli[$i][$j] = $aHoli[$i][$j].""; break; case ("백로"): $aHoli[$i][$j] = $aHoli[$i][$j].""; break; case ("추분"): $aHoli[$i][$j] = $aHoli[$i][$j].""; $ChubunMM = $i; // 추분 일자 월 $ChubunDD = $j; // 추분 일자 일 break; case ("한로"): $aHoli[$i][$j] = $aHoli[$i][$j].""; break; case ("상강"): $aHoli[$i][$j] = $aHoli[$i][$j].""; break; case ("입동"): $aHoli[$i][$j] = $aHoli[$i][$j].""; break; case ("소설"): $aHoli[$i][$j] = $aHoli[$i][$j].""; break; case ("대설"): $aHoli[$i][$j] = $aHoli[$i][$j].""; break; case ("동지"): $aHoli[$i][$j] = $aHoli[$i][$j].""; $DongjiMM = $i; // 동지 일자 월 $DongjiDD = $j; // 동지 일자 일 } } } // ---- 간지 시작일 을 조건에 따라 설정 ---- if ($ganjioption == "설날"): $GanjiStartMM = $SeolMM; $GanjiStartDD = $SeolDD; elseif ($ganjioption == "입춘"): $GanjiStartMM = $IpchunMM; $GanjiStartDD = $IpchunDD; elseif ($ganjioption == "동지"): $GanjiStartMM = $DongjiMM; $GanjiStartDD = $DongjiDD; else: $GanjiStartMM = $SeolMM; // 설날로 설정 $GanjiStartDD = $SeolDD; endif; // --세차와 일진을 구한다------------------------------ $arr_Secha = fn_ganji_ary($pYear, $GanjiStartMM, $GanjiStartDD); // --- 초복, 중복, 말복 계산(하지, 추분 및 일진을 조합하여 계산------------- // 초복, 중복: 하지 로부터 세 번째(초복), 네번째(중복) 돌아오는 경일 // 말복 : 입추로부터 첫 번째 경일 // 하지 일자 월, 일: $HajiMM $HajiDD // 입추 일자 월, 일: $IpchuMM $IpchuDD // 경일:'庚午','庚辰','庚寅','庚子','庚戌','庚申' // 문자열 자르기가 안되서 비교로 처리함 //-- 초복, 중복 -------- $k = 0; For ($i = $HajiMM; $i<13; $i++) { For ($j = 1; $j <32; $j++ ) { if ($i > $HajiMM or $i = $HajiMM and $j >= $HajiDD ) { $temp01 = explode("-",$arr_Secha[$i][$j]); $wrkfld01 = $temp01[2]; if($wrkfld01 == "庚午日" or $wrkfld01 == "庚辰日" or $wrkfld01 == "庚寅日" or $wrkfld01 == "庚子日" or $wrkfld01 == "庚戌日" or $wrkfld01 == "庚申日") { $k = $k + 1; if ($k == 3) { $aHoli[$i][$j] = $aHoli[$i][$j]."초복"; } if ($k == 4) { $aHoli[$i][$j] = $aHoli[$i][$j]."중복"; break; } } } } } // -- 말복 --- $k = 0; For ($i = $IpchuMM; $i<13; $i++) { For ($j = 1; $j <32; $j++ ) { if ($i > $IpchuMM or $i = $IpchuMM and $j >= $IpchuDD ) { $temp01 = explode("-",$arr_Secha[$i][$j]); $wrkfld01 = $temp01[2]; if($wrkfld01 == "庚午日" or $wrkfld01 == "庚辰日" or $wrkfld01 == "庚寅日" or $wrkfld01 == "庚子日" or $wrkfld01 == "庚戌日" or $wrkfld01 == "庚申日") { $k = $k + 1; if ($k == 1) { $aHoli[$i][$j] = $aHoli[$i][$j]."말복"; break; } } } } } // 기타 음력절기 상 특별한날 ------------------------ $aMoon[5][5] = "단오"; $aMoon[7][7] = "칠석"; $aMoon[7][15] = "백중"; for ($i=1; $i < 13; $i++ ) { for ($j=1; $j < 32; $j++ ) { if ($aMoon[$i][$j] != null) { // 자료가 있으면 양력으로 환산하여 자료 추가 $temp01 = explode("-",fn_lun2sol($pYear,$i,$j)); $iLunYmd =date("Y-n-j", mktime(0, 0, 0,$temp01[1], $temp01[2], $temp01[0])); $temp02 = explode("-",$iLunYmd); $aHoli[$temp02[1]][$temp02[2]] = $aHoli[$temp02[1]][$temp02[2]].$aMoon[$i][$j]; } } } //---- 한식일자 구하기: 한식은 전년도 동지에서 105일째 되는 날인바 // 전년도 동지일을 기준으로 계산 하여야 하나 편의를 위해 테이블로 작업함 // 아래 테이블은 2000년부터 2050년까지 4월 6일인 경우의 해이고 // 테이블에 없는 해는 4월 5일이 한식임. $arr_HansikYear = array('2002','2003','2006','2007','2010','2011','2014','2015','2018','2019','2022','2023','2027','2031','2035','2039','2043','2047'); if ($pYear >=2000 and $pYear <=2050) { for ($i=0; $i<50; $i++ ) { if ($arr_HansikYear[$i] == $pYear) { $wrk_hansik = $i; break; } } if ($wrk_hansik != null ) { $aHoli[4][6] = $aHoli[4][6]."한식"; } else { $aHoli[4][5] = $aHoli[4][5]."한식"; } } //---- 절기와 간지 합하여 어레이 리턴--- For ($i = 1; $i<13; $i++) { For ($j = 1; $j <32; $j++ ) { $aHoli[$i][$j] = $arr_Secha[$i][$j]."-".$arr_WolGeon[$i][$j]."-".$aHoli[$i][$j]; } } return $aHoli; } //----------------------------------------------------------------------------------- /** * @function: fn_easterday($pYear) * @return : string * @brief: 해당년 부활절 일자를 구한다 **/ function fn_easterday($pYear) { $k=easter_days($pYear); if ($k>10) { $wrkYmd =date("Y-n-j", mktime(0, 0, 0,4, $k-10, $pYear)); } else { $wrkYmd =date("Y-n-j", mktime(0, 0, 0,3, $k+21, $pYear)); } return $wrkYmd; } //-------------------------------------------------------------------------------------- /** * @function: fn_HolidayChk($pYear, $pMonth) * @return : array * @brief: 휴일 여부 **/ Function fn_HolidayChk($pYear, $pMonth) { /****************************************************** *휴일은 음력에서 1.1(설)/8.15(추석)/4.8(석가탄신일) 이 있으며 *양력으로 1.1(신정)/3.1(삼일절)/5.5(어린이날)/6.6(현충일)/8.15(광복절)/10.3(개천절)/12.25(성탄절) 이다. (4.5: 2006년부터 식목일은 법정 공휴일에서 법정기념일 기년일로바뀜) (7.17: 2008년 부터 제헌절은 법정 공휴일에서 법정기념일 기년일로바뀜) *설과 추석은 앞뒤로 하루씩 휴일이 더해진다. *******************************************************/ // For ($i = 0; $i<13; $i++) { // For ($j = 0; $j <32; $j++ ) { // $aHoli[$i][$j] = null; // } // } $aHoli = null; //양력 휴일(국경일,기념일중 휴일) $aHoli[1][1] = "신정 "; $aHoli[3][1] = "삼일절 "; $aHoli[5][5] = "어린이날 "; $aHoli[6][6] = "현충일 "; // $aHoli[7][17] = "제헌절 "; // 국경일이나 휴일아님 $aHoli[8][15] = "광복절 "; $aHoli[10][3] = "개천절 "; // $aHoli[10][9] = "한글날 "; // 국경일이나 휴일아님 $aHoli[12][25] = "성탄절 "; //음력휴일 //(설날) $temp01 = explode("-",fn_lun2sol($pYear,1,1)); $iLunYmd =date("Y-n-j", mktime(0, 0, 0,$temp01[1], $temp01[2], $temp01[0])); $iLunYmdpre =date("Y-n-j", mktime(0, 0, 0,$temp01[1], $temp01[2]-1, $temp01[0])); $iLunYmdnext =date("Y-n-j", mktime(0, 0, 0,$temp01[1], $temp01[2]+1, $temp01[0])); $temp02 = explode("-",$iLunYmd); $aHoli[$temp02[1]][$temp02[2]] = $aHoli[$temp02[1]][$temp02[2]]."설날"; $temp02 = explode("-",$iLunYmdpre); $aHoli[$temp02[1]][$temp02[2]] = $aHoli[$temp02[1]][$temp02[2]]."설연휴"; $temp02 = explode("-",$iLunYmdnext); $aHoli[$temp02[1]][$temp02[2]] = $aHoli[$temp02[1]][$temp02[2]]."설연휴"; //(추석) $temp01 = explode("-",fn_lun2sol($pYear,8,15)); $iLunYmd =date("Y-n-j", mktime(0, 0, 0,$temp01[1], $temp01[2], $temp01[0])); $iLunYmdpre =date("Y-n-j", mktime(0, 0, 0,$temp01[1], $temp01[2]-1, $temp01[0])); $iLunYmdnext =date("Y-n-j", mktime(0, 0, 0,$temp01[1], $temp01[2]+1, $temp01[0])); $temp02 = explode("-",$iLunYmd); $aHoli[$temp02[1]][$temp02[2]] = $aHoli[$temp02[1]][$temp02[2]]."추석"; $temp02 = explode("-",$iLunYmdpre); $aHoli[$temp02[1]][$temp02[2]] = $aHoli[$temp02[1]][$temp02[2]]."추석연휴"; $temp02 = explode("-",$iLunYmdnext); $aHoli[$temp02[1]][$temp02[2]] = $aHoli[$temp02[1]][$temp02[2]]."추석연휴"; //(석가탄신일) $temp01 = explode("-",fn_lun2sol($pYear,4,8)); $iLunYmd =date("Y-n-j", mktime(0, 0, 0,$temp01[1], $temp01[2], $temp01[0])); $temp02 = explode("-",$iLunYmd); $aHoli[$temp02[1]][$temp02[2]] = $aHoli[$temp02[1]][$temp02[2]]."석가탄신일"; return $aHoli; } //------------------------------------------------------------------------ /** * @function: fn_MemdayChk($pYear, $pMonth) * @return : boolean * @brief: 기념일 여부 **/ Function fn_MemdayChk($pYear, $pMonth) { /****************************************************** *법정 기념일과 공휴일이 아닌 국경일 *음력 기념일 등 *******************************************************/ // For ($i = 0; $i<13; $i++) { // For ($j = 0; $j <32; $j++ ) { // $aHoli[$i][$j] = null; // } // } $aHoli = null; //음력 기념일 $aMoon[월][일][평달=0, 윤달=1] 형식으로.... //음력은 일년에 같은 월 같은 날이 두번 들어 있을 수 있음. // $aMoon[11][9][0] = $aMoon[11][9][0]."조부기일
"; // 음력11월 9일 (평달) // $aMoon[8][26][0] = $aMoon[8][26][0]."조카생일
"; // 음력8월 26일 (평달) // $aMoon[5][16][1] = $aMoon[5][16][1]." **윤달테스트**"; // 윤달 // $aMoon[11][24][0] = $aMoon[11][24][0]." **중복테스트**"; // 1년에 두번 예:2008년 $iLunYmd_arr = fn_sol2lun_ary($pYear, $pMonth); // 당월 양력에 해당되는 음력일자 어레이 얻기 for ($i=1; $i < 13; $i++ ) { for ($j=1; $j < 32; $j++ ) { if ($aMoon[$i][$j][0] != null or $aMoon[$i][$j][1] != null ) { // 기념일이 있으면.. $lunmemMM = $i; $lunmemDD = $j; for ($k=$pMonth; $k < $pMonth+1; $k++ ) { for ($d=1; $d < 32; $d++ ) { $iLunYmd = explode("-",$iLunYmd_arr[$k][$d]); // 음력 어레이를 읽어서 $iLunMM = $iLunYmd[1]; $iLunDD = $iLunYmd[2]; $Yundal = $iLunYmd[3]; if ($aMoon[$lunmemMM][$lunmemDD][0] != null ) { // 음력(평달) 기념일에 해당되는 양력 날자에.. if ($iLunMM == $lunmemMM and $iLunDD == $lunmemDD and $Yundal == null ) { $aHoli[$k][$d] = $aHoli[$k][$d].$aMoon[$i][$j][0]; } } if ($aMoon[$lunmemMM][$lunmemDD][1] != null ) { // 음력(윤) 기념일에 해당되는 양력 날자에.. if ($iLunMM == $lunmemMM and $iLunDD == $lunmemDD and $Yundal != null ) { $aHoli[$k][$d] = $aHoli[$k][$d].$aMoon[$i][$j][1]; } } } // end for } // end for } // end if } // end for } // end for //양력기념일 (기념일,국경일,법정기념일 - 휴일아닌경우) // $aHoli[5][29] = $aHoli[5][29]." 큰딸생일"; // $aHoli[6][9] = $aHoli[6][9]." 작은딸생일"; $aHoli[3][3] = $aHoli[3][3]." 납세자의날"; //$aHoli[3][xx] = " 상공의날"; //3월셋째 수요일 //$aHoli[4][xx] = " 향토예비군의날"; //4월첫째 금요일 $aHoli[4][5] = $aHoli[4][5]." 식목일"; $aHoli[4][7] = $aHoli[4][7]." 보건의날"; $aHoli[4][13] = $aHoli[4][13]." 임시정부수립"; $aHoli[4][19] = $aHoli[4][19]." 4.19기념일"; $aHoli[4][20] = $aHoli[4][20]." 장애인의날"; $aHoli[4][21] = $aHoli[4][21]." 과학의날"; $aHoli[4][22] = $aHoli[4][22]." 정보통신의날"; $aHoli[4][25] = $aHoli[4][25]." 법의날"; $aHoli[4][28] = $aHoli[4][28]." 충무공탄신일"; $aHoli[5][1] = $aHoli[5][1]." 근로자의날"; // $aHoli[5][5] = $aHoli[5][5]." 어린이날"; $aHoli[5][8] = $aHoli[5][8]." 어버이날"; $aHoli[5][11] = $aHoli[5][11]." 입양의날"; //개별법 $aHoli[5][15] = $aHoli[5][15]." 스승의날"; $aHoli[5][15] = $aHoli[5][15]." 가정의날"; //개별법 $aHoli[5][18] = $aHoli[5][18]." 5.18기념일"; $aHoli[5][19] = $aHoli[5][19]." 발명의날"; //개별법 $aHoli[5][20] = $aHoli[5][20]." 세계인의날"; //개별법 $aHoli[5][21] = $aHoli[5][21]." 부부의날"; $aHoli[5][25] = $aHoli[5][25]." 방재의날"; //개별법 //$aHoli[5][xx] = " 성년의날"; //5월셋째 월요일 $aHoli[5][31] = $aHoli[5][31]." 바다의날"; $aHoli[6][5] = $aHoli[6][5]." 환경의날"; // $aHoli[6][6] = $aHoli[6][6]." 현충일"; $aHoli[6][10] = $aHoli[6][10]." 6.10기념일"; $aHoli[6][25] = $aHoli[6][25]." 6.25사변일"; $aHoli[7][17] = $aHoli[7][17]." 제헌절"; //국경일 $aHoli[9][1] = $aHoli[9][1]." 통계의날"; //개별법 $aHoli[9][4] = $aHoli[9][4]." 태권도의날"; //개별법 $aHoli[9][7] = $aHoli[9][7]." 사회복지의날"; //개별법 $aHoli[9][18] = $aHoli[9][18]." 철도의날"; $aHoli[10][1] = $aHoli[10][1]." 국군의날"; $aHoli[10][2] = $aHoli[10][2]." 노인의날"; $aHoli[10][5] = $aHoli[10][5]." 세계한인의날"; $aHoli[10][8] = $aHoli[10][8]." 재향군인의날"; $aHoli[10][9] = $aHoli[10][9]." 한글날"; //국경일 $aHoli[10][10] = $aHoli[10][10]." 임산부의날"; //개별법 $aHoli[10][15] = $aHoli[10][15]." 체육의날"; //$aHoli[10][xx] = " 문화의날"; //10월셋째 토요일 $aHoli[10][21] = $aHoli[10][21]." 경찰의날"; $aHoli[10][24] = $aHoli[10][24]." 국제연합일"; $aHoli[10][28] = $aHoli[10][28]." 교정의날"; //$aHoli[10][xx] = " 저축의날"; //10월마지막화요일 $aHoli[11][3] = $aHoli[11][3]." 학생독립운동기념일"; $aHoli[11][9] = $aHoli[11][9]." 소방의날"; //개별법 $aHoli[11][11] = $aHoli[11][11]." 농업인의날"; $aHoli[11][17] = $aHoli[11][17]." 순국선열의날"; $aHoli[11][30] = $aHoli[11][30]." 무역의날"; $aHoli[12][3] = $aHoli[12][3]." 소비자의날"; $aHoli[12][5] = $aHoli[12][5]." 자원봉사자의날"; //개별법 // 몇월 몇번째 무슨요일 형식 기념일 설정 (예: 상공의날- 3월 셋째 수요일은 ($pYear, 월=3, 일=3, 수=3) 형식으로) $temp02 = explode("-",fn_nsweekday($pYear, 3, 3, 3)); $aHoli[$temp02[1]][$temp02[2]] = $aHoli[$temp02[1]][$temp02[2]]." 상공의날"; $temp02 = explode("-",fn_nsweekday($pYear, 4, 1, 5)); $aHoli[$temp02[1]][$temp02[2]] = $aHoli[$temp02[1]][$temp02[2]]." 향군의날"; $temp02 = explode("-",fn_nsweekday($pYear, 5, 3, 1)); $aHoli[$temp02[1]][$temp02[2]] = $aHoli[$temp02[1]][$temp02[2]]." 성년의날"; $temp02 = explode("-",fn_nsweekday($pYear, 10, 3, 6)); $aHoli[$temp02[1]][$temp02[2]] = $aHoli[$temp02[1]][$temp02[2]]." 문화의날"; // 몇월, 끝에서 몇번째 주, 무슨요일 형식 기념일 설정 (예: 저축의날- 10월마지막화요일) //상공의날 $temp02 = explode("-",fn_nslastweekday($pYear, 10, 1, 2)); $aHoli[$temp02[1]][$temp02[2]] = $aHoli[$temp02[1]][$temp02[2]]." 저축의날"; /*** // 몇월, 몇번째 주, 무슨요일 형식 기념일 설정 (예: 10월 4번째주 금요일) -현재 해당 기념일 없음. //테스트용 (예: 10월 4쨰주 금요일) $temp02 = explode("-",fn_nsweeknsweekday($pYear, 10, 4, 5)); $aHoli[$temp02[1]][$temp02[2]] = $aHoli[$temp02[1]][$temp02[2]]." 현재없음-테스트"; ***/ /*** // 매월, 몇번째 주, 무슨요일 형식 기념일 설정 (예: 4번째주 금요일) -현재 해당 기념일 없음. for ($k=1; $k < 13; $k++ ) { $temp02 = explode("-",fn_nsweeknsweekday($pYear, $k, 4, 5)); $aHoli[$temp02[1]][$temp02[2]] = $aHoli[$temp02[1]][$temp02[2]]." 월말결산"; } ***/ /*** // 매월, 몇번째 무슨요일 형식 기념일 설정 (예-옵션만기일: 매월 2번째 목요일) for ($k=1; $k < 13; $k++ ) { $temp02 = explode("-",fn_nsweekday($pYear, $k, 2, 4)); $aHoli[$temp02[1]][$temp02[2]] = $aHoli[$temp02[1]][$temp02[2]]." 옵션만기일"; } ***/ /*** // 몇월, 끝에서 몇번째 무슨요일 형식 기념일 설정 (예: Victoria Day=끝에서 2번째 월요일) $temp02 = explode("-",fn_nslastweekday($pYear, 5, 2, 1)); $aHoli[$temp02[1]][$temp02[2]] = $aHoli[$temp02[1]][$temp02[2]]." Victoria Day"; ***/ /*** //(부활절) $temp01 = explode("-",fn_easterday($pYear)); $iYmd =date("Y-n-j", mktime(0, 0, 0,$temp01[1], $temp01[2], $temp01[0])); $iYmdpre =date("Y-n-j", mktime(0, 0, 0,$temp01[1], $temp01[2]-2, $temp01[0])); $iYmdnext =date("Y-n-j", mktime(0, 0, 0,$temp01[1], $temp01[2]+1, $temp01[0])); // $temp02 = explode("-",$iYmdpre); // $aHoli[$temp02[1]][$temp02[2]] = $aHoli[$temp02[1]][$temp02[2]]."Good Friday"; $temp02 = explode("-",$iYmd); $aHoli[$temp02[1]][$temp02[2]] = $aHoli[$temp02[1]][$temp02[2]]."부활절"; // $temp02 = explode("-",$iYmdnext); // $aHoli[$temp02[1]][$temp02[2]] = $aHoli[$temp02[1]][$temp02[2]]."Easter Monday"; ***/ return $aHoli; } //------------------------------------------------------------------------ /** * @function: fn_repeat_schedule($pYear, $pMonth, $plan_start, $plan_end, $plan_repeat_cycle, $plan_repeat_unit) * @return : array * @brief: 반복일정이 적용되는 양력일자 어레이 리턴 **/ Function fn_repeat_schedule($pYear, $pMonth, $plan_start, $plan_end, $plan_repeat_cycle, $plan_repeat_unit) { /****************************************************** * 반복일정이 적용되는 일자에 "*" 삽입 * 반복일정은 일정시작일을 기준으로 반복되며, 모든 반복일정은 일정 자체의 기간은 1일 간으로한다. * 그렇지 않을경우 일정자체의 기간을 지정할 2개의 추가 확장변수가 필요하게 되어 실익이 없다. *******************************************************/ $aHoli = null; if ($plan_start == null ) { return $aHoli; } $startYY = substr($plan_start,0,4); $startMM = ltrim(substr($plan_start,4,2), "0" ); // 앞의 "0" 제거 $startDD = ltrim(substr($plan_start,6,2), "0" ); // 앞의 "0" 제거 $plnstartYY = $startYY; $plnstartMM = $startMM; $plnstartDD = $startDD; $endYY = substr($plan_end,0,4); $endMM = ltrim(substr($plan_end,4,2), "0" ); // 일자 앞의 "0" 제거 $endDD = ltrim(substr($plan_end,6,2), "0" ); // 일자 앞의 "0" 제거 $plnendYY = $endYY; $plnendMM = $endMM; $plnendDD = $endDD; $plan_startdate = mktime(0, 0, 0, $startMM, $startDD, $startYY); // 일정시작 일자 타임스탬프 $plan_enddate = mktime(0, 0, 0, $endMM, $endDD, $endYY); // 일정종료 일자 타임스탬프 $k = 12; // 1년간 반복일정 처리 (월 반복일정) if ($plnstartYY == $pYear and $plnstartMM == $pMonth) { // 당월 시작 이면서 당월 이후 종료 if ($plnendYY > $pYear or $plnendYY == $pYear and $plnendMM > $pMonth) { $plnendYY = $pYear; $plnendMM = $pMonth; $plnendDD = 31; } } elseif ($plnstartYY < $pYear or $plnstartYY == $pYear and $plnstartMM < $pMonth) { // 당월 이전 시작 이면서 당월 종료 if ($plnendYY == $pYear and $plnendMM == $pMonth) { $plnstartYY = $pYear; $plnstartMM = $pMonth; $plnstartDD = 1; } if ($plnendYY > $pYear or $plnendYY == $pYear and $plnendMM > $pMonth) { // 당월 이전시작 이면서 당월 이후 종료 $plnstartYY = $pYear; $plnstartMM = $pMonth; $plnstartDD = 1; $plnendYY = $pYear; $plnendMM = $pMonth; $plnendDD = 31; } } // plan_repeat_cycle 또는 plan_repeat_unit 값이 null 일때******************** if ($plan_repeat_unit == null or $plan_repeat_cycle == null ) { if ( $plnstartYY == $pYear and $plnstartMM == $pMonth) { For ($i = $plnstartMM; $i <= $plnendMM; $i++) { For ($j = $plnstartDD; $j <= $plnendDD; $j++ ) { $aHoli[$i][$j] = "*"; } } } } // unit 값이 1.일(간격) : 몇일 간결으로 반복*********************************** elseif (substr($plan_repeat_unit,0,1) == "1" and $plan_repeat_cycle != null ) { $k = 365/$plan_repeat_cycle +1; // 1년간 반복일정 처리 For ($i = 0; $i <= $k; $i++ ) { $wrkday= $startDD + ($plan_repeat_cycle * $i); $wrkYY = date("Y", mktime(0, 0, 0, $startMM, $wrkday, $startYY)); // 반복될 일자-년 $wrkMM = date("n", mktime(0, 0, 0, $startMM, $wrkday, $startYY)); // 반복될 일자-월 $wrkDD = date("j", mktime(0, 0, 0, $startMM, $wrkday, $startYY)); // 반복될 일자-일 $work_date = mktime(0, 0, 0, $wrkMM, $wrkDD, $wrkYY); // 반복 일자 타임스탬프 if( $work_date >= $plan_startdate and $work_date <= $plan_enddate ) { $aHoli[$wrkMM][$wrkDD] = "*"; } } } // 2.개월(날자): 반복월 같은 날자********************************************** elseif (substr($plan_repeat_unit,0,1) == "2" and $plan_repeat_cycle != null ) { For ($i = 0; $i <= $k; $i++ ) { $wrkmonth= $startMM + ($plan_repeat_cycle * $i); $wrkYY = date("Y", mktime(0, 0, 0, $wrkmonth, $startDD, $startYY)); // 반복될 일자-년 $wrkMM = date("n", mktime(0, 0, 0, $wrkmonth, $startDD, $startYY)); // 반복될 일자-월 $wrkDD = date("j", mktime(0, 0, 0, $wrkmonth, $startDD, $startYY)); // 반복될 일자-일 $work_date = mktime(0, 0, 0, $wrkMM, $wrkDD, $wrkYY); // 반복 일자 타임스탬프 if( $work_date >= $plan_startdate and $work_date <= $plan_enddate ) { $aHoli[$wrkMM][$wrkDD] = "*"; } } } // 3.개월(요일): 반복월 같은번째 요일******************************************* elseif (substr($plan_repeat_unit,0,1) == "3" and $plan_repeat_cycle != null ) { $pYoil = date("w", mktime(0, 0, 0,$startMM, $startDD, $startYY)); //해당일의 요일번호(일=0, 토=6) $yoilcount = fn_weekdaycountofmonth($startYY,$startMM,$startDD); // n번째 요일 숫자 For ($i = 0; $i <= $k; $i++ ) { $wrkmonth= $startMM + ($plan_repeat_cycle * $i); $wrkYY = date("Y", mktime(0, 0, 0, $wrkmonth, $startDD, $startYY)); // 반복될 일자-년 $wrkMM = date("n", mktime(0, 0, 0, $wrkmonth, $startDD, $startYY)); // 반복될 일자-월 $wrkDD = date("j", mktime(0, 0, 0, $wrkmonth, $startDD, $startYY)); // 반복될 일자-일 $temp01 = explode("-",fn_nsweekday($wrkYY, $wrkMM, $yoilcount, $pYoil)); // 해당n번째요일에 대응되는 일자 얻기 $work_date = mktime(0, 0, 0, $temp01[1], $temp01[2], $temp01[0]); // 반복 일자 타임스탬프 if( $work_date >= $plan_startdate and $work_date <= $plan_enddate ) { $aHoli[$temp01[1]][$temp01[2]] = "*"; } } } // 4.개월(주): 반복월 같은번째 주 같은요일************************************** elseif (substr($plan_repeat_unit,0,1) == "4" and $plan_repeat_cycle != null ) { $pYoil = date("w", mktime(0, 0, 0,$startMM, $startDD, $startYY)); //해당일의 요일번호(일=0, 토=6) $weekcount = fn_weekcountofmonth($startYY,$startMM,$startDD); //n번째 주 숫자 For ($i = 0; $i <= $k; $i++ ) { $wrkmonth= $startMM + ($plan_repeat_cycle * $i); $wrkYY = date("Y", mktime(0, 0, 0, $wrkmonth, $startDD, $startYY)); // 반복될 일자-년 $wrkMM = date("n", mktime(0, 0, 0, $wrkmonth, $startDD, $startYY)); // 반복될 일자-월 $wrkDD = date("j", mktime(0, 0, 0, $wrkmonth, $startDD, $startYY)); // 반복될 일자-일 $temp01 = explode("-",fn_nsweeknsweekday($wrkYY, $wrkMM, $weekcount, $pYoil)); // 해당주/요일에 대응되는 일자 얻기 $work_date = mktime(0, 0, 0, $temp01[1], $temp01[2], $temp01[0]); // 반복 일자 타임스탬프 if( $work_date >= $plan_startdate and $work_date <= $plan_enddate ) { $aHoli[$temp01[1]][$temp01[2]] = "*"; } } } // 5.개월(말일): 반복월 말일**************************************************** elseif (substr($plan_repeat_unit,0,1) == "5" and $plan_repeat_cycle != null ) { For ($i = 0; $i <= $k; $i++ ) { $wrkmonth= $startMM + ($plan_repeat_cycle * $i); $wrkYY = date("Y", mktime(0, 0, 0, $wrkmonth, $startDD, $startYY)); // 반복될 일자-년 $wrkMM = date("n", mktime(0, 0, 0, $wrkmonth, $startDD, $startYY)); // 반복될 일자-월 $wrkDD = date("j", mktime(0, 0, 0, $wrkmonth, $startDD, $startYY)); // 반복될 일자-일 $wrklastday= date("t", mktime(0, 0, 0, $wrkmonth, 1, $startYY)); // 반복될 마지막 날자 $work_date = mktime(0, 0, 0, $wrkMM, $wrklastday, $wrkYY); // 반복 일자 타임스탬프 if( $work_date >= $plan_startdate and $work_date <= $plan_enddate ) { $aHoli[$wrkMM][$wrklastday] = "*"; } } } return $aHoli; } ?> 3 ) { $pOption=1; // 간지옵션 } $pYear =date("Y", mktime(0, 0, 0, $pMonth, 1, $pYear)); $pMonth =date("n", mktime(0, 0, 0, $pMonth, 1, $pYear)); $pMon =date("F", mktime(0, 0, 0, $pMonth, 1, $pYear)); $todayYY = date("Y"); // 당일년도 $todayMM = date("n"); // 당일월 $todayDD = date("j"); // 당일일 ?> pYear = $pYear; $tempmonth = substr("0".$pMonth, -2); //월 을 "7" 에서 "07"로 $__Context->tempMonth = $tempmonth; ?> {@ $planner_document_list = $notice_list + $document_list} {@ $planner_document_list = $document_list} {@ $category_color = $category_list[$document->get('category_srl')]->color} {@ $category_title = $category_list[$document->get('category_srl')]->title} category_title; $category_color = $__Context->category_color; ?> {@ $plan_start = $document->getExtraValue($val->idx)} {@ $startYY = substr($plan_start,0,4)} {@ $startMM = substr($plan_start,4,2)} {@ $startDD = substr($plan_start,6,2)} {@ $plan_title = $document->getTitle($module_info->subject_cut_size)} {@ $plan_detail = $document->getSummary($module_info->content_cut_size)} {@ $plan_url = getUrl('document_srl',$document->document_srl, 'listStyle', $listStyle, 'cpage','')} {@ $plan_docurl = $document->document_srl} plan_title; $plan_detail = $__Context->plan_detail; $plan_url = $__Context->plan_url; $plan_start = $__Context->plan_start; // 일정시작 $plnstartYY = $__Context->startYY; $plnstartMM = $__Context->startMM; $plnstartDD = $__Context->startDD; $plnstartMM = ltrim( $plnstartMM, "0" ); // 앞의 "0" 제거 $plnstartDD = ltrim( $plnstartDD, "0" ); // 앞의 "0" 제거 ?> {@ $plan_end = $document->getExtraValue($val->idx)} {@ $plan_end = $plan_start} {@ $endYY = substr($plan_end,0,4)} {@ $endMM = substr($plan_end,4,2)} {@ $endDD = substr($plan_end,6,2)} {@ $plan_title = $document->getTitle($module_info->subject_cut_size)} {@ $plan_detail = $document->getSummary($module_info->content_cut_size)} {@ $plan_url = getUrl('document_srl',$document->document_srl, 'listStyle', $listStyle, 'cpage','')} {@ $plan_docurl = $document->document_srl} plan_title; $plan_detail = $__Context->plan_detail; $plan_url = $__Context->plan_url; $plan_end = $__Context->plan_end; // 일정종료 $plnendYY = $__Context->endYY; $plnendMM = $__Context->endMM; $plnendDD = $__Context->endDD; $plnendMM = ltrim( $plnendMM, "0" ); // 일자 앞의 "0" 제거 $plnendDD = ltrim( $plnendDD, "0" ); // 일자 앞의 "0" 제거 ?> {@ $plan_bgcolor = $document->getExtraValueHTML($val->idx)} plan_bgcolor; // 배경색상 ?> {@ $plan_flagicon = $document->getExtraValueHTML($val->idx)} plan_flagicon; // 일정확인 ?> {@ $plan_repeat_cycle = $document->getExtraValueHTML($val->idx)} plan_repeat_cycle; // 반복일정 cycle ?> {@ $plan_repeat_unit = $document->getExtraValueHTML($val->idx)} plan_repeat_unit; // 반복일정 unit ?> $pYear or $plnendYY == $pYear and $plnendMM > $pMonth) { $plnendYY = $pYear; $plnendMM = $pMonth; $plnendDD = 31; } } elseif ($plnstartYY < $pYear or $plnstartYY == $pYear and $plnstartMM < $pMonth) { // 당월 이전 시작 이면서 당월 종료 if ($plnendYY == $pYear and $plnendMM == $pMonth) { $plnstartYY = $pYear; $plnstartMM = $pMonth; $plnstartDD = 1; } if ($plnendYY > $pYear or $plnendYY == $pYear and $plnendMM > $pMonth) { // 당월 이전시작 이면서 당월 이후 종료 $plnstartYY = $pYear; $plnstartMM = $pMonth; $plnstartDD = 1; $plnendYY = $pYear; $plnendMM = $pMonth; $plnendDD = 31; } } $plan_detail = str_replace("'", "`", $plan_detail); // '을 `로 대체 textbox보이기위해 $plan_detail = str_replace("\"", """, $plan_detail); // "를 "로 대체 textbox보이기위해 $plan_detail = str_replace(chr(012), "", $plan_detail); // LF를 제거 textbox보이기위해 $plan_detail = str_replace(chr(015), "
", $plan_detail); // CR을 제거 textbox보이기위해 -줄바꿈 // $plan_detail = strip_tags($plan_detail); // HTML tag 제거 - 줄바꿈 사용않음 if( $plnstartYY == $pYear and $plnstartMM == $pMonth) { // 일정관련자료 어레이에 출력 $arr_repeat = fn_repeat_schedule($pYear, $pMonth, $plan_start, $plan_end, $plan_repeat_cycle, $plan_repeat_unit); For ($i = $plnstartMM; $i <= $plnendMM; $i++) { For ($j = $plnstartDD; $j <= $plnendDD; $j++ ) { if ( $arr_repeat[$i][$j] == "*") { $arr_plan[$i][$j] = $arr_plan[$i][$j].$plan_title."~:~".$plan_url."~:~".$plan_detail."~:~".$plan_bgcolor."~:~".$plan_flagicon."~:~".$category_title."~:~".$category_color."||"; // 어레이에 추가 1차분리자= "||", 2차 분리자 "~:~" } } } } } ?>
  
전년 후년
전월 <?php echo $i?>월 익월
"); for ($j=0; $j<7; $j++) { ?> "); } echo (""); } ?>
Sun Mon Tue Wed Thu Fri Sat
bgcolor={$today_bgcolor} bgcolor={$day_bgcolor} height="80" width="14%" onMouseOut="this.style.backgroundColor=''" onMouseOver="this.style.backgroundColor='#DDFFFA'" style="word-break:break-all;padding:0px;"> "; if ($pYear == $todayYY and $pMonth == $todayMM and $Calmain[$i][$j] == $todayDD ) { $outtext = $outtext.""; echo ($outtext); // 두째줄 --일정/플랜--- if ($tmparr6[0] != null) { $count = count($tmparr6); for ($k = 0; $k < $count; $k++) { $tmparr7=explode("~:~",$tmparr6[$k]); $outtext = ""; echo ($outtext); } } // 셋째줄 --공휴일, 기념일--- if ($tmparr4[0] != null or $tmparr5[0] != null) { $outtext = ""; echo ($outtext); } } echo ("
"; // 당일 } else { $outtext = $outtext.""; // 평일 } if ($j==0 or $tmparr4[0] != null) { $tmpfld = "".$Calmain[$i][$j].""; // 일요일 및 휴일 } elseif ($j==6) { $tmpfld = "".$Calmain[$i][$j].""; // 토요일 } else { $tmpfld = "".$Calmain[$i][$j].""; // 평일 } $templink = getUrl('act','dispBoardWrite','document_srl','') ; // 일자 클릭시 쓰기로 이동 $templink = $templink."&extra_vars1=$pYear-$tempmonth-".substr("0".$tempday,-2); // 확장변수에 값 넣는것은 잘 안됨 $templink = ""; $outtext = $outtext." ".$templink.$tmpfld.""; // 일자 ?> ".$tmpfld1.""; // 음력 } $outtext = $outtext." ".$tmparr2[4].""; // 절기 $outtext = $outtext."".$tmparr4[0].""; // 공휴일 $outtext = $outtext."
"; if ($tmparr7[0] != null and $tmparr7[4] != null) { $outtext = $outtext.""; } $outtext = $outtext.""."".$tmparr7[0].""; $outtext = $outtext."
"; // $outtext = $outtext."".$tmparr4[0].""; // 공휴일 $outtext = $outtext." ".$tmparr5[0].""; // 기념일 $outtext = $outtext."