Weekly course date shift problem after update from 4.1.5+ > 4.1.6+ (after daylight saving time change)

Weekly course date shift problem after update from 4.1.5+ > 4.1.6+ (after daylight saving time change)

by Tobias Kueng -
Number of replies: 1
After the update 4.1.5+ > 4.1.6+ there is a weekday shift after daylight saving time change. Example:

Weekly course date BEFORE the update:


Weekly course date AFTER the update:


In the file /var/www/moodle/course/format/weeks/lib.php we have now found the following adjustment:

Code Version 4.1.5+:
-------------------------------------------------------------------------------------------------

        $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;

        $dates = new stdClass();
        $dates->start = $startdate + ($oneweekseconds * ($sectionnum - 1));
        $dates->end = $dates->start + $oneweekseconds;
-------------------------------------------------------------------------------------------------

has been replaced by in version 4.1.6+:
-------------------------------------------------------------------------------------------------
        // 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 = $startdateobj->getTimestamp();
        $dates->end = $enddateobj->getTimestamp();
-------------------------------------------------------------------------------------------------

If we replace this part of the code with the old code in version 4.1.6+, our problem is solved.

Does anyone know this problem and is there a solution to do it without manually updapting the code?

Many thanks in advance!

Average of ratings: -
In reply to Tobias Kueng

Re: Weekly course date shift problem after update from 4.1.5+ > 4.1.6+ (after daylight saving time change)

by Marty Gilbert -
Picture of Core developers
I ran into the same issue - thanks for your post.

I did find MDL-79648 which seems to be our issue and also has a patch in the works. It adds three lines that set the user's timezone from get_user_timezone():