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

Time is incorrect for a given milliseconds since epoch under Moscow's timezone

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed
    • Priority: P2: Important
    • Resolution: Invalid
    • Affects Version/s: 5.5.1
    • Fix Version/s: None
    • Component/s: Core: Date/Time
    • Labels:
      None

      Description

      qDebug() << QDateTime::fromMSecsSinceEpoch(1393534800000);
      

      prints the following on Ubuntu 14.04:

      QDateTime(2014-02-28 01:00:00.000 MSK Qt::TimeSpec(LocalTime))
      

      when the timezone is set to Moscow. This doesn't happen in other timezones I tested (Oslo, for example).

      On Windows 7 it is correct, but a different timezone is chosen:

       QDateTime(2014-02-28 00:00:00.000 Russia TZ 2 Standard Time Qt::TimeSpec(LocalTime))
      

      That is with (UTC+03:00) Moscow, St. Petersburg, Volgograd (RTZ 2) set - the only available timezone in Windows for Moscow.

      Take this example from Chrome's developer console:

      new Date(2014, 1, 28).getTime()
      1393534800000
      new Date(1393534800000)
      Fri Feb 28 2014 00:00:00 GMT+0300 (MSK)
      

      The problem also seems to affect C++ -> QML conversions:

      #include <QApplication>
      #include <QtQuick>
      #include <QtQml>
      
      class Range : public QObject {
          Q_OBJECT
          Q_PROPERTY(QDate date READ date WRITE setDate NOTIFY dateChanged)
      public:
      
          QDate date() const;
          void setDate(const QDate &date);
      
      signals:
          void dateChanged();
      
      private:
          QDate mDate;
      };
      
      QDate Range::date() const
      {
          return mDate;
      }
      
      void Range::setDate(const QDate &date)
      {
          QDate adjusted = date;
      
          if (adjusted != mDate) {
              mDate = adjusted;
              qDebug() << Q_FUNC_INFO << date;
              qDebug() << Q_FUNC_INFO << adjusted;
              emit dateChanged();
          }
      }
      
      int main(int argc, char *argv[])
      {
          QApplication app(argc, argv);
      
          qmlRegisterType<Range>("Test", 1, 0, "Range");
      
          QQmlApplicationEngine engine;
          engine.load(QUrl(QStringLiteral("qrc:/main.qml")));
      
          return app.exec();
      }
      
      #include "main.moc"
      
      import QtQuick 2.4
      import QtQuick.Window 2.0
      
      import Test 1.0
      
      Window {
          width: 400
          height: 400
          visible: true
      
          Range {
              date: new Date(2014, 1, 28)
      
              Component.onCompleted: print(date, date.getDate(), new Date(2014, 1, 28).getDate())
          }
      }
      

      void Range::setDate(const QDate&) QDate("2014-02-28")
      void Range::setDate(const QDate&) QDate("2014-02-28")
      qml: Fri Feb 28 00:00:00 2014 GMT+0300 27 28

      date.getDate() should have returned 28 there.

        Attachments

          Issue Links

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

            Activity

              People

              Assignee:
              thiago Thiago Macieira
              Reporter:
              mitch_curtis Mitch Curtis
              Votes:
              2 Vote for this issue
              Watchers:
              3 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved:

                  Gerrit Reviews

                  There are no open Gerrit changes