diff --git a/admin/tool/uploadcourse/classes/course.php b/admin/tool/uploadcourse/classes/course.php index 7b111cb9d35..de8c1459ce3 100644 --- a/admin/tool/uploadcourse/classes/course.php +++ b/admin/tool/uploadcourse/classes/course.php @@ -582,6 +582,11 @@ class tool_uploadcourse_course { } } + // Course start date. + if (!empty($coursedata['startdate'])) { + $coursedata['startdate'] = strtotime($coursedata['startdate']); + } + // Ultimate check mode vs. existence. switch ($mode) { case tool_uploadcourse_processor::MODE_CREATE_NEW: @@ -631,11 +636,6 @@ class tool_uploadcourse_course { $this->do = self::DO_CREATE; } - // Course start date. - if (!empty($coursedata['startdate'])) { - $coursedata['startdate'] = strtotime($coursedata['startdate']); - } - // Add role renaming. $errors = array(); $rolenames = tool_uploadcourse_helper::get_role_names($this->rawdata, $errors); diff --git a/admin/tool/uploadcourse/tests/course_test.php b/admin/tool/uploadcourse/tests/course_test.php index 0b62e87938b..32dd7a35d53 100644 --- a/admin/tool/uploadcourse/tests/course_test.php +++ b/admin/tool/uploadcourse/tests/course_test.php @@ -420,7 +420,7 @@ class tool_uploadcourse_course_testcase extends advanced_testcase { 'fullname' => 'Fullname', 'category' => '1', 'visible' => '0', - 'startdate' => '8 June 1990', + 'startdate' => 644803200, 'idnumber' => '123abc', 'summary' => 'Summary', 'format' => 'weeks', @@ -447,7 +447,7 @@ class tool_uploadcourse_course_testcase extends advanced_testcase { $this->assertEquals($defaultdata['fullname'], $course->fullname); $this->assertEquals($defaultdata['category'], $course->category); $this->assertEquals($defaultdata['visible'], $course->visible); - $this->assertEquals(mktime(0, 0, 0, 6, 8, 1990), $course->startdate); + $this->assertEquals($defaultdata['startdate'], $course->startdate); $this->assertEquals($defaultdata['idnumber'], $course->idnumber); $this->assertEquals($defaultdata['summary'], $course->summary); $this->assertEquals($defaultdata['format'], $course->format); @@ -473,7 +473,7 @@ class tool_uploadcourse_course_testcase extends advanced_testcase { 'fullname' => 'Fullname 2', 'category' => $cat->id, 'visible' => '1', - 'startdate' => '11 June 1984', + 'startdate' => 455760000, 'idnumber' => 'changedid', 'summary' => 'Summary 2', 'format' => 'topics', @@ -500,7 +500,7 @@ class tool_uploadcourse_course_testcase extends advanced_testcase { $this->assertEquals($defaultdata['fullname'], $course->fullname); $this->assertEquals($defaultdata['category'], $course->category); $this->assertEquals($defaultdata['visible'], $course->visible); - $this->assertEquals(mktime(0, 0, 0, 6, 11, 1984), $course->startdate); + $this->assertEquals($defaultdata['startdate'], $course->startdate); $this->assertEquals($defaultdata['idnumber'], $course->idnumber); $this->assertEquals($defaultdata['summary'], $course->summary); $this->assertEquals($defaultdata['format'], $course->format); diff --git a/calendar/tests/calendartype_test.php b/calendar/tests/calendartype_test.php index c124477dc83..fdf6ee9184d 100644 --- a/calendar/tests/calendartype_test.php +++ b/calendar/tests/calendartype_test.php @@ -224,7 +224,7 @@ class core_calendar_type_testcase extends advanced_testcase { $el->_createElements(); $submitvalues = array('dateselector' => $date); - $this->assertSame($el->exportValue($submitvalues), array('dateselector' => $date['timestamp'])); + $this->assertSame(array('dateselector' => $date['timestamp']), $el->exportValue($submitvalues, true)); } /** diff --git a/lib/form/dateselector.php b/lib/form/dateselector.php index 29957e3d904..c7dfad279b5 100644 --- a/lib/form/dateselector.php +++ b/lib/form/dateselector.php @@ -262,7 +262,6 @@ class MoodleQuickForm_date_selector extends MoodleQuickForm_group { * @return array */ function exportValue(&$submitValues, $assoc = false) { - $value = null; $valuearray = array(); foreach ($this->_elements as $element){ $thisexport = $element->exportValue($submitValues[$this->getName()], true); @@ -274,21 +273,20 @@ class MoodleQuickForm_date_selector extends MoodleQuickForm_group { if($this->_options['optional']) { // If checkbox is on, the value is zero, so go no further if(empty($valuearray['enabled'])) { - $value[$this->getName()] = 0; - return $value; + return $this->_prepareValue(0, $assoc); } } // Get the calendar type used - see MDL-18375. $calendartype = \core_calendar\type_factory::get_calendar_instance(); $gregoriandate = $calendartype->convert_to_gregorian($valuearray['year'], $valuearray['month'], $valuearray['day']); - $value[$this->getName()] = make_timestamp($gregoriandate['year'], + $value = make_timestamp($gregoriandate['year'], $gregoriandate['month'], $gregoriandate['day'], 0, 0, 0, $this->_options['timezone'], true); - return $value; + return $this->_prepareValue($value, $assoc); } else { return null; } diff --git a/lib/form/datetimeselector.php b/lib/form/datetimeselector.php index 8055f026e6f..aa4951b3d44 100644 --- a/lib/form/datetimeselector.php +++ b/lib/form/datetimeselector.php @@ -285,7 +285,6 @@ class MoodleQuickForm_date_time_selector extends MoodleQuickForm_group { * @return array */ function exportValue(&$submitValues, $assoc = false) { - $value = null; $valuearray = array(); foreach ($this->_elements as $element){ $thisexport = $element->exportValue($submitValues[$this->getName()], true); @@ -297,8 +296,7 @@ class MoodleQuickForm_date_time_selector extends MoodleQuickForm_group { if($this->_options['optional']) { // If checkbox is on, the value is zero, so go no further if(empty($valuearray['enabled'])) { - $value[$this->getName()] = 0; - return $value; + return $this->_prepareValue(0, $assoc); } } // Get the calendar type used - see MDL-18375. @@ -308,7 +306,7 @@ class MoodleQuickForm_date_time_selector extends MoodleQuickForm_group { $valuearray['day'], $valuearray['hour'], $valuearray['minute']); - $value[$this->getName()] = make_timestamp($gregoriandate['year'], + $value = make_timestamp($gregoriandate['year'], $gregoriandate['month'], $gregoriandate['day'], $gregoriandate['hour'], @@ -317,7 +315,7 @@ class MoodleQuickForm_date_time_selector extends MoodleQuickForm_group { $this->_options['timezone'], true); - return $value; + return $this->_prepareValue($value, $assoc); } else { return null; } diff --git a/lib/form/tests/dateselector_test.php b/lib/form/tests/dateselector_test.php index f6e4e24198d..c2b003109de 100644 --- a/lib/form/tests/dateselector_test.php +++ b/lib/form/tests/dateselector_test.php @@ -133,7 +133,7 @@ class core_form_dateselector_testcase extends advanced_testcase { $el->_createElements(); $submitvalues = array('dateselector' => $vals); - $this->assertSame(array('dateselector' => $vals['timestamp']), $el->exportValue($submitvalues), + $this->assertSame(array('dateselector' => $vals['timestamp']), $el->exportValue($submitvalues, true), "Please check if timezones are updated (Site adminstration -> location -> update timezone)"); } } diff --git a/lib/form/tests/datetimeselector_test.php b/lib/form/tests/datetimeselector_test.php index ba188ee35b9..db3bdad60a1 100644 --- a/lib/form/tests/datetimeselector_test.php +++ b/lib/form/tests/datetimeselector_test.php @@ -145,7 +145,7 @@ class core_form_datetimeselector_testcase extends advanced_testcase { $el->_createElements(); $submitvalues = array('dateselector' => $vals); - $this->assertSame(array('dateselector' => $vals['timestamp']), $el->exportValue($submitvalues), + $this->assertSame(array('dateselector' => $vals['timestamp']), $el->exportValue($submitvalues, true), "Please check if timezones are updated (Site adminstration -> location -> update timezone)"); } }