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

QDateTime::fromString generating invalid data with DST days

    XMLWordPrintable

Details

    • Linux/Other display system
    • ced34cb3d5805f1fbaf3b275714a1a5f3585900c (qt/qtbase/5.11)

    Description

      When creating a QDateTime object using ::fromString if the date is in the daylight saving time change the object may not be valid (as isValid() sees or toString() fails).

      To better understand I made a small example also attached (x.cpp).

      #include <iostream>
      #include <QtCore/QDateTime>
      
      int main (int ac, char **av) {
          QString tmp("2008.10.19");
          QDateTime ts = QDateTime::fromString(tmp, "yyyy.MM.dd");
          std::cout << "Date: " << ts.toString("dd.MM.yyyy hh.mm").toStdString() << std::endl;
          std::cout << "From epoch (ms): " << ts.toMSecsSinceEpoch() << std::endl;
          std::cout << "Valid: " << ts.isValid() << std::endl;
      }
      

      If this code is called with a TZ='Brazil/East' it will output:

      $ TZ='Brazil/East' ./x
      Date: 
      From epoch (ms): 1224385200000
      Valid: 0
      

      If called with a TZ='GMT' it will output:

      $ TZ='GMT' ./x
      Date: 19.10.2008 00.00
      From epoch (ms): 1224374400000
      Valid: 1
      

      I don't know if this is expected behavior for this code, but it seems the QDateTime should generate a valid object since it didn't receive time values, only date (yyyy.MM.dd), also on both timezones the ms from epoch seems right.}}

      I tested this on Ubuntu 18.04.1 LTS (Qt 5.9.5) and Gentoo (Qt 5.9.6).

      Thanks!

      Attachments

        1. CMakeLists.txt
          0.5 kB
        2. x.cpp
          0.6 kB
        3. x.cpp
          0.4 kB
        For Gerrit Dashboard: QTBUG-70823
        # Subject Branch Project Status CR V

        Activity

          People

            Eddy Edward Welbourne
            vnpavanelli Vinicius Pavanelli
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes