Ignore:
Timestamp:
2013/08/28 13:55:43 (7 years ago)
Author:
m_uehara
Message:

#2348 r23140 をマージ

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/version-2_13_0/data/module/Calendar/Util/Textual.php

    r23126 r23143  
    11<?php 
    22/* 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// 
    4023/** 
    4124 * @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 $ 
    4326 */ 
    4427 
     
    5942 * Static utlities to help with fetching textual representations of months and 
    6043 * 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 
    7046 */ 
    7147class Calendar_Util_Textual 
     
    7450    /** 
    7551     * 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) 
    7953     * @return array 
    8054     * @access public 
    8155     * @static 
    8256     */ 
    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)) { 
    9261            $format = 'long'; 
    9362        } 
     
    9766            $month = strftime($formats[$format], $stamp); 
    9867            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); 
    10473                break; 
    10574            } 
     
    11180    /** 
    11281     * 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) 
    11683     * @return array 
    11784     * @access public 
    11885     * @static 
    11986     */ 
    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)) { 
    12991            $format = 'long'; 
    13092        } 
     
    13496            $day = strftime($formats[$format], $stamp); 
    13597            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); 
    141103                break; 
    142104            } 
     
    148110    /** 
    149111     * 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') 
    159119    { 
    160120        $months = Calendar_Util_Textual::monthNames($format); 
     
    164124    /** 
    165125     * 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') 
    175133    { 
    176134        $months = Calendar_Util_Textual::monthNames($format); 
     
    180138    /** 
    181139     * 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') 
    191147    { 
    192148        $months = Calendar_Util_Textual::monthNames($format); 
     
    197153     * Returns textual representation of the previous day of week of the decorated calendar object 
    198154     * <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') 
    208162    { 
    209163        $days = Calendar_Util_Textual::weekdayNames($format); 
    210164        $stamp = $Calendar->prevDay('timestamp'); 
    211165        $cE = $Calendar->getEngine(); 
    212         include_once 'Date/Calc.php'; 
     166        require_once 'Date/Calc.php'; 
    213167        $day = Date_Calc::dayOfWeek($cE->stampToDay($stamp), 
    214168            $cE->stampToMonth($stamp), $cE->stampToYear($stamp)); 
     
    219173     * Returns textual representation of the day of week of the decorated calendar object 
    220174     * <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) 
    225177     * @return string 
    226178     * @access public 
     
    230182    { 
    231183        $days = Calendar_Util_Textual::weekdayNames($format); 
    232         include_once 'Date/Calc.php'; 
     184        require_once 'Date/Calc.php'; 
    233185        $day = Date_Calc::dayOfWeek($Calendar->thisDay(), $Calendar->thisMonth(), $Calendar->thisYear()); 
    234186        return $days[$day]; 
     
    237189    /** 
    238190     * 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) 
    243193     * @return string 
    244194     * @access public 
     
    250200        $stamp = $Calendar->nextDay('timestamp'); 
    251201        $cE = $Calendar->getEngine(); 
    252         include_once 'Date/Calc.php'; 
     202        require_once 'Date/Calc.php'; 
    253203        $day = Date_Calc::dayOfWeek($cE->stampToDay($stamp), 
    254204            $cE->stampToMonth($stamp), $cE->stampToYear($stamp)); 
     
    260210     * calendar object. Only useful for Calendar_Month_Weekdays, Calendar_Month_Weeks 
    261211     * 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) 
    266214     * @return array ordered array of week day names 
    267215     * @access public 
    268216     * @static 
    269217     */ 
    270     function orderedWeekdays($Calendar, $format = 'long') 
     218    function orderedWeekdays($Calendar, $format='long') 
    271219    { 
    272220        $days = Calendar_Util_Textual::weekdayNames($format); 
    273221         
     222        // Not so good - need methods to access this information perhaps... 
    274223        if (isset($Calendar->tableHelper)) { 
    275             $ordereddays = $Calendar->tableHelper->getDaysOfWeek(); 
     224            $ordereddays = $Calendar->tableHelper->daysOfWeek; 
    276225        } 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); 
    292227        } 
    293228         
Note: See TracChangeset for help on using the changeset viewer.