- 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/Engine/PearDate.php
r23126 r23143 1 1 <?php 2 2 /* vim: set expandtab tabstop=4 shiftwidth=4: */ 3 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: Lorenzo Alberton <l dot alberton at quipo dot it> | 18 // +----------------------------------------------------------------------+ 19 // 20 // $Id: PearDate.php,v 1.8 2004/08/20 20:00:55 quipo Exp $ 21 // 4 22 /** 5 * Contains the Calendar_Engine_PearDate 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 Lorenzo Alberton <l.alberton@quipo.it> 33 * @copyright 2003-2007 Lorenzo Alberton 34 * @license http://www.debian.org/misc/bsd.license BSD License (3 Clause) 35 * @version CVS: $Id: PearDate.php 269076 2008-11-15 21:41:38Z quipo $ 36 * @link http://pear.php.net/package/Calendar 23 * @package Calendar 24 * @version $Id: PearDate.php,v 1.8 2004/08/20 20:00:55 quipo Exp $ 37 25 */ 38 39 26 /** 40 27 * Load PEAR::Date class … … 45 32 * Performs calendar calculations based on the PEAR::Date class 46 33 * Timestamps are in the ISO-8601 format (YYYY-MM-DD HH:MM:SS) 47 * 48 * @category Date and Time 49 * @package Calendar 50 * @author Lorenzo Alberton <l.alberton@quipo.it> 51 * @copyright 2003-2007 Lorenzo Alberton 52 * @license http://www.debian.org/misc/bsd.license BSD License (3 Clause) 53 * @link http://pear.php.net/package/Calendar 34 * @package Calendar 54 35 * @access protected 55 36 */ … … 60 41 * Uses a static variable to prevent date() being used twice 61 42 * for a date which is already known 62 * 63 * @param mixed $stamp Any timestamp format recognized by Pear::Date 64 * 43 * @param mixed Any timestamp format recognized by Pear::Date 65 44 * @return object Pear::Date object 66 45 * @access protected … … 77 56 /** 78 57 * Returns a numeric year given a iso-8601 datetime 79 * 80 * @param string $stamp iso-8601 datetime (YYYY-MM-DD HH:MM:SS) 81 * 58 * @param string iso-8601 datetime (YYYY-MM-DD HH:MM:SS) 82 59 * @return int year (e.g. 2003) 83 60 * @access protected … … 91 68 /** 92 69 * Returns a numeric month given a iso-8601 datetime 93 * 94 * @param string $stamp iso-8601 datetime (YYYY-MM-DD HH:MM:SS) 95 * 70 * @param string iso-8601 datetime (YYYY-MM-DD HH:MM:SS) 96 71 * @return int month (e.g. 9) 97 72 * @access protected … … 105 80 /** 106 81 * Returns a numeric day given a iso-8601 datetime 107 * 108 * @param string $stamp iso-8601 datetime (YYYY-MM-DD HH:MM:SS) 109 * 82 * @param string iso-8601 datetime (YYYY-MM-DD HH:MM:SS) 110 83 * @return int day (e.g. 15) 111 84 * @access protected … … 119 92 /** 120 93 * Returns a numeric hour given a iso-8601 datetime 121 * 122 * @param string $stamp iso-8601 datetime (YYYY-MM-DD HH:MM:SS) 123 * 94 * @param string iso-8601 datetime (YYYY-MM-DD HH:MM:SS) 124 95 * @return int hour (e.g. 13) 125 96 * @access protected … … 133 104 /** 134 105 * Returns a numeric minute given a iso-8601 datetime 135 * 136 * @param string $stamp iso-8601 datetime (YYYY-MM-DD HH:MM:SS) 137 * 106 * @param string iso-8601 datetime (YYYY-MM-DD HH:MM:SS) 138 107 * @return int minute (e.g. 34) 139 108 * @access protected … … 147 116 /** 148 117 * Returns a numeric second given a iso-8601 datetime 149 * 150 * @param string $stamp iso-8601 datetime (YYYY-MM-DD HH:MM:SS) 151 * 118 * @param string iso-8601 datetime (YYYY-MM-DD HH:MM:SS) 152 119 * @return int second (e.g. 51) 153 120 * @access protected … … 161 128 /** 162 129 * Returns a iso-8601 datetime 163 * 164 * @param int $y year (2003) 165 * @param int $m month (9) 166 * @param int $d day (13) 167 * @param int $h hour (13) 168 * @param int $i minute (34) 169 * @param int $s second (53) 170 * 130 * @param int year (2003) 131 * @param int month (9) 132 * @param int day (13) 133 * @param int hour (13) 134 * @param int minute (34) 135 * @param int second (53) 171 136 * @return string iso-8601 datetime 172 137 * @access protected … … 186 151 /** 187 152 * Set the correct date values (useful for math operations on dates) 188 * 189 * @param int &$y year (2003) 190 * @param int &$m month (9) 191 * @param int &$d day (13) 192 * @param int &$h hour (13) 193 * @param int &$i minute (34) 194 * @param int &$s second (53) 195 * 196 * @return void 153 * @param int year (2003) 154 * @param int month (9) 155 * @param int day (13) 156 * @param int hour (13) 157 * @param int minute (34) 158 * @param int second (53) 197 159 * @access protected 198 160 */ … … 248 210 /** 249 211 * The upper limit on years that the Calendar Engine can work with 250 *251 212 * @return int 9999 252 213 * @access protected … … 259 220 /** 260 221 * The lower limit on years that the Calendar Engine can work with 261 *262 222 * @return int 0 263 223 * @access protected … … 270 230 /** 271 231 * Returns the number of months in a year 272 *273 * @param int $y year274 *275 232 * @return int (12) 276 233 * @access protected … … 283 240 /** 284 241 * Returns the number of days in a month, given year and month 285 * 286 * @param int $y year (2003) 287 * @param int $m month (9) 288 * 242 * @param int year (2003) 243 * @param int month (9) 289 244 * @return int days in month 290 245 * @access protected … … 298 253 * Returns numeric representation of the day of the week in a month, 299 254 * given year and month 300 * 301 * @param int $y year (2003) 302 * @param int $m month (9) 303 * 255 * @param int year (2003) 256 * @param int month (9) 304 257 * @return int from 0 to 7 305 258 * @access protected … … 312 265 /** 313 266 * Returns the number of days in a week 314 * 315 * @param int $y year (2003) 316 * @param int $m month (9) 317 * @param int $d day (4) 318 * 267 * @param int year (2003) 268 * @param int month (9) 269 * @param int day (4) 319 270 * @return int (7) 320 271 * @access protected 321 272 */ 322 function getDaysInWeek($y= null, $m=null, $d=null)273 function getDaysInWeek($y=NULL, $m=NULL, $d=NULL) 323 274 { 324 275 return 7; … … 327 278 /** 328 279 * Returns the number of the week in the year (ISO-8601), given a date 329 * 330 * @param int $y year (2003) 331 * @param int $m month (9) 332 * @param int $d day (4) 333 * 280 * @param int year (2003) 281 * @param int month (9) 282 * @param int day (4) 334 283 * @return int week number 335 284 * @access protected … … 337 286 function getWeekNInYear($y, $m, $d) 338 287 { 339 //return Date_Calc::weekOfYear($d, $m, $y); //beware, Date_Calc doesn't follow ISO-8601 standard! 340 list($nYear, $nWeek) = Date_Calc::weekOfYear4th($d, $m, $y); 341 return $nWeek; 288 return Date_Calc::weekOfYear($d, $m, $y); //beware, Date_Calc doesn't follow ISO-8601 standard! 342 289 } 343 290 344 291 /** 345 292 * Returns the number of the week in the month, given a date 346 * 347 * @param int $y year (2003) 348 * @param int $m month (9) 349 * @param int $d day (4) 350 * @param int $firstDay first day of the week (default: monday) 351 * 293 * @param int year (2003) 294 * @param int month (9) 295 * @param int day (4) 296 * @param int first day of the week (default: monday) 352 297 * @return int week number 353 298 * @access protected … … 367 312 /** 368 313 * Returns the number of weeks in the month 369 * 370 * @param int $y year (2003) 371 * @param int $m month (9) 372 * @param int $firstDay first day of the week (default: monday) 373 * 314 * @param int year (2003) 315 * @param int month (9) 316 * @param int first day of the week (default: monday) 374 317 * @return int weeks number 375 318 * @access protected … … 395 338 /** 396 339 * Returns the number of the day of the week (0=sunday, 1=monday...) 397 * 398 * @param int $y year (2003) 399 * @param int $m month (9) 400 * @param int $d day (4) 401 * 340 * @param int year (2003) 341 * @param int month (9) 342 * @param int day (4) 402 343 * @return int weekday number 403 344 * @access protected … … 410 351 /** 411 352 * Returns a list of integer days of the week beginning 0 412 * 413 * @param int $y year (2003) 414 * @param int $m month (9) 415 * @param int $d day (4) 416 * 353 * @param int year (2003) 354 * @param int month (9) 355 * @param int day (4) 417 356 * @return array (0, 1, 2, 3, 4, 5, 6) 1 = Monday 418 357 * @access protected 419 358 */ 420 function getWeekDays($y= null, $m=null, $d=null)359 function getWeekDays($y=NULL, $m=NULL, $d=NULL) 421 360 { 422 361 return array(0, 1, 2, 3, 4, 5, 6); … … 425 364 /** 426 365 * Returns the default first day of the week 427 * 428 * @param int $y year (2003) 429 * @param int $m month (9) 430 * @param int $d day (4) 431 * 366 * @param int year (2003) 367 * @param int month (9) 368 * @param int day (4) 432 369 * @return int (default 1 = Monday) 433 370 * @access protected 434 371 */ 435 function getFirstDayOfWeek($y= null, $m=null, $d=null)372 function getFirstDayOfWeek($y=NULL, $m=NULL, $d=NULL) 436 373 { 437 374 return 1; … … 440 377 /** 441 378 * Returns the number of hours in a day 442 *443 * @param int $y year (2003)444 * @param int $m month (9)445 * @param int $d day (4)446 *447 379 * @return int (24) 448 380 * @access protected … … 455 387 /** 456 388 * Returns the number of minutes in an hour 457 *458 * @param int $y year (2003)459 * @param int $m month (9)460 * @param int $d day (4)461 * @param int $h hour462 *463 389 * @return int (60) 464 390 * @access protected … … 471 397 /** 472 398 * Returns the number of seconds in a minutes 473 *474 * @param int $y year (2003)475 * @param int $m month (9)476 * @param int $d day (4)477 * @param int $h hour478 * @param int $i minute479 *480 399 * @return int (60) 481 400 * @access protected … … 484 403 { 485 404 return 60; 486 }487 488 /**489 * Checks if the given day is the current day490 *491 * @param mixed $stamp Any timestamp format recognized by Pear::Date492 *493 * @return boolean494 * @access protected495 */496 function isToday($stamp)497 {498 static $today = null;499 if (is_null($today)) {500 $today = new Date();501 }502 $date = Calendar_Engine_PearDate::stampCollection($stamp);503 return ( $date->day == $today->getDay()504 && $date->month == $today->getMonth()505 && $date->year == $today->getYear()506 );507 405 } 508 406 }
Note: See TracChangeset
for help on using the changeset viewer.