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

QDateTime needs clarifications on Windows

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Not Evaluated
    • Resolution: Fixed
    • Affects Version/s: 5.2.1
    • Fix Version/s: 5.11
    • Component/s: Core: Date/Time
    • Labels:
      None
    • Environment:
      Windows 7 x64 SP1 Russian, Qt 5.2.1, mingw 4.8. Time zone is 'Europe/Moscow'.
    • Commits:
      68bcccac228b73c54137304718c3c92460bc1f4b

      Description

      This code snippet shows that 01.01.2014 0:00:00 is an invalid date/time in 'Europe/Moscow' time zone:

          const QDateTime yearStart(QDate(2014, 1, 1));
          Q_ASSERT(yearStart.isValid()); // Fails!
      

      But actually, it was perfectly valid date/time
      And due to recent time zone data update in Russia, Microsoft has issued a patch. I examined new time zone data with http://www.southsoftware.com/tzedit.zip

      The time zone update consists of -1 hour shift on 26.10.2014, 03:00:00. From +4 hours to +3.

      Old time zone data was: UTC bias +4 hours, no DST.
      New time zone data in Windows for year 2014 in Moscow is:
      UTC bias is +3 hours.
      Enable DST from 01.01.2014 0:00:00 to 26.10.2014 03:00 (add +1 hour).

      And I think it's buggy because it makes 01.01.2014 0:00:00 an invalid date/time.

      Consider UTC date/time 31.12.2013 19:59:59. In Moscow, it is 31.12.2013 23:59:59. The question is: what datetime will be in Moscow the next second?
      It cannot be 01.01.2014 01:00:00, because that would make time difference +5 hours. It should be 01.01.2014 00:00:00!

      In addition, consider:

          const char* tzMoscow = "Europe/Moscow";
          QTimeZone moscow(QByteArray::fromRawData(tzMoscow, 13));
          Q_ASSERT(moscow.isValid());
          QDateTime t1(QDate(2013, 12, 31), QTime(19, 59, 59), Qt::UTC);
          QDateTime t2 = t1.toTimeZone(moscow);
          QDateTime t3 = t1.toLocalTime(); // in 'Europe/Moscow'
          QDateTime t4 = t2.addSecs(1);
          QDateTime t5 = t3.addSecs(1);
          QTimeZone tz1 = t1.timeZone();
          QTimeZone tz2 = t2.timeZone();
          QTimeZone tz3 = t3.timeZone();
      

      The debugger shows:
      t1 == Tue Dec 31 19:59:59 2013 GMT
      t2 == Tue Dec 31 23:59:59 2013 GMT
      t3 == Tue Dec 31 22:59:59 2013
      t4 == Wed Jan 1 00:00:00 2014 GMT
      t5 == Tue Dec 31 23:00:00 2013
      tz1 == "UTC"
      tz2 == "Europe/Moscow"
      tz3 == "Europe/Moscow"

      But time difference between t1, t2 and t3 is zero.
      The question is: why ::toTimeZone and ::toLocalTime produce different results? The local time zone is set to "Europe/Moscow".

        Attachments

          Issue Links

          No reviews matched the request. Check your Options in the drop-down menu of this sections header.

            Activity

              People

              Assignee:
              Eddy Edward Welbourne
              Reporter:
              azarubkin Alexandr Zarubkin
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved:

                  Gerrit Reviews

                  There are no open Gerrit changes