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

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Unresolved
    • Icon: Blocker Blocker
    • None
    • 3.6.5, 3.7.1, 3.8
    • Enrolments
    • MOODLE_36_STABLE, MOODLE_37_STABLE, MOODLE_38_STABLE

      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.

            Unassigned Unassigned
            dobedobedoh Andrew Lyons
            Votes:
            8 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:

                Estimated:
                Original Estimate - Not Specified
                Not Specified
                Remaining:
                Remaining Estimate - 0 minutes
                0m
                Logged:
                Time Spent - 3 hours
                3h

                  Error rendering 'clockify-timesheets-time-tracking-reports:timer-sidebar'. Please contact your Jira administrators.