diff --git a/calendar/export_execute.php b/calendar/export_execute.php index 6e76e331867..b4afb2c7076 100644 --- a/calendar/export_execute.php +++ b/calendar/export_execute.php @@ -91,7 +91,10 @@ if(!empty($what) && !empty($time)) { list($startmonth, $startyear) = calendar_add_month($startmonth, $startyear); $startmonthday = find_day_in_month(1, $startweekday, $startmonth, $startyear); } - $timestart = make_timestamp($startyear, $startmonth, $startmonthday); + $gregoriandate = $calendartype->convert_to_gregorian($startyear, $startmonth, $startmonthday); + $timestart = make_timestamp($gregoriandate['year'], $gregoriandate['month'], $gregoriandate['day'], + $gregoriandate['hour'], $gregoriandate['minute']); + $endmonthday = $startmonthday + $numberofdaysinweek; $endmonth = $startmonth; $endyear = $startyear; @@ -99,7 +102,9 @@ if(!empty($what) && !empty($time)) { list($endmonth, $endyear) = calendar_add_month($endmonth, $endyear); $endmonthday = find_day_in_month(1, $startweekday, $endmonth, $endyear); } - $timeend = make_timestamp($endyear, $endmonth, $endmonthday) - 1; + $gregoriandate = $calendartype->convert_to_gregorian($endyear, $endmonth, $endmonthday); + $timeend = make_timestamp($gregoriandate['year'], $gregoriandate['month'], $gregoriandate['day'], + $gregoriandate['hour'], $gregoriandate['minute']); break; case 'weeknext': $startweekday = calendar_get_starting_weekday(); @@ -110,7 +115,10 @@ if(!empty($what) && !empty($time)) { list($startmonth, $startyear) = calendar_add_month($startmonth, $startyear); $startmonthday = find_day_in_month(1, $startweekday, $startmonth, $startyear); } - $timestart = make_timestamp($startyear, $startmonth, $startmonthday); + $gregoriandate = $calendartype->convert_to_gregorian($startyear, $startmonth, $startmonthday); + $timestart = make_timestamp($gregoriandate['year'], $gregoriandate['month'], $gregoriandate['day'], + $gregoriandate['hour'], $gregoriandate['minute']); + $endmonthday = $startmonthday + $numberofdaysinweek; $endmonth = $startmonth; $endyear = $startyear; @@ -118,15 +126,17 @@ if(!empty($what) && !empty($time)) { list($endmonth, $endyear) = calendar_add_month($endmonth, $endyear); $endmonthday = find_day_in_month(1, $startweekday, $endmonth, $endyear); } - $timeend = make_timestamp($endyear, $endmonth, $endmonthday) - 1; + $gregoriandate = $calendartype->convert_to_gregorian($endyear, $endmonth, $endmonthday); + $timeend = make_timestamp($gregoriandate['year'], $gregoriandate['month'], $gregoriandate['day'], + $gregoriandate['hour'], $gregoriandate['minute']); break; case 'monthnow': // Convert to gregorian. $gregoriandate = $calendartype->convert_to_gregorian($now['year'], $now['mon'], 1); - $timestart = make_timestamp($gregoriandate['year'], $gregoriandate['month'], $gregoriandate['day']); - $timeend = make_timestamp($gregoriandate['year'], $gregoriandate['month'], - calendar_days_in_month($now['mon'], $now['year']), 23, 59, 59); + $timestart = make_timestamp($gregoriandate['year'], $gregoriandate['month'], $gregoriandate['day'], + $gregoriandate['hour'], $gregoriandate['minute']); + $timeend = $timestart + (calendar_days_in_month($now['mon'], $now['year']) * DAYSECS); break; case 'monthnext': // Get the next month for this calendar. @@ -136,9 +146,9 @@ if(!empty($what) && !empty($time)) { $gregoriandate = $calendartype->convert_to_gregorian($nextyear, $nextmonth, 1); // Create the timestamps. - $timestart = make_timestamp($gregoriandate['year'], $gregoriandate['month'], $gregoriandate['day']); - $timeend = make_timestamp($gregoriandate['year'], $gregoriandate['month'], - calendar_days_in_month($nextmonth, $nextyear), 23, 59, 59); + $timestart = make_timestamp($gregoriandate['year'], $gregoriandate['month'], $gregoriandate['day'], + $gregoriandate['hour'], $gregoriandate['minute']); + $timeend = $timestart + (calendar_days_in_month($nextmonth, $nextyear) * DAYSECS); break; case 'recentupcoming': //Events in the last 5 or next 60 days diff --git a/calendar/lib.php b/calendar/lib.php index a805f33b279..6c7bf6e59c7 100644 --- a/calendar/lib.php +++ b/calendar/lib.php @@ -227,10 +227,10 @@ function calendar_get_mini($courses, $groups, $users, $calmonth = false, $calyea list($d, $m, $y) = array($date['mday'], $date['mon'], $date['year']); // This is what we want to display. - // Get Gregorian date. + // Get Gregorian date for the start of the month. $gregoriandate = $calendartype->convert_to_gregorian($date['year'], $date['mon'], 1); - // Store the gregorian year and month to be used later. + // Store the gregorian date values to be used later. list($gy, $gm, $gd, $gh, $gmin) = array($gregoriandate['year'], $gregoriandate['month'], $gregoriandate['day'], $gregoriandate['hour'], $gregoriandate['minute']); @@ -249,7 +249,7 @@ function calendar_get_mini($courses, $groups, $users, $calmonth = false, $calyea // These are used for DB queries, so we want unixtime, so we need to use Gregorian dates. $display->tstart = make_timestamp($gy, $gm, $gd, $gh, $gmin, 0); - $display->tend = make_timestamp($gy, $gm, $display->maxdays, 23, 59, 59); + $display->tend = $display->tstart + ($display->maxdays * DAYSECS) - 1; // Align the starting weekday to fall in our display range // This is simple, not foolproof. @@ -860,12 +860,14 @@ function calendar_top_controls($type, $data) { // We need to get the previous and next months in certain cases. if ($type == 'frontpage' || $type == 'course' || $type == 'month') { $prevmonth = calendar_sub_month($date['mon'], $date['year']); - $prevmonthtime = $calendartype->convert_to_gregorian($prevmonth[1], $prevmonth[0], $date['mday']); - $prevmonthtime = make_timestamp($prevmonthtime['year'], $prevmonthtime['month'], $prevmonthtime['day']); + $prevmonthtime = $calendartype->convert_to_gregorian($prevmonth[1], $prevmonth[0], 1); + $prevmonthtime = make_timestamp($prevmonthtime['year'], $prevmonthtime['month'], $prevmonthtime['day'], + $prevmonthtime['hour'], $prevmonthtime['minute']); $nextmonth = calendar_add_month($date['mon'], $date['year']); - $nextmonthtime = $calendartype->convert_to_gregorian($nextmonth[1], $nextmonth[0], $date['mday']); - $nextmonthtime = make_timestamp($nextmonthtime['year'], $nextmonthtime['month'], $nextmonthtime['day']); + $nextmonthtime = $calendartype->convert_to_gregorian($nextmonth[1], $nextmonth[0], 1); + $nextmonthtime = make_timestamp($nextmonthtime['year'], $nextmonthtime['month'], $nextmonthtime['day'], + $nextmonthtime['hour'], $nextmonthtime['minute']); } switch ($type) { diff --git a/calendar/renderer.php b/calendar/renderer.php index efb4725baf9..fd9b99eeb55 100644 --- a/calendar/renderer.php +++ b/calendar/renderer.php @@ -172,12 +172,14 @@ class core_calendar_renderer extends plugin_renderer_base { $date = $calendartype->timestamp_to_date_array($calendar->time); $prevmonth = calendar_sub_month($date['mon'], $date['year']); - $prevmonthtime = $calendartype->convert_to_gregorian($prevmonth[1], $prevmonth[0], $date['mday']); - $prevmonthtime = make_timestamp($prevmonthtime['year'], $prevmonthtime['month'], $prevmonthtime['day']); + $prevmonthtime = $calendartype->convert_to_gregorian($prevmonth[1], $prevmonth[0], 1); + $prevmonthtime = make_timestamp($prevmonthtime['year'], $prevmonthtime['month'], $prevmonthtime['day'], + $prevmonthtime['hour'], $prevmonthtime['minute']); $nextmonth = calendar_add_month($date['mon'], $date['year']); - $nextmonthtime = $calendartype->convert_to_gregorian($nextmonth[1], $nextmonth[0], $date['mday']); - $nextmonthtime = make_timestamp($nextmonthtime['year'], $nextmonthtime['month'], $nextmonthtime['day']); + $nextmonthtime = $calendartype->convert_to_gregorian($nextmonth[1], $nextmonth[0], 1); + $nextmonthtime = make_timestamp($nextmonthtime['year'], $nextmonthtime['month'], $nextmonthtime['day'], + $nextmonthtime['hour'], $nextmonthtime['minute']); $content = html_writer::start_tag('div', array('class' => 'minicalendarblock')); $content .= calendar_get_mini($calendar->courses, $calendar->groups, $calendar->users, false, false, 'display', $calendar->courseid, $prevmonthtime); @@ -417,10 +419,9 @@ class core_calendar_renderer extends plugin_renderer_base { $calendar->time = time(); } - // Get Gregorian date. + // Get Gregorian date for the start of the month. $gregoriandate = $calendartype->convert_to_gregorian($date['year'], $date['mon'], 1); - - // Store the gregorian year and month to be used later. + // Store the gregorian date values to be used later. list($gy, $gm, $gd, $gh, $gmin) = array($gregoriandate['year'], $gregoriandate['month'], $gregoriandate['day'], $gregoriandate['hour'], $gregoriandate['minute']); @@ -437,7 +438,7 @@ class core_calendar_renderer extends plugin_renderer_base { // These are used for DB queries, so we want unixtime, so we need to use Gregorian dates. $display->tstart = make_timestamp($gy, $gm, $gd, $gh, $gmin, 0); - $display->tend = make_timestamp($gy, $gm, $display->maxdays, 23, 59, 59); + $display->tend = $display->tstart + ($display->maxdays * DAYSECS) - 1; // Align the starting weekday to fall in our display range // This is simple, not foolproof.