- Timestamp:
- 2013/08/26 12:42:34 (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/version-2_13-dev/data/module/Calendar/Engine/PearDate.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 // | 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 // 3 22 4 /** 23 * @package Calendar 24 * @version $Id: PearDate.php,v 1.8 2004/08/20 20:00:55 quipo Exp $ 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 25 37 */ 38 26 39 /** 27 40 * Load PEAR::Date class … … 32 45 * Performs calendar calculations based on the PEAR::Date class 33 46 * Timestamps are in the ISO-8601 format (YYYY-MM-DD HH:MM:SS) 34 * @package Calendar 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 35 54 * @access protected 36 55 */ … … 41 60 * Uses a static variable to prevent date() being used twice 42 61 * for a date which is already known 43 * @param mixed Any timestamp format recognized by Pear::Date 62 * 63 * @param mixed $stamp Any timestamp format recognized by Pear::Date 64 * 44 65 * @return object Pear::Date object 45 66 * @access protected … … 56 77 /** 57 78 * Returns a numeric year given a iso-8601 datetime 58 * @param string iso-8601 datetime (YYYY-MM-DD HH:MM:SS) 79 * 80 * @param string $stamp iso-8601 datetime (YYYY-MM-DD HH:MM:SS) 81 * 59 82 * @return int year (e.g. 2003) 60 83 * @access protected … … 68 91 /** 69 92 * Returns a numeric month given a iso-8601 datetime 70 * @param string iso-8601 datetime (YYYY-MM-DD HH:MM:SS) 93 * 94 * @param string $stamp iso-8601 datetime (YYYY-MM-DD HH:MM:SS) 95 * 71 96 * @return int month (e.g. 9) 72 97 * @access protected … … 80 105 /** 81 106 * Returns a numeric day given a iso-8601 datetime 82 * @param string iso-8601 datetime (YYYY-MM-DD HH:MM:SS) 107 * 108 * @param string $stamp iso-8601 datetime (YYYY-MM-DD HH:MM:SS) 109 * 83 110 * @return int day (e.g. 15) 84 111 * @access protected … … 92 119 /** 93 120 * Returns a numeric hour given a iso-8601 datetime 94 * @param string iso-8601 datetime (YYYY-MM-DD HH:MM:SS) 121 * 122 * @param string $stamp iso-8601 datetime (YYYY-MM-DD HH:MM:SS) 123 * 95 124 * @return int hour (e.g. 13) 96 125 * @access protected … … 104 133 /** 105 134 * Returns a numeric minute given a iso-8601 datetime 106 * @param string iso-8601 datetime (YYYY-MM-DD HH:MM:SS) 135 * 136 * @param string $stamp iso-8601 datetime (YYYY-MM-DD HH:MM:SS) 137 * 107 138 * @return int minute (e.g. 34) 108 139 * @access protected … … 116 147 /** 117 148 * Returns a numeric second given a iso-8601 datetime 118 * @param string iso-8601 datetime (YYYY-MM-DD HH:MM:SS) 149 * 150 * @param string $stamp iso-8601 datetime (YYYY-MM-DD HH:MM:SS) 151 * 119 152 * @return int second (e.g. 51) 120 153 * @access protected … … 128 161 /** 129 162 * Returns a iso-8601 datetime 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) 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 * 136 171 * @return string iso-8601 datetime 137 172 * @access protected … … 151 186 /** 152 187 * Set the correct date values (useful for math operations on dates) 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) 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 159 197 * @access protected 160 198 */ … … 210 248 /** 211 249 * The upper limit on years that the Calendar Engine can work with 250 * 212 251 * @return int 9999 213 252 * @access protected … … 220 259 /** 221 260 * The lower limit on years that the Calendar Engine can work with 261 * 222 262 * @return int 0 223 263 * @access protected … … 230 270 /** 231 271 * Returns the number of months in a year 272 * 273 * @param int $y year 274 * 232 275 * @return int (12) 233 276 * @access protected … … 240 283 /** 241 284 * Returns the number of days in a month, given year and month 242 * @param int year (2003) 243 * @param int month (9) 285 * 286 * @param int $y year (2003) 287 * @param int $m month (9) 288 * 244 289 * @return int days in month 245 290 * @access protected … … 253 298 * Returns numeric representation of the day of the week in a month, 254 299 * given year and month 255 * @param int year (2003) 256 * @param int month (9) 300 * 301 * @param int $y year (2003) 302 * @param int $m month (9) 303 * 257 304 * @return int from 0 to 7 258 305 * @access protected … … 265 312 /** 266 313 * Returns the number of days in a week 267 * @param int year (2003) 268 * @param int month (9) 269 * @param int day (4) 314 * 315 * @param int $y year (2003) 316 * @param int $m month (9) 317 * @param int $d day (4) 318 * 270 319 * @return int (7) 271 320 * @access protected 272 321 */ 273 function getDaysInWeek($y= NULL, $m=NULL, $d=NULL)322 function getDaysInWeek($y=null, $m=null, $d=null) 274 323 { 275 324 return 7; … … 278 327 /** 279 328 * Returns the number of the week in the year (ISO-8601), given a date 280 * @param int year (2003) 281 * @param int month (9) 282 * @param int day (4) 329 * 330 * @param int $y year (2003) 331 * @param int $m month (9) 332 * @param int $d day (4) 333 * 283 334 * @return int week number 284 335 * @access protected … … 286 337 function getWeekNInYear($y, $m, $d) 287 338 { 288 return Date_Calc::weekOfYear($d, $m, $y); //beware, Date_Calc doesn't follow ISO-8601 standard! 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; 289 342 } 290 343 291 344 /** 292 345 * Returns the number of the week in the month, given a date 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) 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 * 297 352 * @return int week number 298 353 * @access protected … … 312 367 /** 313 368 * Returns the number of weeks in the month 314 * @param int year (2003) 315 * @param int month (9) 316 * @param int first day of the week (default: monday) 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 * 317 374 * @return int weeks number 318 375 * @access protected … … 338 395 /** 339 396 * Returns the number of the day of the week (0=sunday, 1=monday...) 340 * @param int year (2003) 341 * @param int month (9) 342 * @param int day (4) 397 * 398 * @param int $y year (2003) 399 * @param int $m month (9) 400 * @param int $d day (4) 401 * 343 402 * @return int weekday number 344 403 * @access protected … … 351 410 /** 352 411 * Returns a list of integer days of the week beginning 0 353 * @param int year (2003) 354 * @param int month (9) 355 * @param int day (4) 412 * 413 * @param int $y year (2003) 414 * @param int $m month (9) 415 * @param int $d day (4) 416 * 356 417 * @return array (0, 1, 2, 3, 4, 5, 6) 1 = Monday 357 418 * @access protected 358 419 */ 359 function getWeekDays($y= NULL, $m=NULL, $d=NULL)420 function getWeekDays($y=null, $m=null, $d=null) 360 421 { 361 422 return array(0, 1, 2, 3, 4, 5, 6); … … 364 425 /** 365 426 * Returns the default first day of the week 366 * @param int year (2003) 367 * @param int month (9) 368 * @param int day (4) 427 * 428 * @param int $y year (2003) 429 * @param int $m month (9) 430 * @param int $d day (4) 431 * 369 432 * @return int (default 1 = Monday) 370 433 * @access protected 371 434 */ 372 function getFirstDayOfWeek($y= NULL, $m=NULL, $d=NULL)435 function getFirstDayOfWeek($y=null, $m=null, $d=null) 373 436 { 374 437 return 1; … … 377 440 /** 378 441 * 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 * 379 447 * @return int (24) 380 448 * @access protected … … 387 455 /** 388 456 * 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 hour 462 * 389 463 * @return int (60) 390 464 * @access protected … … 397 471 /** 398 472 * 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 hour 478 * @param int $i minute 479 * 399 480 * @return int (60) 400 481 * @access protected … … 403 484 { 404 485 return 60; 486 } 487 488 /** 489 * Checks if the given day is the current day 490 * 491 * @param mixed $stamp Any timestamp format recognized by Pear::Date 492 * 493 * @return boolean 494 * @access protected 495 */ 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 ); 405 507 } 406 508 }
Note: See TracChangeset
for help on using the changeset viewer.