- Timestamp:
- 2013/08/26 12:42:34 (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/version-2_13-dev/data/module/Calendar/Util/Textual.php
r20119 r23125 1 1 <?php 2 2 /* vim: set expandtab tabstop=4 shiftwidth=4: */ 3 // 4 // +----------------------------------------------------------------------+ 5 // | PHP Version 4 | 6 // +----------------------------------------------------------------------+ 7 // | Copyright (c) 1997-2002 The PHP Group | 8 // +----------------------------------------------------------------------+ 9 // | This source file is subject to version 2.02 of the PHP license, | 10 // | that is bundled with this package in the file LICENSE, and is | 11 // | available at through the world-wide-web at | 12 // | http://www.php.net/license/3_0.txt. | 13 // | If you did not receive a copy of the PHP license and are unable to | 14 // | obtain it through the world-wide-web, please send a note to | 15 // | [email protected] so we can mail you a copy immediately. | 16 // +----------------------------------------------------------------------+ 17 // | Authors: Harry Fuecks <[email protected]> | 18 // | Lorenzo Alberton <l dot alberton at quipo dot it> | 19 // +----------------------------------------------------------------------+ 20 // 21 // $Id: Textual.php,v 1.2 2004/08/16 13:13:09 hfuecks Exp $ 22 // 3 4 /** 5 * Contains the Calendar_Util_Textual class 6 * 7 * PHP versions 4 and 5 8 * 9 * LICENSE: Redistribution and use in source and binary forms, with or without 10 * modification, are permitted provided that the following conditions are met: 11 * 1. Redistributions of source code must retain the above copyright 12 * notice, this list of conditions and the following disclaimer. 13 * 2. Redistributions in binary form must reproduce the above copyright 14 * notice, this list of conditions and the following disclaimer in the 15 * documentation and/or other materials provided with the distribution. 16 * 3. The name of the author may not be used to endorse or promote products 17 * derived from this software without specific prior written permission. 18 * 19 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR IMPLIED 20 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 21 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 22 * IN NO EVENT SHALL THE FREEBSD PROJECT OR CONTRIBUTORS BE LIABLE FOR ANY 23 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 24 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 25 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 26 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 28 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 * 30 * @category Date and Time 31 * @package Calendar 32 * @author Harry Fuecks <[email protected]> 33 * @author Lorenzo Alberton <[email protected]> 34 * @copyright 2003-2007 Harry Fuecks, Lorenzo Alberton 35 * @license http://www.debian.org/misc/bsd.license BSD License (3 Clause) 36 * @version CVS: $Id: Textual.php 247250 2007-11-28 19:42:01Z quipo $ 37 * @link http://pear.php.net/package/Calendar 38 */ 39 23 40 /** 24 41 * @package Calendar 25 * @version $Id: Textual.php ,v 1.2 2004/08/16 13:13:09 hfuecks Exp$42 * @version $Id: Textual.php 247250 2007-11-28 19:42:01Z quipo $ 26 43 */ 27 44 … … 42 59 * Static utlities to help with fetching textual representations of months and 43 60 * days of the week. 44 * @package Calendar 45 * @access public 61 * 62 * @category Date and Time 63 * @package Calendar 64 * @author Harry Fuecks <[email protected]> 65 * @author Lorenzo Alberton <[email protected]> 66 * @copyright 2003-2007 Harry Fuecks, Lorenzo Alberton 67 * @license http://www.debian.org/misc/bsd.license BSD License (3 Clause) 68 * @link http://pear.php.net/package/Calendar 69 * @access public 46 70 */ 47 71 class Calendar_Util_Textual … … 50 74 /** 51 75 * Returns an array of 12 month names (first index = 1) 52 * @param string (optional) format of returned months (one,two,short or long) 76 * 77 * @param string $format (optional) format of returned months (one|two|short|long) 78 * 53 79 * @return array 54 80 * @access public 55 81 * @static 56 82 */ 57 function monthNames($format='long') 58 { 59 $formats = array('one'=>'%b', 'two'=>'%b', 'short'=>'%b', 'long'=>'%B'); 60 if (!array_key_exists($format,$formats)) { 83 function monthNames($format = 'long') 84 { 85 $formats = array( 86 'one' => '%b', 87 'two' => '%b', 88 'short' => '%b', 89 'long' => '%B', 90 ); 91 if (!array_key_exists($format, $formats)) { 61 92 $format = 'long'; 62 93 } … … 66 97 $month = strftime($formats[$format], $stamp); 67 98 switch($format) { 68 case 'one':69 $month = substr($month, 0, 1);99 case 'one': 100 $month = substr($month, 0, 1); 70 101 break; 71 case 'two':72 $month = substr($month, 0, 2);102 case 'two': 103 $month = substr($month, 0, 2); 73 104 break; 74 105 } … … 80 111 /** 81 112 * Returns an array of 7 week day names (first index = 0) 82 * @param string (optional) format of returned days (one,two,short or long) 113 * 114 * @param string $format (optional) format of returned days (one,two,short or long) 115 * 83 116 * @return array 84 117 * @access public 85 118 * @static 86 119 */ 87 function weekdayNames($format='long') 88 { 89 $formats = array('one'=>'%a', 'two'=>'%a', 'short'=>'%a', 'long'=>'%A'); 90 if (!array_key_exists($format,$formats)) { 120 function weekdayNames($format = 'long') 121 { 122 $formats = array( 123 'one' => '%a', 124 'two' => '%a', 125 'short' => '%a', 126 'long' => '%A', 127 ); 128 if (!array_key_exists($format, $formats)) { 91 129 $format = 'long'; 92 130 } … … 96 134 $day = strftime($formats[$format], $stamp); 97 135 switch($format) { 98 case 'one':99 $day = substr($day, 0, 1);136 case 'one': 137 $day = substr($day, 0, 1); 100 138 break; 101 case 'two':102 $day = substr($day, 0, 2);139 case 'two': 140 $day = substr($day, 0, 2); 103 141 break; 104 142 } … … 110 148 /** 111 149 * Returns textual representation of the previous month of the decorated calendar object 112 * @param object subclass of Calendar e.g. Calendar_Month 113 * @param string (optional) format of returned months (one,two,short or long) 114 * @return string 115 * @access public 116 * @static 117 */ 118 function prevMonthName($Calendar, $format='long') 150 * 151 * @param object $Calendar subclass of Calendar e.g. Calendar_Month 152 * @param string $format (optional) format of returned months (one,two,short or long) 153 * 154 * @return string 155 * @access public 156 * @static 157 */ 158 function prevMonthName($Calendar, $format = 'long') 119 159 { 120 160 $months = Calendar_Util_Textual::monthNames($format); … … 124 164 /** 125 165 * Returns textual representation of the month of the decorated calendar object 126 * @param object subclass of Calendar e.g. Calendar_Month 127 * @param string (optional) format of returned months (one,two,short or long) 128 * @return string 129 * @access public 130 * @static 131 */ 132 function thisMonthName($Calendar, $format='long') 166 * 167 * @param object $Calendar subclass of Calendar e.g. Calendar_Month 168 * @param string $format (optional) format of returned months (one,two,short or long) 169 * 170 * @return string 171 * @access public 172 * @static 173 */ 174 function thisMonthName($Calendar, $format = 'long') 133 175 { 134 176 $months = Calendar_Util_Textual::monthNames($format); … … 138 180 /** 139 181 * Returns textual representation of the next month of the decorated calendar object 140 * @param object subclass of Calendar e.g. Calendar_Month 141 * @param string (optional) format of returned months (one,two,short or long) 142 * @return string 143 * @access public 144 * @static 145 */ 146 function nextMonthName($Calendar, $format='long') 182 * 183 * @param object $Calendar subclass of Calendar e.g. Calendar_Month 184 * @param string $format (optional) format of returned months (one,two,short or long) 185 * 186 * @return string 187 * @access public 188 * @static 189 */ 190 function nextMonthName($Calendar, $format = 'long') 147 191 { 148 192 $months = Calendar_Util_Textual::monthNames($format); … … 153 197 * Returns textual representation of the previous day of week of the decorated calendar object 154 198 * <b>Note:</b> Requires PEAR::Date 155 * @param object subclass of Calendar e.g. Calendar_Month 156 * @param string (optional) format of returned months (one,two,short or long) 157 * @return string 158 * @access public 159 * @static 160 */ 161 function prevDayName($Calendar, $format='long') 199 * 200 * @param object $Calendar subclass of Calendar e.g. Calendar_Month 201 * @param string $format (optional) format of returned months (one,two,short or long) 202 * 203 * @return string 204 * @access public 205 * @static 206 */ 207 function prevDayName($Calendar, $format = 'long') 162 208 { 163 209 $days = Calendar_Util_Textual::weekdayNames($format); 164 210 $stamp = $Calendar->prevDay('timestamp'); 165 211 $cE = $Calendar->getEngine(); 166 require_once 'Date/Calc.php';212 include_once 'Date/Calc.php'; 167 213 $day = Date_Calc::dayOfWeek($cE->stampToDay($stamp), 168 214 $cE->stampToMonth($stamp), $cE->stampToYear($stamp)); … … 173 219 * Returns textual representation of the day of week of the decorated calendar object 174 220 * <b>Note:</b> Requires PEAR::Date 175 * @param object subclass of Calendar e.g. Calendar_Month 176 * @param string (optional) format of returned months (one,two,short or long) 221 * 222 * @param object $Calendar subclass of Calendar e.g. Calendar_Month 223 * @param string $format (optional) format of returned months (one,two,short or long) 224 * 177 225 * @return string 178 226 * @access public … … 182 230 { 183 231 $days = Calendar_Util_Textual::weekdayNames($format); 184 require_once 'Date/Calc.php';232 include_once 'Date/Calc.php'; 185 233 $day = Date_Calc::dayOfWeek($Calendar->thisDay(), $Calendar->thisMonth(), $Calendar->thisYear()); 186 234 return $days[$day]; … … 189 237 /** 190 238 * Returns textual representation of the next day of week of the decorated calendar object 191 * @param object subclass of Calendar e.g. Calendar_Month 192 * @param string (optional) format of returned months (one,two,short or long) 239 * 240 * @param object $Calendar subclass of Calendar e.g. Calendar_Month 241 * @param string $format (optional) format of returned months (one,two,short or long) 242 * 193 243 * @return string 194 244 * @access public … … 200 250 $stamp = $Calendar->nextDay('timestamp'); 201 251 $cE = $Calendar->getEngine(); 202 require_once 'Date/Calc.php';252 include_once 'Date/Calc.php'; 203 253 $day = Date_Calc::dayOfWeek($cE->stampToDay($stamp), 204 254 $cE->stampToMonth($stamp), $cE->stampToYear($stamp)); … … 210 260 * calendar object. Only useful for Calendar_Month_Weekdays, Calendar_Month_Weeks 211 261 * and Calendar_Week. Otherwise the returned array will begin on Sunday 212 * @param object subclass of Calendar e.g. Calendar_Month 213 * @param string (optional) format of returned months (one,two,short or long) 262 * 263 * @param object $Calendar subclass of Calendar e.g. Calendar_Month 264 * @param string $format (optional) format of returned months (one,two,short or long) 265 * 214 266 * @return array ordered array of week day names 215 267 * @access public 216 268 * @static 217 269 */ 218 function orderedWeekdays($Calendar, $format ='long')270 function orderedWeekdays($Calendar, $format = 'long') 219 271 { 220 272 $days = Calendar_Util_Textual::weekdayNames($format); 221 273 222 // Not so good - need methods to access this information perhaps...223 274 if (isset($Calendar->tableHelper)) { 224 $ordereddays = $Calendar->tableHelper-> daysOfWeek;275 $ordereddays = $Calendar->tableHelper->getDaysOfWeek(); 225 276 } else { 226 $ordereddays = array(0, 1, 2, 3, 4, 5, 6); 277 //default: start from Sunday 278 $firstDay = 0; 279 //check if defined / set 280 if (defined('CALENDAR_FIRST_DAY_OF_WEEK')) { 281 $firstDay = CALENDAR_FIRST_DAY_OF_WEEK; 282 } elseif(isset($Calendar->firstDay)) { 283 $firstDay = $Calendar->firstDay; 284 } 285 $ordereddays = array(); 286 for ($i = $firstDay; $i < 7; $i++) { 287 $ordereddays[] = $i; 288 } 289 for ($i = 0; $i < $firstDay; $i++) { 290 $ordereddays[] = $i; 291 } 227 292 } 228 293
Note: See TracChangeset
for help on using the changeset viewer.
