Uploaded image for project: 'Moodle'
  1. Moodle
  2. MDL-66339

When system time does not match user profile time, dates in enrolment modal are wrong



    • Bug
    • Status: Open
    • Blocker
    • Resolution: Unresolved
    • 3.6.5, 3.7.1, 3.8
    • None
    • Enrolments


      Given my system timezone is set to "Europe/Berlin"
      And my Moodle User profile timezone is set to "Australia/Perth"
      And I have a course "The history of cheese"
      When I enrol user "colin" to "The history of cheese" with an enrolment start date of "9th August 2019 22:00"
      And I view the enrolment information for "colin" in "The history of cheese"
      Then I should see an enrolment start date of "9th August 2019 22:00"
      However I see an enrolment start date of "10th August 2019 04:00"

      This took a long time to track down.

      Moodle always corrects everything to be in user profile time, which defaults to the "Server timezone" (which is actually the one set in site administration), which itself defaults to "Australia/Perth"

      All of our CI servers therefore end up with a timezone of Australia/Perth, despite the fact that they're in Germany.

      However, the true System timezone (the one selected on the actual server) is "Europe/Berlin".

      For the most part that's A-Okay. No dramas there, BUT in the enrolment editing page we play with timezones in JavaScript.

      When we open the dialogue, and we set a time of 10pm...

      We create a new timezone with:

      var timeStart = new Date(timeStartYear, timeStartMonth, timeStartDay, timeStartHour, timeStartMinute);

      The values in the various fields are in the User timezone (i.e. "Australia/Perth")

      This creates a new Date Object with the values provided. It does so assuming that they are values in the timezone of the browser - "Europe/Berlin".
      As a result our 10pm AWST (Australian Western Standard Time) is assumed to actually be 10pm EST (European Summer Time).
      In the following line we get the unix timestamp of that value, which is modified for UTC.
      As a result we end up with a unix timestamp relating to 10pm EST => 8pm UTC.
      We then store that date in the database as being 8pm UTC.

      Next time that we open the dialogue, the time is read as being 8pm UTC, and then converted to a value for Moodle in AWST which is 4am AWST the following day.

      This happens because the JS Date object always assumes that the Browser timezone matches the content. Essentially it is not safe to use the JS Date object in Moodle to fetch a unix timestamp.


        Issue Links



              Unassigned Unassigned
              dobedobedoh Andrew Lyons
              Amaia Anabitarte, Carlos Escobedo, Ferran Recio, Ilya Tregubov, Laurent David, Raquel Ortega, Sara Arjona (@sarjona)
              3 Vote for this issue
              1 Start watching this issue



                Time Tracking

                  Original Estimate - Not Specified
                  Not Specified
                  Remaining Estimate - 0 minutes
                  Time Spent - 3 hours