Merge branch 'MDL-75928-401' of https://github.com/lameze/moodle into MOODLE_401_STABLE

This commit is contained in:
Shamim Rezaie 2023-09-25 17:52:16 +10:00
commit ff0b12cfd3
2 changed files with 19 additions and 8 deletions

View File

@ -406,14 +406,25 @@ class format_weeks extends core_courseformat\base {
} else {
$sectionnum = $section;
}
$oneweekseconds = 604800;
// Hack alert. We add 2 hours to avoid possible DST problems. (e.g. we go into daylight
// savings and the date changes.
$startdate = $startdate + 7200;
// Create a DateTime object for the start date.
$startdateobj = new DateTime("@$startdate");
// Calculate the interval for one week.
$oneweekinterval = new DateInterval('P7D');
// Calculate the interval for the specified number of sections.
for ($i = 1; $i < $sectionnum; $i++) {
$startdateobj->add($oneweekinterval);
}
// Calculate the end date.
$enddateobj = clone $startdateobj;
$enddateobj->add($oneweekinterval);
$dates = new stdClass();
$dates->start = $startdate + ($oneweekseconds * ($sectionnum - 1));
$dates->end = $dates->start + $oneweekseconds;
$dates->start = $startdateobj->getTimestamp();
$dates->end = $enddateobj->getTimestamp();
return $dates;
}

View File

@ -219,8 +219,8 @@ class format_weeks_test extends \advanced_testcase {
$courseform = new \testable_course_edit_form(null, $args);
$courseform->definition_after_data();
// format_weeks::get_section_dates is adding 2h to avoid DST problems, we need to replicate it here.
$enddate = $params['startdate'] + (WEEKSECS * $params['numsections']) + 7200;
// Calculate the expected end date.
$enddate = $params['startdate'] + (WEEKSECS * $params['numsections']);
$weeksformat = course_get_format($course->id);
$this->assertEquals($enddate, $weeksformat->get_default_course_enddate($courseform->get_quick_form()));