cvs: php4 /pear/Date Calc.php
| From: | Yavor Shahpasov | Date: | Mon, 20 Aug 2001 22:14:21 +0000 |
| Subject: | cvs: php4 /pear/Date Calc.php | ||
| Groups: | php.pear.cvs | ||
| Request: | Send a blank email to pear-cvs+get-594@lists.php.net to get a copy of this message | ||
yavo Mon Aug 20 18:14:21 2001 EDT
Modified files:
/php4/pear/Date Calc.php
Log:
- Added getMonthNames and getWeekDays methods to get month and week day names in the current
locale.
- Replaced all literal occurences of month names and week days with getMonthNames and getWeekDays
Index: php4/pear/Date/Calc.php
diff -u php4/pear/Date/Calc.php:1.13 php4/pear/Date/Calc.php:1.14
--- php4/pear/Date/Calc.php:1.13 Mon Aug 20 16:58:52 2001
+++ php4/pear/Date/Calc.php Mon Aug 20 18:14:20 2001
@@ -1432,10 +1432,10 @@
if(empty($month))
$month = Date_Calc::dateNow("%m");
- $month_names =
array("January","February","March","April","May","June",
-
"July","August","September","October","November","December");
-
- return $month_names[($month - 1)];
+ $month_names = Date_Calc::getMonthNames();
+ return $month_names[$month];
+ // getMonthNames returns months with correct indexes
+ //return $month_names[($month - 1)];
} // end func getMonthFullname
@@ -1448,18 +1448,14 @@
* @access public
*
* @return string abbreviated month name
+ * @see Date_Calc::getMonthFullname
*/
function getMonthAbbrname($month,$length=3)
{
if(empty($month))
$month = Date_Calc::dateNow("%m");
-
- $month_names =
array("January","February","March","April","May","June",
-
"July","August","September","October","November","December");
-
- return substr($month_names[($month - 1)],0,$length);
-
+ return substr(Date_Calc::getMonthFullname($month), 0, $length);
} // end func getMonthAbbrname
/**
@@ -1483,8 +1479,7 @@
if(empty($day))
$day = Date_Calc::dateNow("%d");
- $weekday_names = array("Sunday","Monday","Tuesday",
-
"Wednesday","Thursday","Friday","Saturday");
+ $weekday_names = Date_Calc::getWeekDays();
$weekday = Date_Calc::dayOfWeek($day,$month,$year);
return $weekday_names[$weekday];
@@ -1502,6 +1497,7 @@
* @access public
*
* @return string full month name
+ * @see Date_Calc::getWeekdayFullname
*/
function getWeekdayAbbrname($day="",$month="",$year="",$length=3)
@@ -1512,37 +1508,59 @@
$month = Date_Calc::dateNow("%m");
if(empty($day))
$day = Date_Calc::dateNow("%d");
+ return substr(Date_Calc::getWeekdayFullname($day,$month,$year),0,$length);
+ } // end func getWeekdayFullname
- $weekday_names = array("Sunday","Monday","Tuesday",
-
"Wednesday","Thursday","Friday","Saturday");
-
- $weekday = Date_Calc::dayOfWeek($day,$month,$year);
-
- return substr($weekday_names[$weekday],0,$length);
-
- } // end func getWeekdayFullname
-
- /**
- * Returns the numeric month from the month name or an abreviation
- *
- * Both August and Aug would return 8
- *
- * @param string month name
- * @return integer month number
- */
- function getMonthFromFullName($month){
- $month = strtolower($month);
- $months = array("january"=>1, "february"=>2,
"march"=>3,
- "april"=>4, "may"=>5,
"june"=>6,
- "july"=>7, "august"=>8,
"september"=>9,
- "october"=>10, "november"=>11,
"december"=>12);
- while(list($name, $id) = each($months)){
- if(ereg($month, $name)){
- return($id);
- }
- }
- return(0);
- }
+ /**
+ * Returns the numeric month from the month name or an abreviation
+ *
+ * Both August and Aug would return 8
+ *
+ * @param string month name
+ * @return integer month number
+ */
+ function getMonthFromFullName($month){
+ $month = strtolower($month);
+ $months = Date_Calc::getMonthNames();
+ while(list($id, $name) = each($months)){
+ if(ereg($month, $name)){
+ return($id);
+ }
+ }
+ return(0);
+ }
+
+ /**
+ * Retunrs an array of month names
+ *
+ * Used to take advantage of the setlocale function to return
+ * language specific month names.
+ * XXX cache values to some global array to avoid preformace hits when called more than once.
+ *
+ * @returns array An array of month names
+ */
+ function getMonthNames(){
+ for($i=1;$i<13;$i++){
+ $months[$i] = strftime('%B', mktime(0, 0, 0, $i, 1, 2001));
+ }
+ return($months);
+ }
+
+ /**
+ * Returns an array of week days
+ *
+ * Used to take advantage of the setlocale function to
+ * return language specific week days
+ * XXX cache values to some global array to avoid preformace hits when called more than once.
+ *
+ * @returns array An array of week day names
+ */
+ function getWeekDays(){
+ for($i=0;$i<7;$i++){
+ $weekdays[$i] = strftime('%A', mktime(0, 0, 0, 1, $i, 2001));
+ }
+ return($weekdays);
+ }
} // end class Date_calendar