- Timestamp:
- 2013/08/28 13:55:43 (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/version-2_13_0/data/module/Calendar/Util/Textual.php
r23126 r23143 1 1 <?php 2 2 /* vim: set expandtab tabstop=4 shiftwidth=4: */ 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 <hfuecks@phppatterns.com> 33 * @author Lorenzo Alberton <l.alberton@quipo.it> 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 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 // | license@php.net so we can mail you a copy immediately. | 16 // +----------------------------------------------------------------------+ 17 // | Authors: Harry Fuecks <hfuecks@phppatterns.com> | 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 // 40 23 /** 41 24 * @package Calendar 42 * @version $Id: Textual.php 247250 2007-11-28 19:42:01Z quipo$25 * @version $Id: Textual.php,v 1.2 2004/08/16 13:13:09 hfuecks Exp $ 43 26 */ 44 27 … … 59 42 * Static utlities to help with fetching textual representations of months and 60 43 * days of the week. 61 * 62 * @category Date and Time 63 * @package Calendar 64 * @author Harry Fuecks <hfuecks@phppatterns.com> 65 * @author Lorenzo Alberton <l.alberton@quipo.it> 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 44 * @package Calendar 45 * @access public 70 46 */ 71 47 class Calendar_Util_Textual … … 74 50 /** 75 51 * Returns an array of 12 month names (first index = 1) 76 * 77 * @param string $format (optional) format of returned months (one|two|short|long) 78 * 52 * @param string (optional) format of returned months (one,two,short or long) 79 53 * @return array 80 54 * @access public 81 55 * @static 82 56 */ 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)) { 57 function monthNames($format='long') 58 { 59 $formats = array('one'=>'%b', 'two'=>'%b', 'short'=>'%b', 'long'=>'%B'); 60 if (!array_key_exists($format,$formats)) { 92 61 $format = 'long'; 93 62 } … … 97 66 $month = strftime($formats[$format], $stamp); 98 67 switch($format) { 99 case 'one':100 $month = substr($month, 0, 1);101 break; 102 case 'two':103 $month = substr($month, 0, 2);68 case 'one': 69 $month = substr($month, 0, 1); 70 break; 71 case 'two': 72 $month = substr($month, 0, 2); 104 73 break; 105 74 } … … 111 80 /** 112 81 * Returns an array of 7 week day names (first index = 0) 113 * 114 * @param string $format (optional) format of returned days (one,two,short or long) 115 * 82 * @param string (optional) format of returned days (one,two,short or long) 116 83 * @return array 117 84 * @access public 118 85 * @static 119 86 */ 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)) { 87 function weekdayNames($format='long') 88 { 89 $formats = array('one'=>'%a', 'two'=>'%a', 'short'=>'%a', 'long'=>'%A'); 90 if (!array_key_exists($format,$formats)) { 129 91 $format = 'long'; 130 92 } … … 134 96 $day = strftime($formats[$format], $stamp); 135 97 switch($format) { 136 case 'one':137 $day = substr($day, 0, 1);138 break; 139 case 'two':140 $day = substr($day, 0, 2);98 case 'one': 99 $day = substr($day, 0, 1); 100 break; 101 case 'two': 102 $day = substr($day, 0, 2); 141 103 break; 142 104 } … … 148 110 /** 149 111 * Returns textual representation of the previous month of the decorated calendar object 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') 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') 159 119 { 160 120 $months = Calendar_Util_Textual::monthNames($format); … … 164 124 /** 165 125 * Returns textual representation of the month of the decorated calendar object 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') 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') 175 133 { 176 134 $months = Calendar_Util_Textual::monthNames($format); … … 180 138 /** 181 139 * Returns textual representation of the next month of the decorated calendar object 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') 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') 191 147 { 192 148 $months = Calendar_Util_Textual::monthNames($format); … … 197 153 * Returns textual representation of the previous day of week of the decorated calendar object 198 154 * <b>Note:</b> Requires PEAR::Date 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') 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') 208 162 { 209 163 $days = Calendar_Util_Textual::weekdayNames($format); 210 164 $stamp = $Calendar->prevDay('timestamp'); 211 165 $cE = $Calendar->getEngine(); 212 include_once 'Date/Calc.php';166 require_once 'Date/Calc.php'; 213 167 $day = Date_Calc::dayOfWeek($cE->stampToDay($stamp), 214 168 $cE->stampToMonth($stamp), $cE->stampToYear($stamp)); … … 219 173 * Returns textual representation of the day of week of the decorated calendar object 220 174 * <b>Note:</b> Requires PEAR::Date 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 * 175 * @param object subclass of Calendar e.g. Calendar_Month 176 * @param string (optional) format of returned months (one,two,short or long) 225 177 * @return string 226 178 * @access public … … 230 182 { 231 183 $days = Calendar_Util_Textual::weekdayNames($format); 232 include_once 'Date/Calc.php';184 require_once 'Date/Calc.php'; 233 185 $day = Date_Calc::dayOfWeek($Calendar->thisDay(), $Calendar->thisMonth(), $Calendar->thisYear()); 234 186 return $days[$day]; … … 237 189 /** 238 190 * Returns textual representation of the next day of week of the decorated calendar object 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 * 191 * @param object subclass of Calendar e.g. Calendar_Month 192 * @param string (optional) format of returned months (one,two,short or long) 243 193 * @return string 244 194 * @access public … … 250 200 $stamp = $Calendar->nextDay('timestamp'); 251 201 $cE = $Calendar->getEngine(); 252 include_once 'Date/Calc.php';202 require_once 'Date/Calc.php'; 253 203 $day = Date_Calc::dayOfWeek($cE->stampToDay($stamp), 254 204 $cE->stampToMonth($stamp), $cE->stampToYear($stamp)); … … 260 210 * calendar object. Only useful for Calendar_Month_Weekdays, Calendar_Month_Weeks 261 211 * and Calendar_Week. Otherwise the returned array will begin on Sunday 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 * 212 * @param object subclass of Calendar e.g. Calendar_Month 213 * @param string (optional) format of returned months (one,two,short or long) 266 214 * @return array ordered array of week day names 267 215 * @access public 268 216 * @static 269 217 */ 270 function orderedWeekdays($Calendar, $format ='long')218 function orderedWeekdays($Calendar, $format='long') 271 219 { 272 220 $days = Calendar_Util_Textual::weekdayNames($format); 273 221 222 // Not so good - need methods to access this information perhaps... 274 223 if (isset($Calendar->tableHelper)) { 275 $ordereddays = $Calendar->tableHelper-> getDaysOfWeek();224 $ordereddays = $Calendar->tableHelper->daysOfWeek; 276 225 } else { 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 } 226 $ordereddays = array(0, 1, 2, 3, 4, 5, 6); 292 227 } 293 228
Note: See TracChangeset
for help on using the changeset viewer.