<?php /*~ calendar.inc.php
.---------------------------------------------------------------------------.
|  Software: Month Calendar Dataset Computing Program                       |
|   Version: 0.1                                                            |
|   Contact: via http://www.uniwits.com/contact                             |
|      Info: http://www.uniwits.com/                                        |
|   Support: http://www.uniwits.com/support                                 |
| ------------------------------------------------------------------------- |
|     Admin: Yuxiang Mao (project admininistrator)                          |
|   Authors: Yuxiang Mao (Uniwits) contact@uniwits.com                      |
|   Founder: Yuxiang Mao                                                    |
| Copyright (c) 2010-2012, Yuxiang Mao. All Rights Reserved.                |
| ------------------------------------------------------------------------- |
|   License: Distributed under Uniwits Shareware License (USL)              |
|            http://www.uniwits.com/licenses/shareware/                     |
| This program is distributed as a part of software provided by Uniwits     |
| System WITHOUT ANY WARRANTY; without even the implied warranty of         |
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.                      |
| ------------------------------------------------------------------------- |
*/ function month_calendar($dateinmonth,$timezone_bias_seconds) { $summary=array( 'dataset'=>array(), 'day2weekday'=>null, 'cur_month_since'=>null, 'cur_month_expire'=>null, 'sec_month_since'=>null, 'sec_month_expire'=>null, 'month_days'=>0 ); $month=&$summary['dataset']; $day2weekday=&$summary['day2weekday']; $cur_month_since=&$summary['month_since']; $cur_month_expire=&$summary['month_expire']; $sec_month_since=&$summary['sec_month_since']; $sec_month_expire=&$summary['sec_month_expire']; $month_days=&$summary['month_days']; $cdt_parts=split_datetime($dateinmonth,$timezone_bias_seconds); $cur_month_since=$cdt_parts['year'].'-'.$cdt_parts['month'].'-01 00:00:00'; if ($cdt_parts['month']>=12) $cur_month_expire=($cdt_parts['year']+1).'-01-01 00:00:00'; else $cur_month_expire=$cdt_parts['year'].'-'.($cdt_parts['month']+1).'-01 00:00:00'; $sec_month_since=datetime_to_seconds($cur_month_since); $sec_month_expire=datetime_to_seconds($cur_month_expire); $month_expire_second=datetime_to_seconds($cur_month_expire); $cur_month_end=seconds_to_datetime($month_expire_second-1); $cme_parts=split_datetime($cur_month_end); $month_days=0+$cme_parts['day']; $month=array( 'year'=>$cdt_parts['year'], 'month'=>$cdt_parts['month'], 'WEEK'=>array( array('DAY'=>array_pad(array(),7,array())) ) ); $weekidx=0; $weekdayi=seconds_to_weekday($sec_month_since); for ($dayi=1;$dayi<=$month_days;$dayi++) { $day2weekday[$dayi]=&$month['WEEK'][$weekidx]['DAY'][$weekdayi]; $day2weekday[$dayi]['fulldate']=$cdt_parts['year'].'-'.$cdt_parts['month'].'-'.sprintf('%02d',$dayi); $day2weekday[$dayi]['yearmonth']=$cdt_parts['year'].'-'.$cdt_parts['month']; $day2weekday[$dayi]['date']=$dayi; $day2weekday[$dayi]['weekday']=$weekdayi; $weekdayi++; if ($weekdayi>6 && $dayi<$month_days) { $weekdayi=0; $weekidx++; array_push($month['WEEK'], array( 'DAY'=>array_pad(array(),7,array()) ) ); } } $weekcount=$weekidx; for ($di=0;$di<7;$di++) { if (!$month['WEEK'][0]['DAY'][$di]) { $day=&$month['WEEK'][0]['DAY'][$di]; $day['fulldate']=datetime_datepart($month['WEEK'][1]['DAY'][$di]['fulldate'],-7*24*3600); $dparts=split_datetime($day['fulldate']); $day['yearmonth']=$dparts['year'].'-'.$dparts['month']; $day['date']=$dparts['day']; $day['weekday']=$month['WEEK'][1]['DAY'][$di]['weekday']; unset($day); } if (!$month['WEEK'][$weekcount]['DAY'][$di]) { $day=&$month['WEEK'][$weekcount]['DAY'][$di]; $day['fulldate']=datetime_datepart($month['WEEK'][$weekcount-1]['DAY'][$di]['fulldate'],+7*24*3600); $dparts=split_datetime($day['fulldate']); $day['yearmonth']=$dparts['year'].'-'.$dparts['month']; $day['date']=0+$dparts['day']; $day['weekday']=$month['WEEK'][$weekcount-1]['DAY'][$di]['weekday']; unset($day); } } return $summary; } ?>