From d7dc9cfb04f0486a3423b9b3b1aaf3829343a1ab Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Mon, 30 Apr 2012 18:23:50 +0200 Subject: [PATCH] Fixed incorrect handling of months by strtotime --- root/portal/modules/portal_calendar.php | 28 +++++++++++++++++-------- 1 file changed, 19 insertions(+), 9 deletions(-) diff --git a/root/portal/modules/portal_calendar.php b/root/portal/modules/portal_calendar.php index f5d25218..f15d71e1 100644 --- a/root/portal/modules/portal_calendar.php +++ b/root/portal/modules/portal_calendar.php @@ -75,16 +75,16 @@ class portal_calendar_module } // get the calendar month - $mini_cal_month = 0; + $this->mini_cal_month = 0; if(isset($_GET['m' . $module_id]) || isset($_POST['m' . $module_id])) { - $mini_cal_month = request_var('m' . $module_id, 0); + $this->mini_cal_month = request_var('m' . $module_id, 0); } // initialise some variables $today_timestamp = time() + $user->timezone + $user->dst; $mini_cal_today = date('Ymd', time() + $user->timezone + $user->dst - date('Z')); - $s_cal_month = ($mini_cal_month != 0) ? $mini_cal_month . ' month' : $mini_cal_today; + $s_cal_month = ($this->mini_cal_month != 0) ? $this->mini_cal_month . ' month' : $mini_cal_today; $this->getMonth($s_cal_month); $mini_cal_count = $this->mini_cal_fdow; $mini_cal_this_year = $this->dateYYYY; @@ -93,10 +93,10 @@ class portal_calendar_module $mini_cal_month_days = $this->daysMonth; // output our general calendar bits - $down = $mini_cal_month - 1; - $up = $mini_cal_month + 1; - $prev_month = '<<'; - $next_month = '>>'; + $down = $this->mini_cal_month - 1; + $up = $this->mini_cal_month + 1; + $prev_month = '<<'; + $next_month = '>>'; $template->assign_block_vars('minical', array( 'S_SUNDAY_FIRST' => ($config['board3_sunday_first_' . $module_id]) ? true : false, @@ -571,7 +571,9 @@ class portal_calendar_module **/ private function makeTimestamp($date) { - $this->stamp = strtotime($date); + global $user; + + $this->stamp = strtotime($date) + $user->timezone + $user->dst; return ($this->stamp); } @@ -580,10 +582,18 @@ class portal_calendar_module **/ private function getMonth($callDate) { + global $user; + // last or first day of some months need to be treated in a special way + if (!empty($this->mini_cal_month)) + { + $today_timestamp = time() + $user->timezone + $user->dst; + $cur_month = date("n", $today_timestamp); + $correct_month = $cur_month + $this->mini_cal_month; + } $this->makeTimestamp($callDate); $this->dateYYYY = date("Y", $this->stamp); - $this->dateMM = date("n", $this->stamp); + $this->dateMM = (isset($correct_month)) ? $correct_month : date("n", $this->stamp); $this->ext_dateMM = date("F", $this->stamp); $this->dateDD = date("d", $this->stamp); $this->daysMonth = date("t", $this->stamp);