Uploaded image for project: 'Moodle'
  1. Moodle
  2. MDL-26753 DST issues
  3. MDL-27577

/lib/moodlelib.php functions userdate() and make_timestamp() were applying dst_offset for numeric timezones, i.e. 0 (UTC)

    XMLWordPrintable

Details

    • Sub-task
    • Status: Closed
    • Critical
    • Resolution: Fixed
    • 1.9.12, 2.0
    • 1.9.13, 2.0.4
    • Libraries
    • MOODLE_19_STABLE, MOODLE_20_STABLE
    • MOODLE_19_STABLE, MOODLE_20_STABLE
    • wip-mdl-27577-master
    • Hide

      1. Login as admin
      2. Update timezone (Site administration -> location -> update timezone)
      3. Run testmoodlelib.php simpletest.

      Instructions to run testmoodlelib.php simpletest
      On Moodle 2.xx
      1. Navigate to unit test (Development -> unit test)
      2. enter "lib/simpletest/testmoodlelib.php" in textbox.
      3. click "Run test"

      On Moodle 1.9x
      1. Navigate to unit test (Reports -> unit test)
      2. enter "lib/simpletest/testmoodlelib.php" in textbox.
      3. click "Run test"

      Show
      1. Login as admin 2. Update timezone (Site administration -> location -> update timezone) 3. Run testmoodlelib.php simpletest. Instructions to run testmoodlelib.php simpletest On Moodle 2.xx 1. Navigate to unit test (Development -> unit test) 2. enter "lib/simpletest/testmoodlelib.php" in textbox. 3. click "Run test" On Moodle 1.9x 1. Navigate to unit test (Reports -> unit test) 2. enter "lib/simpletest/testmoodlelib.php" in textbox. 3. click "Run test"

    Description

      /lib/moodlelib.php functions userdate() and make_timestamp() were applying dst_offset for numeric timezones, i.e. 0 (UTC)
      Our remedy:

      function make_timestamp($year, $month=1, $day=1, $hour=0, $minute=0, $second=0, $timezone=99, $applydst=true) {
       
          $passedtimezone = $timezone;
          $strtimezone = NULL;
          if (!is_numeric($timezone)) {
              $strtimezone = $timezone;
          }
       
          $timezone = get_user_timezone_offset($timezone);
       
          if (abs($timezone) > 13) {
              $time = mktime((int)$hour, (int)$minute, (int)$second, (int)$month, (int)$day, (int)$year);
          } else {
              $time = gmmktime((int)$hour, (int)$minute, (int)$second, (int)$month, (int)$day, (int)$year);
              $time = usertime($time, $timezone);
              if ($applydst && ($passedtimezone == 99 || !is_numeric($passedtimezone))) {
                  $time -= dst_offset_on($time, $strtimezone);
              }
          }
       
          return $time;
       
      }
       
      in userdate(): 
      ... // added if clause
          if ($timezone == 99 || !is_numeric($timezone)) {
              $date += dst_offset_on($date, $strtimezone);
          }
      ...

      Attachments

        Issue Links

          Activity

            People

              rajeshtaneja Rajesh Taneja
              brentb Brent Boghosian
              Andrew Davis Andrew Davis
              Eloy Lafuente (stronk7) Eloy Lafuente (stronk7)
              Eloy Lafuente (stronk7) Eloy Lafuente (stronk7)
              Amaia Anabitarte, Carlos Escobedo, Ferran Recio, Ilya Tregubov, Laurent David, Sara Arjona (@sarjona)
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:
                1/Aug/11