cvs: php4 /pear/Date Calc.php

From: Date: Thu, 06 Jun 2002 11:38:10 +0000
Subject: cvs: php4 /pear/Date Calc.php
Groups: php.pear.cvs 
Request: Send a blank email to pear-cvs+get-4452@lists.php.net to get a copy of this message
cox Thu Jun 6 07:38:10 2002 EDT Modified files: /php4/pear/Date Calc.php Log: ws+cs Index: php4/pear/Date/Calc.php diff -u php4/pear/Date/Calc.php:1.18 php4/pear/Date/Calc.php:1.19 --- php4/pear/Date/Calc.php:1.18 Mon Jan 14 13:55:24 2002 +++ php4/pear/Date/Calc.php Thu Jun 6 07:38:09 2002 @@ -28,8 +28,8 @@ * @author Monte Ohrt <monte@ispi.net> */ -class Date_Calc { - +class Date_Calc +{ /** * Returns the current local date. NOTE: This function * retrieves the local date using strftime(), which may @@ -805,17 +805,17 @@ if(empty($month)) $month = Date_Calc::dateNow("%m"); - if(DATE_CALC_BEGIN_WEEKDAY == 1) - { + if(DATE_CALC_BEGIN_WEEKDAY == 1) + { - if(Date_Calc::firstOfMonthWeekday($month,$year) == 0) - $first_week_days = 1; - else - $first_week_days = 7 - (Date_Calc::firstOfMonthWeekday($month,$year) - 1); - - } - else - $first_week_days = 7 - Date_Calc::firstOfMonthWeekday($month,$year); + if(Date_Calc::firstOfMonthWeekday($month,$year) == 0) + $first_week_days = 1; + else + $first_week_days = 7 - (Date_Calc::firstOfMonthWeekday($month,$year) - 1); + + } + else + $first_week_days = 7 - Date_Calc::firstOfMonthWeekday($month,$year); return ceil(((Date_Calc::daysInMonth($month,$year) - $first_week_days) / 7) + 1); @@ -891,17 +891,17 @@ $this_weekday = Date_Calc::dayOfWeek($day,$month,$year); - if(DATE_CALC_BEGIN_WEEKDAY == 1) - { - if($this_weekday == 0) - $beginOfWeek = Date_Calc::dateToDays($day,$month,$year) - 6; - else - $beginOfWeek = Date_Calc::dateToDays($day,$month,$year) - - $this_weekday + 1; - } - else - $beginOfWeek = (Date_Calc::dateToDays($day,$month,$year) - - $this_weekday); + if(DATE_CALC_BEGIN_WEEKDAY == 1) + { + if($this_weekday == 0) + $beginOfWeek = Date_Calc::dateToDays($day,$month,$year) - 6; + else + $beginOfWeek = Date_Calc::dateToDays($day,$month,$year) + - $this_weekday + 1; + } + else + $beginOfWeek = (Date_Calc::dateToDays($day,$month,$year) + - $this_weekday); /* $beginOfWeek = (Date_Calc::dateToDays($day,$month,$year) @@ -1081,17 +1081,17 @@ $month_array = array(); // date for the first row, first column of calendar month - if(DATE_CALC_BEGIN_WEEKDAY == 1) - { - if(Date_Calc::firstOfMonthWeekday($month,$year) == 0) - $curr_day = Date_Calc::dateToDays("01",$month,$year) - 6; - else - $curr_day = Date_Calc::dateToDays("01",$month,$year) - - Date_Calc::firstOfMonthWeekday($month,$year) + 1; - } - else - $curr_day = (Date_Calc::dateToDays("01",$month,$year) - - Date_Calc::firstOfMonthWeekday($month,$year)); + if(DATE_CALC_BEGIN_WEEKDAY == 1) + { + if(Date_Calc::firstOfMonthWeekday($month,$year) == 0) + $curr_day = Date_Calc::dateToDays("01",$month,$year) - 6; + else + $curr_day = Date_Calc::dateToDays("01",$month,$year) + - Date_Calc::firstOfMonthWeekday($month,$year) + 1; + } + else + $curr_day = (Date_Calc::dateToDays("01",$month,$year) + - Date_Calc::firstOfMonthWeekday($month,$year)); // number of days in this month $daysInMonth = Date_Calc::daysInMonth($month,$year); @@ -1190,18 +1190,18 @@ function daysToDate($days,$format="%Y%m%d") { - $days -= 1721119; - $century = floor(( 4 * $days - 1) / 146097); - $days = floor(4 * $days - 1 - 146097 * $century); - $day = floor($days / 4); - - $year = floor(( 4 * $day + 3) / 1461); - $day = floor(4 * $day + 3 - 1461 * $year); - $day = floor(($day + 4) / 4); - - $month = floor(( 5 * $day - 3) / 153); - $day = floor(5 * $day - 3 - 153 * $month); - $day = floor(($day + 5) / 5); + $days -= 1721119; + $century = floor(( 4 * $days - 1) / 146097); + $days = floor(4 * $days - 1 - 146097 * $century); + $day = floor($days / 4); + + $year = floor(( 4 * $day + 3) / 1461); + $day = floor(4 * $day + 3 - 1461 * $year); + $day = floor(($day + 4) / 4); + + $month = floor(( 5 * $day - 3) / 153); + $day = floor(5 * $day - 3 - 153 * $month); + $day = floor(($day + 5) / 5); if($month < 10) $month +=3; @@ -1237,8 +1237,8 @@ * @return string date in given format */ - function NWeekdayOfMonth($occurance,$dayOfWeek,$month,$year,$format="%Y%m%d") { - + function NWeekdayOfMonth($occurance,$dayOfWeek,$month,$year,$format="%Y%m%d") + { $year = sprintf("%04d",$year); $month = sprintf("%02d",$month); @@ -1524,7 +1524,8 @@ * @param string month name * @return integer month number */ - function getMonthFromFullName($month){ + function getMonthFromFullName($month) + { $month = strtolower($month); $months = Date_Calc::getMonthNames(); while(list($id, $name) = each($months)){ @@ -1544,7 +1545,8 @@ * * @returns array An array of month names */ - function getMonthNames(){ + function getMonthNames() + { for($i=1;$i<13;$i++){ $months[$i] = strftime('%B', mktime(0, 0, 0, $i, 1, 2001)); } @@ -1560,7 +1562,8 @@ * * @returns array An array of week day names */ - function getWeekDays(){ + function getWeekDays() + { for($i=0;$i<7;$i++){ $weekdays[$i] = strftime('%A', mktime(0, 0, 0, 1, $i, 2001)); }

« previous php.pear.cvs (#4452) next »