Ignore:
Timestamp:
2013/08/26 15:52:37 (11 years ago)
Author:
m_uehara
Message:

#2348 r23116 - r23125 をマージ

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/version-2_13_0/data/module/Calendar/Engine/PearDate.php

    r20119 r23126  
    11<?php 
    22/* 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 
    224/** 
    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 
    2537 */ 
     38 
    2639/** 
    2740 * Load PEAR::Date class 
     
    3245 * Performs calendar calculations based on the PEAR::Date class 
    3346 * 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 
    3554 * @access protected 
    3655 */ 
     
    4160     * Uses a static variable to prevent date() being used twice 
    4261     * 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     * 
    4465     * @return object Pear::Date object 
    4566     * @access protected 
     
    5677    /** 
    5778     * 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     * 
    5982     * @return int year (e.g. 2003) 
    6083     * @access protected 
     
    6891    /** 
    6992     * 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     * 
    7196     * @return int month (e.g. 9) 
    7297     * @access protected 
     
    80105    /** 
    81106     * 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     * 
    83110     * @return int day (e.g. 15) 
    84111     * @access protected 
     
    92119    /** 
    93120     * 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     * 
    95124     * @return int hour (e.g. 13) 
    96125     * @access protected 
     
    104133    /** 
    105134     * 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     * 
    107138     * @return int minute (e.g. 34) 
    108139     * @access protected 
     
    116147    /** 
    117148     * 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     * 
    119152     * @return int second (e.g. 51) 
    120153     * @access protected 
     
    128161    /** 
    129162     * 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     * 
    136171     * @return string iso-8601 datetime 
    137172     * @access protected 
     
    151186    /** 
    152187     * 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 
    159197     * @access protected 
    160198     */ 
     
    210248    /** 
    211249     * The upper limit on years that the Calendar Engine can work with 
     250     * 
    212251     * @return int 9999 
    213252     * @access protected 
     
    220259    /** 
    221260     * The lower limit on years that the Calendar Engine can work with 
     261     * 
    222262     * @return int 0 
    223263     * @access protected 
     
    230270    /** 
    231271     * Returns the number of months in a year 
     272     * 
     273     * @param int $y year 
     274     * 
    232275     * @return int (12) 
    233276     * @access protected 
     
    240283    /** 
    241284     * 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     * 
    244289     * @return int days in month 
    245290     * @access protected 
     
    253298     * Returns numeric representation of the day of the week in a month, 
    254299     * 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     * 
    257304     * @return int from 0 to 7 
    258305     * @access protected 
     
    265312    /** 
    266313     * 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     * 
    270319     * @return int (7) 
    271320     * @access protected 
    272321     */ 
    273     function getDaysInWeek($y=NULL, $m=NULL, $d=NULL) 
     322    function getDaysInWeek($y=null, $m=null, $d=null) 
    274323    { 
    275324        return 7; 
     
    278327    /** 
    279328     * 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     * 
    283334     * @return int week number 
    284335     * @access protected 
     
    286337    function getWeekNInYear($y, $m, $d) 
    287338    { 
    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; 
    289342    } 
    290343 
    291344    /** 
    292345     * 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     * 
    297352     * @return int week number 
    298353     * @access protected 
     
    312367    /** 
    313368     * 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     * 
    317374     * @return int weeks number 
    318375     * @access protected 
     
    338395    /** 
    339396     * 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     * 
    343402     * @return int weekday number 
    344403     * @access protected 
     
    351410    /** 
    352411     * 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     * 
    356417     * @return array (0, 1, 2, 3, 4, 5, 6) 1 = Monday 
    357418     * @access protected 
    358419     */ 
    359     function getWeekDays($y=NULL, $m=NULL, $d=NULL) 
     420    function getWeekDays($y=null, $m=null, $d=null) 
    360421    { 
    361422        return array(0, 1, 2, 3, 4, 5, 6); 
     
    364425    /** 
    365426     * 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     * 
    369432     * @return int (default 1 = Monday) 
    370433     * @access protected 
    371434     */ 
    372     function getFirstDayOfWeek($y=NULL, $m=NULL, $d=NULL) 
     435    function getFirstDayOfWeek($y=null, $m=null, $d=null) 
    373436    { 
    374437        return 1; 
     
    377440    /** 
    378441     * 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     * 
    379447     * @return int (24) 
    380448     * @access protected 
     
    387455    /** 
    388456     * 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     * 
    389463     * @return int (60) 
    390464     * @access protected 
     
    397471    /** 
    398472     * 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     * 
    399480     * @return int (60) 
    400481     * @access protected 
     
    403484    { 
    404485        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        ); 
    405507    } 
    406508} 
Note: See TracChangeset for help on using the changeset viewer.