2017-01-17 11 views
2

私は、Windowsでは64ビットバージョンのQt 5.7.1を使用しています。 私のアプリケーションでは、異なるタイムゾーンで日付を管理しています。これらのタイムゾーンの変換は正しいですか?

私は最近、いくつかの奇妙な行動を見て、ここでそれをテストするための簡単なコードできた

:私は理解していない

      ParisDate = QDateTime(2016-01-20 02:00:00.000 Paris, Madrid Qt::TimeSpec(TimeZone) Europe/Paris) 
          PerthDate = QDateTime(2016-01-20 09:00:00.000 Australie (Ouest) Qt::TimeSpec(TimeZone) Australia/Perth) 
       delta Paris => Perth = 8 
delta ParisConvertedToPerth => Perth = 0 
        ParisDate to UTC = QDateTime(2016-01-20 01:00:00.000 UTC Qt::TimeSpec(UTC)) 
        PerthDate to UTC = QDateTime(2016-01-20 09:00:00.000 UTC Qt::TimeSpec(UTC)) 
     ParisConvertedToPerth to UTC = QDateTime(2016-01-20 09:00:00.000 UTC Qt::TimeSpec(UTC)) 

、理由:

QDateTime ParisDate(QDate(2016, 1, 20), QTime(2, 0, 0), QTimeZone("Europe/Paris")); 
QDateTime PerthDate(QDate(2016, 1, 20), QTime(9, 0, 0), QTimeZone("Australia/Perth")); 
QDateTime ParisConvertedToPerth = ParisDate.toTimeZone(QTimeZone("Australia/Perth")); 

qDebug() << "        ParisDate = " << ParisDate; 
qDebug() << "        PerthDate = " << PerthDate; 
qDebug() << "      delta Paris => Perth = " << ParisDate.secsTo(PerthDate)/3600; 
qDebug() << "  delta ParisConvertedToPerth => Perth = " << ParisConvertedToPerth.secsTo(PerthDate)/3600; 
qDebug() << "       ParisDate to UTC = " << ParisDate.toUTC(); 
qDebug() << "       PerthDate to UTC = " << PerthDate.toUTC(); 
qDebug() << "    ParisConvertedToPerth to UTC = " << ParisConvertedToPerth.toUTC(); 

これは以下の出力を生成私は、2つの変数 "ParisDate"と "PerthDate"は同じタイムゾーンを参照すべきで、異なるタイムゾーンを出現すると考えました。

「デルタパリ=>パース」は0時間とすべきだと思います。

私はQt5コードが壊れているとは思えないので、ここで何を欠場しましたか?

+0

それはバグのようになります。

使用したQtのdevの枝私はこの出力を持っています。 'PerthDate.utcOffset()'は0を返します:/ –

答えて

3

これはすでに修正されていますが、修正が公開されていないのQtのバグです。 Qt 5.9やQt 5.6.3を待たなければならないようです。

      ParisDate = QDateTime(2016-01-20 02:00:00.000 Paris, Madrid Qt::TimeSpec(TimeZone) Europe/Paris) 
          PerthDate = QDateTime(2016-01-20 09:00:00.000 Australie (Ouest) Qt::TimeSpec(TimeZone) Australia/Perth) 
       delta Paris => Perth = 0 
delta ParisConvertedToPerth => Perth = 0 
        ParisDate to UTC = QDateTime(2016-01-20 01:00:00.000 UTC Qt::TimeSpec(UTC)) 
        PerthDate to UTC = QDateTime(2016-01-20 01:00:00.000 UTC Qt::TimeSpec(UTC)) 
     ParisConvertedToPerth to UTC = QDateTime(2016-01-20 01:00:00.000 UTC Qt::TimeSpec(UTC)) 
+0

バグへのリンク?バグはいつ正確に起こりますか? – Mike

+0

これは悪いニュースですが、ありがとう!あなたはこのバグへのリンクを送ることができます、私はその状態に従うことができますか? – Aurelien

+0

私はこのバグに関連するバグレポートを知りません。しかし、このバグはWindows固有のようだが、私はUbuntu x64でそれを再現するためのablではなかった。 –

1

Qtでは何が起こっているのか話すことができません。しかし、私はあなたのテストの構文を変更してfree, open-source C++11/14 libraryを使用し、テストの構文と出力を比較することは面白いことだと思っていました。

auto ParisDate = make_zoned("Europe/Paris", local_days{2016_y/1/20} + 2h); 
auto PerthDate = make_zoned("Australia/Perth", local_days{2016_y/1/20} + 9h); 
auto ParisConvertedToPerth = make_zoned("Australia/Perth", ParisDate); 

cout << "       ParisDate = " << ParisDate << '\n'; 
cout << "       PerthDate = " << PerthDate << '\n'; 
cout << "    delta Paris => Perth = " 
    << floor<hours>(PerthDate.get_sys_time() - ParisDate.get_sys_time()) << '\n'; 
cout << "delta ParisConvertedToPerth => Perth = " 
    << floor<hours>(PerthDate.get_sys_time() - ParisConvertedToPerth.get_sys_time()) << '\n'; 
cout << "     ParisDate to UTC = " << ParisDate.get_sys_time() << '\n'; 
cout << "     PerthDate to UTC = " << PerthDate.get_sys_time() << '\n'; 
cout << "  ParisConvertedToPerth to UTC = " << ParisConvertedToPerth.get_sys_time() << '\n'; 

これは、次のような出力を生成:

      ParisDate = 2016-01-20 02:00:00 CET 
          PerthDate = 2016-01-20 09:00:00 AWST 
       delta Paris => Perth = 0h 
delta ParisConvertedToPerth => Perth = 0h 
        ParisDate to UTC = 2016-01-20 01:00:00 
        PerthDate to UTC = 2016-01-20 01:00:00 
     ParisConvertedToPerth to UTC = 2016-01-20 01:00:00 
関連する問題