cvs: php4 /pear/Date Calc.php
| From: | Monte Ohrt | Date: | Wed, 15 Nov 2000 15:25:29 +0000 |
| Subject: | cvs: php4 /pear/Date Calc.php | ||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-2615@lists.php.net to get a copy of this message | ||
mohrt Wed Nov 15 07:25:29 2000 EDT
Modified files:
/php4/pear/Date Calc.php
Log:
rearranged arguments in functions to day,month,year for better usability.
also other small fixes and updates, see http://www.phpinsider.com
Index: php4/pear/Date/Calc.php diff -u php4/pear/Date/Calc.php:1.4 php4/pear/Date/Calc.php:1.5 --- php4/pear/Date/Calc.php:1.4 Tue Oct 17 07:05:12 2000 +++ php4/pear/Date/Calc.php Wed Nov 15 07:25:29 2000 @@ -19,7 +19,7 @@ * * @access public * - * @version 1.0.4 + * @version 1.1 * @author Monte Ohrt <monte@ispi.net> */ @@ -30,7 +30,7 @@ * 0=Sunday, 1=Monday * * @access public - * @version 1.0 + * @version 1.1 * @author Monte Ohrt <monte@ispi.net> * * @var int [$begin_weekday] @@ -46,8 +46,6 @@ * @param string the strftime() format to return the date * * @access public - * @version 1.0 - * @author Monte Ohrt <monte@ispi.net> * * @return string the current date in specified format */ @@ -66,13 +64,11 @@ * @param string day in format DD * * @access public - * @version 1.0 - * @author Monte Ohrt <monte@ispi.net> * * @return boolean true/false */ - function isValidDate($year, $month, $day) + function isValidDate($day, $month, $year) { if(empty($year) || empty($month) || empty($day)) @@ -90,7 +86,7 @@ return false; if($month < 1 || $month > 12) return false; - if($day < 1 || $day > 31 || $day > $this->daysInMonth($year,$month)) + if($day < 1 || $day > 31 || $day > $this->daysInMonth($month,$year)) return false; return true; @@ -121,13 +117,11 @@ * @param string day in format DD * * @access public - * @version 1.0 - * @author Monte Ohrt <monte@ispi.net> * * @return boolean true/false */ - function isFutureDate($year,$month,$day) + function isFutureDate($day,$month,$year) { $this_year = $this->dateNow("%Y"); $this_month = $this->dateNow("%m"); @@ -155,13 +149,11 @@ * @param string day in format DD * * @access public - * @version 1.0 - * @author Monte Ohrt <monte@ispi.net> * * @return boolean true/false */ - function isPastDate($year,$month,$day) + function isPastDate($day,$month,$year) { $this_year = $this->dateNow("%Y"); $this_month = $this->dateNow("%m"); @@ -189,21 +181,19 @@ * @param string day in format DD, default is current local day * * @access public - * @version 1.0 - * @author Monte Ohrt <monte@ispi.net> * * @return int $weekday_number */ - function dayOfWeek($year="",$month="",$day="") + function dayOfWeek($day="",$month="",$year="") { - if(empty($year) || empty($month) || empty($day)) - { + if(empty($year)) $year = $this->dateNow("%Y"); + if(empty($month)) $month = $this->dateNow("%m"); + if(empty($day)) $day = $this->dateNow("%d"); - } if($month > 2) $month -= 2; @@ -233,27 +223,25 @@ * @param string day in format DD * * @access public - * @version 1.0 - * @author Monte Ohrt <monte@ispi.net> * * @return integer $week_number */ - function weekOfYear($year,$month,$day) + function weekOfYear($day,$month,$year) { - if(empty($year) || empty($month) || empty($day)) - { + if(empty($year)) $year = $this->dateNow("%Y"); + if(empty($month)) $month = $this->dateNow("%m"); + if(empty($day)) $day = $this->dateNow("%d"); - } $week_year = $year - 1501; $week_day = $week_year * 365 + floor($week_year / 4) - 29872 + 1 - floor($week_year / 100) + floor(($week_year - 300) / 400); $week_number = - floor(($this->julianDate($year,$month,$day) + floor(($week_day + 4) % 7)) / 7); + floor(($this->julianDate($day,$month,$year) + floor(($week_day + 4) % 7)) / 7); return $week_number; @@ -267,20 +255,18 @@ * @param string day in format DD, default is current local day * * @access public - * @version 1.0 - * @author Monte Ohrt <monte@ispi.net> * * @return int $julian */ - function julianDate($year="",$month="",$day="") + function julianDate($day="",$month="",$year="") { - if(empty($year) || empty($month) || empty($day)) - { + if(empty($year)) $year = $this->dateNow("%Y"); + if(empty($month)) $month = $this->dateNow("%m"); + if(empty($day)) $day = $this->dateNow("%d"); - } $days = array(0,31,59,90,120,151,181,212,243,273,304,334); @@ -301,20 +287,18 @@ * @param string day in format DD, default current local day * * @access public - * @version 1.0 - * @author Monte Ohrt <monte@ispi.net> * * @return int $year_quarter */ - function quarterOfYear($year="",$month="",$day="") + function quarterOfYear($day="",$month="",$year="") { - if(empty($year) || empty($month) || empty($day)) - { + if(empty($year)) $year = $this->dateNow("%Y"); + if(empty($month)) $month = $this->dateNow("%m"); + if(empty($day)) $day = $this->dateNow("%d"); - } $year_quarter = (intval(($month - 1) / 3 + 1)); @@ -331,20 +315,18 @@ * @param string format for returned date * * @access public - * @version 1.0 - * @author Monte Ohrt <monte@ispi.net> * * @return string date in given format - */ + */ - function beginOfNextMonth($year="",$month="",$day="",$format="%Y%m%d") + function beginOfNextMonth($day="",$month="",$year="",$format="%Y%m%d") { - if(empty($year) || empty($month) || empty($day)) - { + if(empty($year)) $year = $this->dateNow("%Y"); + if(empty($month)) $month = $this->dateNow("%m"); + if(empty($day)) $day = $this->dateNow("%d"); - } if($month < 12) { @@ -358,7 +340,7 @@ $day=1; } - return $this->dateFormat($year,$month,$day,$format); + return $this->dateFormat($day,$month,$year,$format); } // end func beginOfNextMonth @@ -371,22 +353,20 @@ * @param string format for returned date * * @access public - * @version 1.0 - * @author Monte Ohrt <monte@ispi.net> * * @return string date in given format */ - function endOfNextMonth($year="",$month="",$day="",$format="%Y%m%d") + function endOfNextMonth($day="",$month="",$year="",$format="%Y%m%d") { - if(empty($year) || empty($month) || empty($day)) - { + if(empty($year)) $year = $this->dateNow("%Y"); + if(empty($month)) $month = $this->dateNow("%m"); + if(empty($day)) $day = $this->dateNow("%d"); - } - $day = $this->daysInMonth($year,$month); + $day = $this->daysInMonth($month,$year); if($month < 12) { @@ -398,7 +378,7 @@ $month=1; } - return $this->dateFormat($year,$month,$day,$format); + return $this->dateFormat($day,$month,$year,$format); } // end func endOfNextMonth @@ -411,20 +391,18 @@ * @param string format for returned date * * @access public - * @version 1.0 - * @author Monte Ohrt <monte@ispi.net> * * @return string date in given format */ - function beginOfPrevMonth($year="",$month="",$day="",$format="%Y%m%d") + function beginOfPrevMonth($day="",$month="",$year="",$format="%Y%m%d") { - if(empty($year) || empty($month) || empty($day)) - { + if(empty($year)) $year = $this->dateNow("%Y"); + if(empty($month)) $month = $this->dateNow("%m"); + if(empty($day)) $day = $this->dateNow("%d"); - } if($month > 1) { @@ -438,7 +416,7 @@ $day=1; } - return $this->dateFormat($year,$month,$day,$format); + return $this->dateFormat($day,$month,$year,$format); } // end func beginOfPrevMonth @@ -451,22 +429,20 @@ * @param string format for returned date * * @access public - * @version 1.0b - * @author Monte Ohrt <monte@ispi.net> * * @return string date in given format */ - function endOfPrevMonth($year="",$month="",$day="",$format="%Y%m%d") + function endOfPrevMonth($day="",$month="",$year="",$format="%Y%m%d") { - if(empty($year) || empty($month) || empty($day)) - { + if(empty($year)) $year = $this->dateNow("%Y"); + if(empty($month)) $month = $this->dateNow("%m"); + if(empty($day)) $day = $this->dateNow("%d"); - } - $day = $this->daysInMonth($year,$month); + $day = $this->daysInMonth($month,$year); if($month > 1) { @@ -478,7 +454,7 @@ $month=12; } - return $this->dateFormat($year,$month,$day,$format); + return $this->dateFormat($day,$month,$year,$format); } // end func endOfPrevMonth @@ -492,26 +468,24 @@ * @param string format for returned date * * @access public - * @version 1.0 - * @author Monte Ohrt <monte@ispi.net> * * @return string date in given format */ - function nextWeekday($year="",$month="",$day="",$format="%Y%m%d") + function nextWeekday($day="",$month="",$year="",$format="%Y%m%d") { - if(empty($year) || empty($month) || empty($day)) - { + if(empty($year)) $year = $this->dateNow("%Y"); + if(empty($month)) $month = $this->dateNow("%m"); + if(empty($day)) $day = $this->dateNow("%d"); - } - $days = $this->dateToDays($year,$month,$day); + $days = $this->dateToDays($day,$month,$year); - if($this->dayOfWeek($year,$month,$day) == 5) + if($this->dayOfWeek($day,$month,$year) == 5) $days += 3; - elseif($this->dayOfWeek($year,$month,$day) == 6) + elseif($this->dayOfWeek($day,$month,$year) == 6) $days += 2; else $days += 1; @@ -530,26 +504,24 @@ * @param string format for returned date * * @access public - * @version 1.0 - * @author Monte Ohrt <monte@ispi.net> * * @return string date in given format */ - function prevWeekday($year="",$month="",$day="",$format="%Y%m%d") + function prevWeekday($day="",$month="",$year="",$format="%Y%m%d") { - if(empty($year) || empty($month) || empty($day)) - { + if(empty($year)) $year = $this->dateNow("%Y"); + if(empty($month)) $month = $this->dateNow("%m"); + if(empty($day)) $day = $this->dateNow("%d"); - } - $days = $this->dateToDays($year,$month,$day); + $days = $this->dateToDays($day,$month,$year); - if($this->dayOfWeek($year,$month,$day) == 1) + if($this->dayOfWeek($day,$month,$year) == 1) $days -= 3; - elseif($this->dayOfWeek($year,$month,$day) == 0) + elseif($this->dayOfWeek($day,$month,$year) == 0) $days -= 2; else $days -= 1; @@ -567,22 +539,20 @@ * @param string format for returned date * * @access public - * @version 1.0 - * @author Monte Ohrt <monte@ispi.net> * * @return string date in given format */ - function nextDay($year="",$month="",$day="",$format="%Y%m%d") + function nextDay($day="",$month="",$year="",$format="%Y%m%d") { - if(empty($year) || empty($month) || empty($day)) - { + if(empty($year)) $year = $this->dateNow("%Y"); + if(empty($month)) $month = $this->dateNow("%m"); + if(empty($day)) $day = $this->dateNow("%d"); - } - $days = $this->dateToDays($year,$month,$day); + $days = $this->dateToDays($day,$month,$year); return($this->daysToDate($days + 1,$format)); @@ -597,22 +567,20 @@ * @param string format for returned date * * @access public - * @version 1.0 - * @author Monte Ohrt <monte@ispi.net> * * @return string date in given format */ - function prevDay($year="",$month="",$day="",$format="%Y%m%d") + function prevDay($day="",$month="",$year="",$format="%Y%m%d") { - if(empty($year) || empty($month) || empty($day)) - { + if(empty($year)) $year = $this->dateNow("%Y"); + if(empty($month)) $month = $this->dateNow("%m"); + if(empty($day)) $day = $this->dateNow("%d"); - } - $days = $this->dateToDays($year,$month,$day); + $days = $this->dateToDays($day,$month,$year); return($this->daysToDate($days - 1,$format)); @@ -625,8 +593,6 @@ * @param string 2 digit year * * @access public - * @version 1.0 - * @author Monte Ohrt <monte@ispi.net> * * @return string 4 digit year */ @@ -653,22 +619,20 @@ * @param string day in format DD * * @access public - * @version 1.0 - * @author Monte Ohrt <monte@ispi.net> * * @return int absolute number of days between dates, * -1 if there is an error. */ - function dateDiff($year1,$month1,$day1,$year2,$month2,$day2) + function dateDiff($day1,$month1,$year1,$day2,$month2,$year2) { - if(!$this->isValidDate($year1,$month1,$day1)) + if(!$this->isValidDate($day1,$month1,$year1)) return -1; - if(!$this->isValidDate($year2,$month2,$day2)) + if(!$this->isValidDate($day2,$month2,$year2)) return -1; - return(abs(($this->dateToDays($year1,$month1,$day1)) - - ($this->dateToDays($year2,$month2,$day2)))); + return(abs(($this->dateToDays($day1,$month1,$year1)) + - ($this->dateToDays($day2,$month2,$year2)))); } // end func dateDiff @@ -678,18 +642,16 @@ * @param string month in format MM, default current local month * * @access public - * @version 1.0 - * @author Monte Ohrt <monte@ispi.net> * * @return int number of days */ - function daysInMonth($year="",$month="") + function daysInMonth($month="",$year="") { + if(empty($year)) + $year = $this->dateNow("%Y"); if(empty($month)) $month = $this->dateNow("%m"); - if(empty($year)) - $month = $this->dateNow("%Y"); if($month == 2) { @@ -704,29 +666,48 @@ return 31; } // end func daysInMonth - + /** + * Find the number of weeks in the given month. + * + * @param string month in format MM, default current local month + * @param string year in format YYCC, default current local year + * + * @access public + * + * @return int number of weeks + */ + + function weeksInMonth($month="",$year="") + { + if(empty($year)) + $year = $this->dateNow("%Y"); + if(empty($month)) + $month = $this->dateNow("%m"); + + return ceil(($this->daysInMonth($month,$year)+$this->firstOfMonthWeekday("01",$month,$year)-$this->begin_weekday)/7); + + } // end func weeksInMonth + + /** * Find the day of the week for the first of the month of given date. * * @param string year in format CCYY, default to current local year * @param string month in format MM, default to current local month * * @access public - * @version 1.0 - * @author Monte Ohrt <monte@ispi.net> * * @return int number of weekday for the first day, 0=Sunday */ - function firstOfMonthWeekday($year="",$month="") + function firstOfMonthWeekday($month="",$year="") { - if(empty($year) || empty($month)) - { + if(empty($year)) $year = $this->dateNow("%Y"); + if(empty($month)) $month = $this->dateNow("%m"); - } - return($this->dayOfWeek($year,$month,"01")); + return($this->dayOfWeek("01",$month,$year)); } // end func firstOfMonthWeekday @@ -738,21 +719,18 @@ * @param string format for returned date * * @access public - * @version 1.0 - * @author Monte Ohrt <monte@ispi.net> * * @return string date in given format */ - function beginOfMonth($year="",$month="",$format="%Y%m%d") + function beginOfMonth($month="",$year="",$format="%Y%m%d") { - if(empty($year) || empty($month)) - { + if(empty($year)) $year = $this->dateNow("%Y"); + if(empty($month)) $month = $this->dateNow("%m"); - } - return($this->dateFormat($year,$month,"01",$format)); + return($this->dateFormat("01",$month,$year,$format)); } // end of func beginOfMonth @@ -766,24 +744,22 @@ * @param string format for returned date * * @access public - * @version 1.0 - * @author Monte Ohrt <monte@ispi.net> * * @return string date in given format */ - function beginOfWeek($year="",$month="",$day="",$format="%Y%m%d") + function beginOfWeek($day="",$month="",$year="",$format="%Y%m%d") { - if(empty($year) || empty($month) || empty($day)) - { + if(empty($year)) $year = $this->dateNow("%Y"); + if(empty($month)) $month = $this->dateNow("%m"); + if(empty($day)) $day = $this->dateNow("%d"); - } - $this_weekday = $this->dayOfWeek($year,$month,$day); + $this_weekday = $this->dayOfWeek($day,$month,$year); - $beginOfWeek = ($this->dateToDays($year,$month,$day) + $beginOfWeek = ($this->dateToDays($day,$month,$year) - ($this_weekday - $this->begin_weekday)); return($this->daysToDate($beginOfWeek,$format)); @@ -801,24 +777,22 @@ * @param string format for returned date * * @access public - * @version 1.0 - * @author Monte Ohrt <monte@ispi.net> * * @return string date in given format */ - function endOfWeek($year="",$month="",$day="",$format="%Y%m%d") + function endOfWeek($day="",$month="",$year="",$format="%Y%m%d") { - if(empty($year) || empty($month) || empty($day)) - { + if(empty($year)) $year = $this->dateNow("%Y"); + if(empty($month)) $month = $this->dateNow("%m"); + if(empty($day)) $day = $this->dateNow("%d"); - } - $this_weekday = $this->dayOfWeek($year,$month,$day); + $this_weekday = $this->dayOfWeek($day,$month,$year); - $last_dayOfWeek = ($this->dateToDays($year,$month,$day) + $last_dayOfWeek = ($this->dateToDays($day,$month,$year) + (6 - $this_weekday + $this->begin_weekday)); return($this->daysToDate($last_dayOfWeek,$format)); @@ -835,30 +809,28 @@ * @param string format for returned date * * @access public - * @version 1.0 - * @author Monte Ohrt <monte@ispi.net> * * @return string date in given format */ - function beginOfNextWeek($year="",$month="",$day="",$format="%Y%m%d") + function beginOfNextWeek($day="",$month="",$year="",$format="%Y%m%d") { - if(empty($year) || empty($month) || empty($day)) - { + if(empty($year)) $year = $this->dateNow("%Y"); + if(empty($month)) $month = $this->dateNow("%m"); + if(empty($day)) $day = $this->dateNow("%d"); - } - $date = $this->daysToDate($this->dateToDays($year,$month,$day+7),"%Y%m%d"); + $date = $this->daysToDate($this->dateToDays($day+7,$month,$year),"%Y%m%d"); $next_week_year = substr($date,0,4); $next_week_month = substr($date,4,2); $next_week_day = substr($date,6,2); - $this_weekday = $this->dayOfWeek($next_week_year,$next_week_month,$next_week_day); + $this_weekday = $this->dayOfWeek($next_week_day,$next_week_month,$next_week_year); - $beginOfWeek = ($this->dateToDays($next_week_year,$next_week_month,$next_week_day) + $beginOfWeek = ($this->dateToDays($next_week_day,$next_week_month,$next_week_year) - ($this_weekday - $this->begin_weekday)); return($this->daysToDate($beginOfWeek,$format)); @@ -875,30 +847,28 @@ * @param string format for returned date * * @access public - * @version 1.0 - * @author Monte Ohrt <monte@ispi.net> * * @return string date in given format */ - function beginOfPrevWeek($year="",$month="",$day="",$format="%Y%m%d") + function beginOfPrevWeek($day="",$month="",$year="",$format="%Y%m%d") { - if(empty($year) || empty($month) || empty($day)) - { + if(empty($year)) $year = $this->dateNow("%Y"); + if(empty($month)) $month = $this->dateNow("%m"); + if(empty($day)) $day = $this->dateNow("%d"); - } - $date = $this->daysToDate($this->dateToDays($year,$month,$day-7),"%Y%m%d"); + $date = $this->daysToDate($this->dateToDays($day-7,$month,$year),"%Y%m%d"); $next_week_year = substr($date,0,4); $next_week_month = substr($date,4,2); $next_week_day = substr($date,6,2); - $this_weekday = $this->dayOfWeek($next_week_year,$next_week_month,$next_week_day); + $this_weekday = $this->dayOfWeek($next_week_day,$next_week_month,$next_week_year); - $beginOfWeek = ($this->dateToDays($next_week_year,$next_week_month,$next_week_day) + $beginOfWeek = ($this->dateToDays($next_week_day,$next_week_month,$next_week_year) - ($this_weekday - $this->begin_weekday)); return($this->daysToDate($beginOfWeek,$format)); @@ -914,26 +884,24 @@ * @param string format for returned date * * @access public - * @version 1.0 - * @author Monte Ohrt <monte@ispi.net> * * @return array $week[$weekday] */ - function getCalendarWeek($year="",$month="",$day="",$format="%Y%m%d") + function getCalendarWeek($day="",$month="",$year="",$format="%Y%m%d") { - if(empty($year) || empty($month) || empty($day)) - { + if(empty($year)) $year = $this->dateNow("%Y"); + if(empty($month)) $month = $this->dateNow("%m"); + if(empty($day)) $day = $this->dateNow("%d"); - } $week_array = array(); // date for the column of week - $curr_day = ($this->dateToDays($year,$month,$day) - - (($this->dayOfWeek($year,$month,$day) - $this->begin_weekday))); + $curr_day = ($this->dateToDays($day,$month,$year) + - (($this->dayOfWeek($day,$month,$year) - $this->begin_weekday))); for($counter=0; $counter <= 6; $counter++) { @@ -954,30 +922,28 @@ * @param string format for returned date * * @access public - * @version 1.0 - * @author Monte Ohrt <monte@ispi.net> * * @return array $month[$row][$col] */ - function getCalendarMonth($year="",$month="",$format="%Y%m%d") + function getCalendarMonth($month="",$year="",$format="%Y%m%d") { - if(empty($year) || empty($month)) - { + if(empty($year)) $year = $this->dateNow("%Y"); + if(empty($month)) $month = $this->dateNow("%m"); - } $month_array = array(); // date for the first row, first column of calendar month - $curr_day = ($this->dateToDays($year,$month,"01") - - $this->firstOfMonthWeekday($year,$month,"01") + $this->begin_weekday); + $curr_day = ($this->dateToDays("01",$month,$year) + - $this->firstOfMonthWeekday("01",$month,$year) + $this->begin_weekday); // number of days in this month - $daysInMonth = $this->daysInMonth($year,$month); + $daysInMonth = $this->daysInMonth($month,$year); - for($row_counter=0; $row_counter <= 5; $row_counter++) + $weeksInMonth = $this->weeksInMonth($month,$year); + for($row_counter=0; $row_counter < $weeksInMonth; $row_counter++) { for($column_counter=0; $column_counter <= 6; $column_counter++) { @@ -998,8 +964,6 @@ * @param string format for returned date * * @access public - * @version 1.0 - * @author Monte Ohrt <monte@ispi.net> * * @return array $year[$month][$row][$col] */ @@ -1014,7 +978,7 @@ for($curr_month=0; $curr_month <=11; $curr_month++) { - $year_array[$curr_month] = $this->getCalendarMonth($year,sprintf("%02d",$curr_month+1),$format); + $year_array[$curr_month] = $this->getCalendarMonth(sprintf("%02d",$curr_month+1),$year,$format); /* for ($x=0; $x< count($year_array[$curr_month]); $x++) { @@ -1038,13 +1002,11 @@ * @param string day in format DD * * @access public - * @version 1.0 - * @author Monte Ohrt <monte@ispi.net> * * @return integer number of days */ - function dateToDays($year,$month,$day) + function dateToDays($day,$month,$year) { $century = substr($year,0,2); @@ -1078,8 +1040,6 @@ * @param string format for returned date * * @access public - * @version 1.0 - * @author Monte Ohrt <monte@ispi.net> * * @return string date in specified format */ @@ -1115,7 +1075,7 @@ $century = sprintf("%02d",$century); $year = sprintf("%02d",$year); - return($this->dateFormat($century.$year,$month,$day,$format)); + return($this->dateFormat($day,$month,$century.$year,$format)); } // end func daysToDate @@ -1130,27 +1090,25 @@ * @param string format for returned date * * @access public - * @version 1.0b - * @author Monte Ohrt <monte@ispi.net> * * @return string date in given format */ - function NWeekdayOfMonth($occurance,$dayOfWeek,$year,$month,$format="%Y%m%d") { + function NWeekdayOfMonth($occurance,$dayOfWeek,$month,$year,$format="%Y%m%d") { $year = sprintf("%04d",$year); $month = sprintf("%02d",$month); $DOW1day = sprintf("%02d",(($occurance - 1) * 7 + 1)); - $DOW1 = $this->dayOfWeek($year,$month,$DOW1day); + $DOW1 = $this->dayOfWeek($month,$year,$DOW1day); $wdate = ($occurance - 1) * 7 + 1 + (7 + $dayOfWeek - $DOW1) % 7; - if( $wdate > $this->daysInMonth($year,$month)) + if( $wdate > $this->daysInMonth($month,$year)) return -1; else - return($this->dateFormat($year,$month,$wdate,$format)); + return($this->dateFormat($month,$year,$wdate,$format)); } // end func NWeekdayOfMonth @@ -1189,15 +1147,13 @@ * @param string format for returned date * * @access public - * @version 1.0 - * @author Monte Ohrt <monte@ispi.net> * * @return string date in given format */ - function dateFormat($year,$month,$day,$format) + function dateFormat($day,$month,$year,$format) { - if(!$this->isValidDate($year,$month,$day)) + if(!$this->isValidDate($day,$month,$year)) { $year = $this->dateNow("%Y"); $month = $this->dateNow("%m"); @@ -1215,10 +1171,10 @@ switch($nextchar) { case "a": - $output .= $this->getWeekdayAbbrname($year,$month,$day); + $output .= $this->getWeekdayAbbrname($day,$month,$year); break; case "A": - $output .= $this->getWeekdayFullname($year,$month,$day); + $output .= $this->getWeekdayFullname($day,$month,$year); break; case "b": $output .= $this->getMonthAbbrname($month); @@ -1233,10 +1189,10 @@ $output .= $day; break; case "E": - $output .= $this->dateToDays($year,$month,$day); + $output .= $this->dateToDays($day,$month,$year); break; case "j": - $output .= $this->julianDate($year,$month,$day); + $output .= $this->julianDate($day,$month,$year); break; case "m": $output .= sprintf("%02d",$month); @@ -1248,10 +1204,10 @@ $output .= "\t"; break; case "w": - $output .= $this->dayOfWeek($year,$month,$day); + $output .= $this->dayOfWeek($day,$month,$year); break; case "U": - $output .= $this->weekOfYear($year,$month,$day); + $output .= $this->weekOfYear($day,$month,$year); break; case "y": $output .= substr($year,2,2); @@ -1280,8 +1236,6 @@ * Returns the current local year in format CCYY * * @access public - * @version 1.0 - * @author Monte Ohrt <monte@ispi.net> * * @return string year in format CCYY */ @@ -1296,8 +1250,6 @@ * Returns the current local month in format MM * * @access public - * @version 1.0 - * @author Monte Ohrt <monte@ispi.net> * * @return string month in format MM */ @@ -1312,8 +1264,6 @@ * Returns the current local day in format DD * * @access public - * @version 1.0 - * @author Monte Ohrt <monte@ispi.net> * * @return string day in format DD */ @@ -1330,8 +1280,6 @@ * @param string month in format MM * * @access public - * @version 1.0 - * @author Monte Ohrt <monte@ispi.net> * * @return string full month name */ @@ -1355,8 +1303,6 @@ * @param int optional length of abbreviation, default is 3 * * @access public - * @version 1.0 - * @author Monte Ohrt <monte@ispi.net> * * @return string abbreviated month name */ @@ -1381,24 +1327,22 @@ * @param string day in format DD, default current local day * * @access public - * @version 1.0 - * @author Monte Ohrt <monte@ispi.net> * * @return string full month name */ - function getWeekdayFullname($year="",$month="",$day="") + function getWeekdayFullname($day="",$month="",$year="") { - if(empty($year) || empty($month) || empty($day)) - { + if(empty($year)) $year = $this->dateNow("%Y"); + if(empty($month)) $month = $this->dateNow("%m"); + if(empty($day)) $day = $this->dateNow("%d"); - } $weekday_names = array("Sunday","Monday","Tuesday", "Wednesday","Thursday","Friday","Saturday"); - $weekday = $this->dayOfWeek($year,$month,$day); + $weekday = $this->dayOfWeek($day,$month,$year); return $weekday_names[$weekday]; @@ -1413,25 +1357,23 @@ * @param int optional length of abbreviation, default is 3 * * @access public - * @version 1.0 - * @author Monte Ohrt <monte@ispi.net> * * @return string full month name */ - function getWeekdayAbbrname($year="",$month="",$day="",$length=3) + function getWeekdayAbbrname($day="",$month="",$year="",$length=3) { - if(empty($year) || empty($month) || empty($day)) - { + if(empty($year)) $year = $this->dateNow("%Y"); + if(empty($month)) $month = $this->dateNow("%m"); + if(empty($day)) $day = $this->dateNow("%d"); - } $weekday_names = array("Sunday","Monday","Tuesday", "Wednesday","Thursday","Friday","Saturday"); - $weekday = $this->dayOfWeek($year,$month,$day); + $weekday = $this->dayOfWeek($day,$month,$year); return substr($weekday_names[$weekday],0,$length);
Index: php4/pear/Date/Calc.php diff -u php4/pear/Date/Calc.php:1.4 php4/pear/Date/Calc.php:1.5 --- php4/pear/Date/Calc.php:1.4 Tue Oct 17 07:05:12 2000 +++ php4/pear/Date/Calc.php Wed Nov 15 07:25:29 2000 @@ -19,7 +19,7 @@ * * @access public * - * @version 1.0.4 + * @version 1.1 * @author Monte Ohrt <monte@ispi.net> */ @@ -30,7 +30,7 @@ * 0=Sunday, 1=Monday * * @access public - * @version 1.0 + * @version 1.1 * @author Monte Ohrt <monte@ispi.net> * * @var int [$begin_weekday] @@ -46,8 +46,6 @@ * @param string the strftime() format to return the date * * @access public - * @version 1.0 - * @author Monte Ohrt <monte@ispi.net> * * @return string the current date in specified format */ @@ -66,13 +64,11 @@ * @param string day in format DD * * @access public - * @version 1.0 - * @author Monte Ohrt <monte@ispi.net> * * @return boolean true/false */ - function isValidDate($year, $month, $day) + function isValidDate($day, $month, $year) { if(empty($year) || empty($month) || empty($day)) @@ -90,7 +86,7 @@ return false; if($month < 1 || $month > 12) return false; - if($day < 1 || $day > 31 || $day > $this->daysInMonth($year,$month)) + if($day < 1 || $day > 31 || $day > $this->daysInMonth($month,$year)) return false; return true; @@ -121,13 +117,11 @@ * @param string day in format DD * * @access public - * @version 1.0 - * @author Monte Ohrt <monte@ispi.net> * * @return boolean true/false */ - function isFutureDate($year,$month,$day) + function isFutureDate($day,$month,$year) { $this_year = $this->dateNow("%Y"); $this_month = $this->dateNow("%m"); @@ -155,13 +149,11 @@ * @param string day in format DD * * @access public - * @version 1.0 - * @author Monte Ohrt <monte@ispi.net> * * @return boolean true/false */ - function isPastDate($year,$month,$day) + function isPastDate($day,$month,$year) { $this_year = $this->dateNow("%Y"); $this_month = $this->dateNow("%m"); @@ -189,21 +181,19 @@ * @param string day in format DD, default is current local day * * @access public - * @version 1.0 - * @author Monte Ohrt <monte@ispi.net> * * @return int $weekday_number */ - function dayOfWeek($year="",$month="",$day="") + function dayOfWeek($day="",$month="",$year="") { - if(empty($year) || empty($month) || empty($day)) - { + if(empty($year)) $year = $this->dateNow("%Y"); + if(empty($month)) $month = $this->dateNow("%m"); + if(empty($day)) $day = $this->dateNow("%d"); - } if($month > 2) $month -= 2; @@ -233,27 +223,25 @@ * @param string day in format DD * * @access public - * @version 1.0 - * @author Monte Ohrt <monte@ispi.net> * * @return integer $week_number */ - function weekOfYear($year,$month,$day) + function weekOfYear($day,$month,$year) { - if(empty($year) || empty($month) || empty($day)) - { + if(empty($year)) $year = $this->dateNow("%Y"); + if(empty($month)) $month = $this->dateNow("%m"); + if(empty($day)) $day = $this->dateNow("%d"); - } $week_year = $year - 1501; $week_day = $week_year * 365 + floor($week_year / 4) - 29872 + 1 - floor($week_year / 100) + floor(($week_year - 300) / 400); $week_number = - floor(($this->julianDate($year,$month,$day) + floor(($week_day + 4) % 7)) / 7); + floor(($this->julianDate($day,$month,$year) + floor(($week_day + 4) % 7)) / 7); return $week_number; @@ -267,20 +255,18 @@ * @param string day in format DD, default is current local day * * @access public - * @version 1.0 - * @author Monte Ohrt <monte@ispi.net> * * @return int $julian */ - function julianDate($year="",$month="",$day="") + function julianDate($day="",$month="",$year="") { - if(empty($year) || empty($month) || empty($day)) - { + if(empty($year)) $year = $this->dateNow("%Y"); + if(empty($month)) $month = $this->dateNow("%m"); + if(empty($day)) $day = $this->dateNow("%d"); - } $days = array(0,31,59,90,120,151,181,212,243,273,304,334); @@ -301,20 +287,18 @@ * @param string day in format DD, default current local day * * @access public - * @version 1.0 - * @author Monte Ohrt <monte@ispi.net> * * @return int $year_quarter */ - function quarterOfYear($year="",$month="",$day="") + function quarterOfYear($day="",$month="",$year="") { - if(empty($year) || empty($month) || empty($day)) - { + if(empty($year)) $year = $this->dateNow("%Y"); + if(empty($month)) $month = $this->dateNow("%m"); + if(empty($day)) $day = $this->dateNow("%d"); - } $year_quarter = (intval(($month - 1) / 3 + 1)); @@ -331,20 +315,18 @@ * @param string format for returned date * * @access public - * @version 1.0 - * @author Monte Ohrt <monte@ispi.net> * * @return string date in given format - */ + */ - function beginOfNextMonth($year="",$month="",$day="",$format="%Y%m%d") + function beginOfNextMonth($day="",$month="",$year="",$format="%Y%m%d") { - if(empty($year) || empty($month) || empty($day)) - { + if(empty($year)) $year = $this->dateNow("%Y"); + if(empty($month)) $month = $this->dateNow("%m"); + if(empty($day)) $day = $this->dateNow("%d"); - } if($month < 12) { @@ -358,7 +340,7 @@ $day=1; } - return $this->dateFormat($year,$month,$day,$format); + return $this->dateFormat($day,$month,$year,$format); } // end func beginOfNextMonth @@ -371,22 +353,20 @@ * @param string format for returned date * * @access public - * @version 1.0 - * @author Monte Ohrt <monte@ispi.net> * * @return string date in given format */ - function endOfNextMonth($year="",$month="",$day="",$format="%Y%m%d") + function endOfNextMonth($day="",$month="",$year="",$format="%Y%m%d") { - if(empty($year) || empty($month) || empty($day)) - { + if(empty($year)) $year = $this->dateNow("%Y"); + if(empty($month)) $month = $this->dateNow("%m"); + if(empty($day)) $day = $this->dateNow("%d"); - } - $day = $this->daysInMonth($year,$month); + $day = $this->daysInMonth($month,$year); if($month < 12) { @@ -398,7 +378,7 @@ $month=1; } - return $this->dateFormat($year,$month,$day,$format); + return $this->dateFormat($day,$month,$year,$format); } // end func endOfNextMonth @@ -411,20 +391,18 @@ * @param string format for returned date * * @access public - * @version 1.0 - * @author Monte Ohrt <monte@ispi.net> * * @return string date in given format */ - function beginOfPrevMonth($year="",$month="",$day="",$format="%Y%m%d") + function beginOfPrevMonth($day="",$month="",$year="",$format="%Y%m%d") { - if(empty($year) || empty($month) || empty($day)) - { + if(empty($year)) $year = $this->dateNow("%Y"); + if(empty($month)) $month = $this->dateNow("%m"); + if(empty($day)) $day = $this->dateNow("%d"); - } if($month > 1) { @@ -438,7 +416,7 @@ $day=1; } - return $this->dateFormat($year,$month,$day,$format); + return $this->dateFormat($day,$month,$year,$format); } // end func beginOfPrevMonth @@ -451,22 +429,20 @@ * @param string format for returned date * * @access public - * @version 1.0b - * @author Monte Ohrt <monte@ispi.net> * * @return string date in given format */ - function endOfPrevMonth($year="",$month="",$day="",$format="%Y%m%d") + function endOfPrevMonth($day="",$month="",$year="",$format="%Y%m%d") { - if(empty($year) || empty($month) || empty($day)) - { + if(empty($year)) $year = $this->dateNow("%Y"); + if(empty($month)) $month = $this->dateNow("%m"); + if(empty($day)) $day = $this->dateNow("%d"); - } - $day = $this->daysInMonth($year,$month); + $day = $this->daysInMonth($month,$year); if($month > 1) { @@ -478,7 +454,7 @@ $month=12; } - return $this->dateFormat($year,$month,$day,$format); + return $this->dateFormat($day,$month,$year,$format); } // end func endOfPrevMonth @@ -492,26 +468,24 @@ * @param string format for returned date * * @access public - * @version 1.0 - * @author Monte Ohrt <monte@ispi.net> * * @return string date in given format */ - function nextWeekday($year="",$month="",$day="",$format="%Y%m%d") + function nextWeekday($day="",$month="",$year="",$format="%Y%m%d") { - if(empty($year) || empty($month) || empty($day)) - { + if(empty($year)) $year = $this->dateNow("%Y"); + if(empty($month)) $month = $this->dateNow("%m"); + if(empty($day)) $day = $this->dateNow("%d"); - } - $days = $this->dateToDays($year,$month,$day); + $days = $this->dateToDays($day,$month,$year); - if($this->dayOfWeek($year,$month,$day) == 5) + if($this->dayOfWeek($day,$month,$year) == 5) $days += 3; - elseif($this->dayOfWeek($year,$month,$day) == 6) + elseif($this->dayOfWeek($day,$month,$year) == 6) $days += 2; else $days += 1; @@ -530,26 +504,24 @@ * @param string format for returned date * * @access public - * @version 1.0 - * @author Monte Ohrt <monte@ispi.net> * * @return string date in given format */ - function prevWeekday($year="",$month="",$day="",$format="%Y%m%d") + function prevWeekday($day="",$month="",$year="",$format="%Y%m%d") { - if(empty($year) || empty($month) || empty($day)) - { + if(empty($year)) $year = $this->dateNow("%Y"); + if(empty($month)) $month = $this->dateNow("%m"); + if(empty($day)) $day = $this->dateNow("%d"); - } - $days = $this->dateToDays($year,$month,$day); + $days = $this->dateToDays($day,$month,$year); - if($this->dayOfWeek($year,$month,$day) == 1) + if($this->dayOfWeek($day,$month,$year) == 1) $days -= 3; - elseif($this->dayOfWeek($year,$month,$day) == 0) + elseif($this->dayOfWeek($day,$month,$year) == 0) $days -= 2; else $days -= 1; @@ -567,22 +539,20 @@ * @param string format for returned date * * @access public - * @version 1.0 - * @author Monte Ohrt <monte@ispi.net> * * @return string date in given format */ - function nextDay($year="",$month="",$day="",$format="%Y%m%d") + function nextDay($day="",$month="",$year="",$format="%Y%m%d") { - if(empty($year) || empty($month) || empty($day)) - { + if(empty($year)) $year = $this->dateNow("%Y"); + if(empty($month)) $month = $this->dateNow("%m"); + if(empty($day)) $day = $this->dateNow("%d"); - } - $days = $this->dateToDays($year,$month,$day); + $days = $this->dateToDays($day,$month,$year); return($this->daysToDate($days + 1,$format)); @@ -597,22 +567,20 @@ * @param string format for returned date * * @access public - * @version 1.0 - * @author Monte Ohrt <monte@ispi.net> * * @return string date in given format */ - function prevDay($year="",$month="",$day="",$format="%Y%m%d") + function prevDay($day="",$month="",$year="",$format="%Y%m%d") { - if(empty($year) || empty($month) || empty($day)) - { + if(empty($year)) $year = $this->dateNow("%Y"); + if(empty($month)) $month = $this->dateNow("%m"); + if(empty($day)) $day = $this->dateNow("%d"); - } - $days = $this->dateToDays($year,$month,$day); + $days = $this->dateToDays($day,$month,$year); return($this->daysToDate($days - 1,$format)); @@ -625,8 +593,6 @@ * @param string 2 digit year * * @access public - * @version 1.0 - * @author Monte Ohrt <monte@ispi.net> * * @return string 4 digit year */ @@ -653,22 +619,20 @@ * @param string day in format DD * * @access public - * @version 1.0 - * @author Monte Ohrt <monte@ispi.net> * * @return int absolute number of days between dates, * -1 if there is an error. */ - function dateDiff($year1,$month1,$day1,$year2,$month2,$day2) + function dateDiff($day1,$month1,$year1,$day2,$month2,$year2) { - if(!$this->isValidDate($year1,$month1,$day1)) + if(!$this->isValidDate($day1,$month1,$year1)) return -1; - if(!$this->isValidDate($year2,$month2,$day2)) + if(!$this->isValidDate($day2,$month2,$year2)) return -1; - return(abs(($this->dateToDays($year1,$month1,$day1)) - - ($this->dateToDays($year2,$month2,$day2)))); + return(abs(($this->dateToDays($day1,$month1,$year1)) + - ($this->dateToDays($day2,$month2,$year2)))); } // end func dateDiff @@ -678,18 +642,16 @@ * @param string month in format MM, default current local month * * @access public - * @version 1.0 - * @author Monte Ohrt <monte@ispi.net> * * @return int number of days */ - function daysInMonth($year="",$month="") + function daysInMonth($month="",$year="") { + if(empty($year)) + $year = $this->dateNow("%Y"); if(empty($month)) $month = $this->dateNow("%m"); - if(empty($year)) - $month = $this->dateNow("%Y"); if($month == 2) { @@ -704,29 +666,48 @@ return 31; } // end func daysInMonth - + /** + * Find the number of weeks in the given month. + * + * @param string month in format MM, default current local month + * @param string year in format YYCC, default current local year + * + * @access public + * + * @return int number of weeks + */ + + function weeksInMonth($month="",$year="") + { + if(empty($year)) + $year = $this->dateNow("%Y"); + if(empty($month)) + $month = $this->dateNow("%m"); + + return ceil(($this->daysInMonth($month,$year)+$this->firstOfMonthWeekday("01",$month,$year)-$this->begin_weekday)/7); + + } // end func weeksInMonth + + /** * Find the day of the week for the first of the month of given date. * * @param string year in format CCYY, default to current local year * @param string month in format MM, default to current local month * * @access public - * @version 1.0 - * @author Monte Ohrt <monte@ispi.net> * * @return int number of weekday for the first day, 0=Sunday */ - function firstOfMonthWeekday($year="",$month="") + function firstOfMonthWeekday($month="",$year="") { - if(empty($year) || empty($month)) - { + if(empty($year)) $year = $this->dateNow("%Y"); + if(empty($month)) $month = $this->dateNow("%m"); - } - return($this->dayOfWeek($year,$month,"01")); + return($this->dayOfWeek("01",$month,$year)); } // end func firstOfMonthWeekday @@ -738,21 +719,18 @@ * @param string format for returned date * * @access public - * @version 1.0 - * @author Monte Ohrt <monte@ispi.net> * * @return string date in given format */ - function beginOfMonth($year="",$month="",$format="%Y%m%d") + function beginOfMonth($month="",$year="",$format="%Y%m%d") { - if(empty($year) || empty($month)) - { + if(empty($year)) $year = $this->dateNow("%Y"); + if(empty($month)) $month = $this->dateNow("%m"); - } - return($this->dateFormat($year,$month,"01",$format)); + return($this->dateFormat("01",$month,$year,$format)); } // end of func beginOfMonth @@ -766,24 +744,22 @@ * @param string format for returned date * * @access public - * @version 1.0 - * @author Monte Ohrt <monte@ispi.net> * * @return string date in given format */ - function beginOfWeek($year="",$month="",$day="",$format="%Y%m%d") + function beginOfWeek($day="",$month="",$year="",$format="%Y%m%d") { - if(empty($year) || empty($month) || empty($day)) - { + if(empty($year)) $year = $this->dateNow("%Y"); + if(empty($month)) $month = $this->dateNow("%m"); + if(empty($day)) $day = $this->dateNow("%d"); - } - $this_weekday = $this->dayOfWeek($year,$month,$day); + $this_weekday = $this->dayOfWeek($day,$month,$year); - $beginOfWeek = ($this->dateToDays($year,$month,$day) + $beginOfWeek = ($this->dateToDays($day,$month,$year) - ($this_weekday - $this->begin_weekday)); return($this->daysToDate($beginOfWeek,$format)); @@ -801,24 +777,22 @@ * @param string format for returned date * * @access public - * @version 1.0 - * @author Monte Ohrt <monte@ispi.net> * * @return string date in given format */ - function endOfWeek($year="",$month="",$day="",$format="%Y%m%d") + function endOfWeek($day="",$month="",$year="",$format="%Y%m%d") { - if(empty($year) || empty($month) || empty($day)) - { + if(empty($year)) $year = $this->dateNow("%Y"); + if(empty($month)) $month = $this->dateNow("%m"); + if(empty($day)) $day = $this->dateNow("%d"); - } - $this_weekday = $this->dayOfWeek($year,$month,$day); + $this_weekday = $this->dayOfWeek($day,$month,$year); - $last_dayOfWeek = ($this->dateToDays($year,$month,$day) + $last_dayOfWeek = ($this->dateToDays($day,$month,$year) + (6 - $this_weekday + $this->begin_weekday)); return($this->daysToDate($last_dayOfWeek,$format)); @@ -835,30 +809,28 @@ * @param string format for returned date * * @access public - * @version 1.0 - * @author Monte Ohrt <monte@ispi.net> * * @return string date in given format */ - function beginOfNextWeek($year="",$month="",$day="",$format="%Y%m%d") + function beginOfNextWeek($day="",$month="",$year="",$format="%Y%m%d") { - if(empty($year) || empty($month) || empty($day)) - { + if(empty($year)) $year = $this->dateNow("%Y"); + if(empty($month)) $month = $this->dateNow("%m"); + if(empty($day)) $day = $this->dateNow("%d"); - } - $date = $this->daysToDate($this->dateToDays($year,$month,$day+7),"%Y%m%d"); + $date = $this->daysToDate($this->dateToDays($day+7,$month,$year),"%Y%m%d"); $next_week_year = substr($date,0,4); $next_week_month = substr($date,4,2); $next_week_day = substr($date,6,2); - $this_weekday = $this->dayOfWeek($next_week_year,$next_week_month,$next_week_day); + $this_weekday = $this->dayOfWeek($next_week_day,$next_week_month,$next_week_year); - $beginOfWeek = ($this->dateToDays($next_week_year,$next_week_month,$next_week_day) + $beginOfWeek = ($this->dateToDays($next_week_day,$next_week_month,$next_week_year) - ($this_weekday - $this->begin_weekday)); return($this->daysToDate($beginOfWeek,$format)); @@ -875,30 +847,28 @@ * @param string format for returned date * * @access public - * @version 1.0 - * @author Monte Ohrt <monte@ispi.net> * * @return string date in given format */ - function beginOfPrevWeek($year="",$month="",$day="",$format="%Y%m%d") + function beginOfPrevWeek($day="",$month="",$year="",$format="%Y%m%d") { - if(empty($year) || empty($month) || empty($day)) - { + if(empty($year)) $year = $this->dateNow("%Y"); + if(empty($month)) $month = $this->dateNow("%m"); + if(empty($day)) $day = $this->dateNow("%d"); - } - $date = $this->daysToDate($this->dateToDays($year,$month,$day-7),"%Y%m%d"); + $date = $this->daysToDate($this->dateToDays($day-7,$month,$year),"%Y%m%d"); $next_week_year = substr($date,0,4); $next_week_month = substr($date,4,2); $next_week_day = substr($date,6,2); - $this_weekday = $this->dayOfWeek($next_week_year,$next_week_month,$next_week_day); + $this_weekday = $this->dayOfWeek($next_week_day,$next_week_month,$next_week_year); - $beginOfWeek = ($this->dateToDays($next_week_year,$next_week_month,$next_week_day) + $beginOfWeek = ($this->dateToDays($next_week_day,$next_week_month,$next_week_year) - ($this_weekday - $this->begin_weekday)); return($this->daysToDate($beginOfWeek,$format)); @@ -914,26 +884,24 @@ * @param string format for returned date * * @access public - * @version 1.0 - * @author Monte Ohrt <monte@ispi.net> * * @return array $week[$weekday] */ - function getCalendarWeek($year="",$month="",$day="",$format="%Y%m%d") + function getCalendarWeek($day="",$month="",$year="",$format="%Y%m%d") { - if(empty($year) || empty($month) || empty($day)) - { + if(empty($year)) $year = $this->dateNow("%Y"); + if(empty($month)) $month = $this->dateNow("%m"); + if(empty($day)) $day = $this->dateNow("%d"); - } $week_array = array(); // date for the column of week - $curr_day = ($this->dateToDays($year,$month,$day) - - (($this->dayOfWeek($year,$month,$day) - $this->begin_weekday))); + $curr_day = ($this->dateToDays($day,$month,$year) + - (($this->dayOfWeek($day,$month,$year) - $this->begin_weekday))); for($counter=0; $counter <= 6; $counter++) { @@ -954,30 +922,28 @@ * @param string format for returned date * * @access public - * @version 1.0 - * @author Monte Ohrt <monte@ispi.net> * * @return array $month[$row][$col] */ - function getCalendarMonth($year="",$month="",$format="%Y%m%d") + function getCalendarMonth($month="",$year="",$format="%Y%m%d") { - if(empty($year) || empty($month)) - { + if(empty($year)) $year = $this->dateNow("%Y"); + if(empty($month)) $month = $this->dateNow("%m"); - } $month_array = array(); // date for the first row, first column of calendar month - $curr_day = ($this->dateToDays($year,$month,"01") - - $this->firstOfMonthWeekday($year,$month,"01") + $this->begin_weekday); + $curr_day = ($this->dateToDays("01",$month,$year) + - $this->firstOfMonthWeekday("01",$month,$year) + $this->begin_weekday); // number of days in this month - $daysInMonth = $this->daysInMonth($year,$month); + $daysInMonth = $this->daysInMonth($month,$year); - for($row_counter=0; $row_counter <= 5; $row_counter++) + $weeksInMonth = $this->weeksInMonth($month,$year); + for($row_counter=0; $row_counter < $weeksInMonth; $row_counter++) { for($column_counter=0; $column_counter <= 6; $column_counter++) { @@ -998,8 +964,6 @@ * @param string format for returned date * * @access public - * @version 1.0 - * @author Monte Ohrt <monte@ispi.net> * * @return array $year[$month][$row][$col] */ @@ -1014,7 +978,7 @@ for($curr_month=0; $curr_month <=11; $curr_month++) { - $year_array[$curr_month] = $this->getCalendarMonth($year,sprintf("%02d",$curr_month+1),$format); + $year_array[$curr_month] = $this->getCalendarMonth(sprintf("%02d",$curr_month+1),$year,$format); /* for ($x=0; $x< count($year_array[$curr_month]); $x++) { @@ -1038,13 +1002,11 @@ * @param string day in format DD * * @access public - * @version 1.0 - * @author Monte Ohrt <monte@ispi.net> * * @return integer number of days */ - function dateToDays($year,$month,$day) + function dateToDays($day,$month,$year) { $century = substr($year,0,2); @@ -1078,8 +1040,6 @@ * @param string format for returned date * * @access public - * @version 1.0 - * @author Monte Ohrt <monte@ispi.net> * * @return string date in specified format */ @@ -1115,7 +1075,7 @@ $century = sprintf("%02d",$century); $year = sprintf("%02d",$year); - return($this->dateFormat($century.$year,$month,$day,$format)); + return($this->dateFormat($day,$month,$century.$year,$format)); } // end func daysToDate @@ -1130,27 +1090,25 @@ * @param string format for returned date * * @access public - * @version 1.0b - * @author Monte Ohrt <monte@ispi.net> * * @return string date in given format */ - function NWeekdayOfMonth($occurance,$dayOfWeek,$year,$month,$format="%Y%m%d") { + function NWeekdayOfMonth($occurance,$dayOfWeek,$month,$year,$format="%Y%m%d") { $year = sprintf("%04d",$year); $month = sprintf("%02d",$month); $DOW1day = sprintf("%02d",(($occurance - 1) * 7 + 1)); - $DOW1 = $this->dayOfWeek($year,$month,$DOW1day); + $DOW1 = $this->dayOfWeek($month,$year,$DOW1day); $wdate = ($occurance - 1) * 7 + 1 + (7 + $dayOfWeek - $DOW1) % 7; - if( $wdate > $this->daysInMonth($year,$month)) + if( $wdate > $this->daysInMonth($month,$year)) return -1; else - return($this->dateFormat($year,$month,$wdate,$format)); + return($this->dateFormat($month,$year,$wdate,$format)); } // end func NWeekdayOfMonth @@ -1189,15 +1147,13 @@ * @param string format for returned date * * @access public - * @version 1.0 - * @author Monte Ohrt <monte@ispi.net> * * @return string date in given format */ - function dateFormat($year,$month,$day,$format) + function dateFormat($day,$month,$year,$format) { - if(!$this->isValidDate($year,$month,$day)) + if(!$this->isValidDate($day,$month,$year)) { $year = $this->dateNow("%Y"); $month = $this->dateNow("%m"); @@ -1215,10 +1171,10 @@ switch($nextchar) { case "a": - $output .= $this->getWeekdayAbbrname($year,$month,$day); + $output .= $this->getWeekdayAbbrname($day,$month,$year); break; case "A": - $output .= $this->getWeekdayFullname($year,$month,$day); + $output .= $this->getWeekdayFullname($day,$month,$year); break; case "b": $output .= $this->getMonthAbbrname($month); @@ -1233,10 +1189,10 @@ $output .= $day; break; case "E": - $output .= $this->dateToDays($year,$month,$day); + $output .= $this->dateToDays($day,$month,$year); break; case "j": - $output .= $this->julianDate($year,$month,$day); + $output .= $this->julianDate($day,$month,$year); break; case "m": $output .= sprintf("%02d",$month); @@ -1248,10 +1204,10 @@ $output .= "\t"; break; case "w": - $output .= $this->dayOfWeek($year,$month,$day); + $output .= $this->dayOfWeek($day,$month,$year); break; case "U": - $output .= $this->weekOfYear($year,$month,$day); + $output .= $this->weekOfYear($day,$month,$year); break; case "y": $output .= substr($year,2,2); @@ -1280,8 +1236,6 @@ * Returns the current local year in format CCYY * * @access public - * @version 1.0 - * @author Monte Ohrt <monte@ispi.net> * * @return string year in format CCYY */ @@ -1296,8 +1250,6 @@ * Returns the current local month in format MM * * @access public - * @version 1.0 - * @author Monte Ohrt <monte@ispi.net> * * @return string month in format MM */ @@ -1312,8 +1264,6 @@ * Returns the current local day in format DD * * @access public - * @version 1.0 - * @author Monte Ohrt <monte@ispi.net> * * @return string day in format DD */ @@ -1330,8 +1280,6 @@ * @param string month in format MM * * @access public - * @version 1.0 - * @author Monte Ohrt <monte@ispi.net> * * @return string full month name */ @@ -1355,8 +1303,6 @@ * @param int optional length of abbreviation, default is 3 * * @access public - * @version 1.0 - * @author Monte Ohrt <monte@ispi.net> * * @return string abbreviated month name */ @@ -1381,24 +1327,22 @@ * @param string day in format DD, default current local day * * @access public - * @version 1.0 - * @author Monte Ohrt <monte@ispi.net> * * @return string full month name */ - function getWeekdayFullname($year="",$month="",$day="") + function getWeekdayFullname($day="",$month="",$year="") { - if(empty($year) || empty($month) || empty($day)) - { + if(empty($year)) $year = $this->dateNow("%Y"); + if(empty($month)) $month = $this->dateNow("%m"); + if(empty($day)) $day = $this->dateNow("%d"); - } $weekday_names = array("Sunday","Monday","Tuesday", "Wednesday","Thursday","Friday","Saturday"); - $weekday = $this->dayOfWeek($year,$month,$day); + $weekday = $this->dayOfWeek($day,$month,$year); return $weekday_names[$weekday]; @@ -1413,25 +1357,23 @@ * @param int optional length of abbreviation, default is 3 * * @access public - * @version 1.0 - * @author Monte Ohrt <monte@ispi.net> * * @return string full month name */ - function getWeekdayAbbrname($year="",$month="",$day="",$length=3) + function getWeekdayAbbrname($day="",$month="",$year="",$length=3) { - if(empty($year) || empty($month) || empty($day)) - { + if(empty($year)) $year = $this->dateNow("%Y"); + if(empty($month)) $month = $this->dateNow("%m"); + if(empty($day)) $day = $this->dateNow("%d"); - } $weekday_names = array("Sunday","Monday","Tuesday", "Wednesday","Thursday","Friday","Saturday"); - $weekday = $this->dayOfWeek($year,$month,$day); + $weekday = $this->dayOfWeek($day,$month,$year); return substr($weekday_names[$weekday],0,$length);