MDL-41792 core_calendar: fixed issues when using multiple calendar types

1) No longer assume that the end of the current month in Gregorian will be
the end of the month for the calendar type being used.
2) Need to take into account the hours and minutes a calendar type may vary
in order to generate timestamps.
3) When generating the previous and next month links start at the beginning
of the month, not the current day.
4) Need to convert to Gregorian when creating timestamps during calendar
exports.
This commit is contained in:
Mark Nelson
2013-10-11 16:28:04 +08:00
parent 1b7930fe4a
commit 1032966cee
3 changed files with 38 additions and 25 deletions
+20 -10
View File
@@ -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
+9 -7
View File
@@ -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) {
+9 -8
View File
@@ -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.