Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-38448

setUTCx group of methods of QML's Date object works strange

    XMLWordPrintable

Details

    • Bug
    • Resolution: Done
    • P2: Important
    • 5.4.0 Beta
    • 5.0.0, 5.2.0
    • None
    • Tested it with Qt5.2 for Android and Ubuntu SDK (5.0)

    Description

      In an example function (which you can see below) I use hadwritten parsing of string representation of current datetime. If I use current time (which can be obtained by new Date()) as "stamp" (look at code), parse it and use set of setUTCx functions of Date object to set correct values I'll get absolutely wrong date, which sometimes differ about 2 days from original. Here is an example output in Qt Creator:

      — Sat, 2014 Apr 19 7 11 27
      — Sat Apr 19 11:34:53 2014 GMT+0400
      — Sat Apr 19 11:34:53 2014 GMT+0400
      — Sat Apr 19 07:34:53 2014 GMT+0400 // Whoops: -4 hours
      — Sat Apr 19 03:34:53 2014 GMT+0400
      — Sat Apr 18 07:34:53 2014 GMT+0400 // Day changed 0_0
      — Sat Apr 18 03:11:53 2014 GMT+0400
      — Sat Apr 17 23:11:27 2014 GMT+0400

      Output in chrome (the same code works fine)

      — Sat, 2014 Apr 19 7 11 27
      — Sat Apr 19 2014 11:12:23 GMT+0400 (MSK)
      — Sat Apr 19 2014 11:12:23 GMT+0400 (MSK)
      — Sat Apr 19 2014 11:12:23 GMT+0400 (MSK)
      — Sat Apr 19 2014 11:12:23 GMT+0400 (MSK)
      — Sat Apr 19 2014 11:12:23 GMT+0400 (MSK)
      — Sat Apr 19 2014 11:11:23 GMT+0400 (MSK)
      — Sat Apr 19 2014 11:11:27 GMT+0400 (MSK)

      Example function:

      function testTime() {
      var stamp = "Sat, 19 Apr 2014 07:11:27 UTC" // Use current date time here
      var parts = stamp.split(" ");
      var dayName;
      var monthName;
      var day;
      var time;
      var hours;
      var minutes;
      var seconds;
      var year;

      dayName = parts[0];
      day = parseInt(parts[1], 10);
      monthName = parts[2];
      year = parseInt(parts[3], 10);
      time = parts[4].split(":");
      hours = parseInt(time[0], 10);
      minutes = parseInt(time[1], 10);
      seconds = parseInt(time[2], 10);

      var month = 0;
      if(monthName=="Jan")

      { month = 0; }

      else if(monthName=="Feb")

      { month = 1; }

      else if(monthName=="Mar")

      { month = 2; }

      else if(monthName=="Apr")

      { month = 3; }

      else if(monthName=="May")

      { month = 4; }

      else if(monthName=="Jun")

      { month = 5; }

      else if(monthName=="Jul")

      { month = 6; }

      else if(monthName=="Aug")

      { month = 7; }

      else if(monthName=="Sep")

      { month = 8; }

      else if(monthName=="Oct")

      { month = 9; }

      else if(monthName=="Nov")

      { month = 10; }

      else if(monthName=="Dec")

      { month = 11; }

      console.log(" — ", dayName, year, monthName, day, hours, minutes, seconds )

      var dt = new Date();
      console.log(" — ", dt)
      dt.setYear(year);
      console.log(" — ", dt)
      dt.setUTCMonth(month);
      console.log(" — ", dt)
      dt.setUTCDate(day);
      console.log(" — ", dt)
      dt.setUTCHours(hours);
      console.log(" — ", dt)
      dt.setUTCMinutes(minutes);
      console.log(" — ", dt)
      dt.setUTCSeconds(seconds);
      console.log(" — ", dt)
      }

      Attachments

        Issue Links

          For Gerrit Dashboard: QTBUG-38448
          # Subject Branch Project Status CR V

          Activity

            People

              laknoll Lars Knoll
              qtros Roman Shchekin
              Votes:
              0 Vote for this issue
              Watchers:
              4 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Gerrit Reviews

                  There are no open Gerrit changes