Show
Ignore:
Timestamp:
07/22/2008 12:39:15 AM (4 months ago)
Author:
Shadowhand
Message:

Follow up to r3185, week_start fixes

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • trunk/system/libraries/Calendar.php

    r3185 r3186  
    1212class Calendar_Core extends Event_Subject { 
    1313 
     14        // Start the calendar on Sunday by default 
     15        public static $start_monday = FALSE; 
     16 
    1417        // Month and year to use for calendaring 
    1518        protected $month; 
    1619        protected $year; 
    1720 
    18         // Start the calendar on Sunday by default 
    19         public $week_start = 0; 
     21        // Week starts on Sunday 
     22        protected $week_start = 0; 
    2023 
    2124        // Observed data 
     
    3437 
    3538                // Days of the week 
    36                 $headings = array('Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'); 
     39                $days = array('Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'); 
     40 
     41                if (Calendar::$start_monday === TRUE) 
     42                { 
     43                        // Push Sunday to the end of the days 
     44                        array_push($days, array_shift($days)); 
     45                } 
    3746 
    3847                if (strpos(Kohana::config('locale.language.0'), 'en') !== 0) 
    3948                { 
    4049                        // This is a bit awkward, but it works properly and is reliable 
    41                         foreach ($headings as $i => $day) 
     50                        foreach ($days as $i => $day) 
    4251                        { 
    4352                                // Convert the English names to i18n names 
    44                                 $headings[$i] = strftime($format, strtotime($day)); 
     53                                $days[$i] = strftime($format, strtotime($day)); 
    4554                        } 
    4655                } 
    4756                elseif ($short == TRUE) 
    4857                { 
    49                         foreach ($headings as $i => $day) 
     58                        foreach ($days as $i => $day) 
    5059                        { 
    5160                                // Shorten the day names to 3 letters 
    52                                 $headings[$i] = substr($day, 0, 3); 
    53                         } 
    54                 } 
    55  
    56                 return $headings; 
     61                                $days[$i] = substr($day, 0, 3); 
     62                        } 
     63                } 
     64 
     65                return $days; 
    5766        } 
    5867 
     
    6372         * @param   integer  month number 
    6473         * @param   integer  year number 
    65          * @param   boolean  start weeks on monday 
    6674         * @return  object 
    6775         */ 
    68         public static function factory($month = NULL, $year = NULL, $start_monday = NULL) 
    69         { 
    70                 return new Calendar($month, $year, $start_monday); 
     76        public static function factory($month = NULL, $year = NULL) 
     77        { 
     78                return new Calendar($month, $year); 
    7179        } 
    7280 
     
    7785         * @param   integer  month number 
    7886         * @param   integer  year number 
    79          * @param   boolean  start weeks on monday 
    8087         * @return  void 
    8188         */ 
    82         public function __construct($month = NULL, $year = NULL, $start_monday = NULL) 
     89        public function __construct($month = NULL, $year = NULL) 
    8390        { 
    8491                empty($month) and $month = date('n'); // Current month 
     
    8996                $this->year  = (int) $year; 
    9097 
    91                 if ($start_monday === TRUE) 
    92                 { 
    93                         // Some locales start the week on Monday, not Sunday. 
     98                if (Calendar::$start_monday === TRUE) 
     99                { 
     100                        // Week starts on Monday 
    94101                        $this->week_start = 1; 
    95102                }