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

Problems with "ddd" format in QDateTime::fromString();

    XMLWordPrintable

Details

    • Bug
    • Resolution: Cannot Reproduce
    • P2: Important
    • 5.0.0
    • 4.6.2
    • Core: Locales (i18n)
    • None
    • Qt 4.6.2 for Windows
      Windows XP SP 3 (Nokia Image :))
      Qt Creator 1.3.1

    Description

      There seems to be a problem when using "ddd" format in QDateTime::fromString(). It only appears if "ddd" is combined with "d" or "dd" in the same date string, not with any other format tokens or even "dddd".

      As a result, date strings where the both the day of the month and the short day name appear, such as "Thu 15 Apr 10 20:30:30", cannot be parsed.

      Source code for testing:

      #include <QtCore/QCoreApplication>
      #include <QDebug>
      #include <QLocale>
      #include <QDateTime>
      
      void dumpAndReadDate(const QString& formatString) {
        QString dateString;
        QDateTime now = QDateTime::currentDateTime();
        QDateTime dateTime;
      
        //1st case, dump and re-read
        dateString = now.toString(formatString);
      
        qDebug() << "==============================================";
        qDebug() << "Current datetime dumped w/ format:" << formatString << " is " << dateString;
        dateTime = QDateTime::fromString(dateString, formatString);
        qDebug() << "Reading back with format " << formatString << ":";
        qDebug() << dateTime << ", isValid:" << dateTime.isValid();
        qDebug() << "==============================================";
      }
      
      int main(int argc, char *argv[])
      {
          QCoreApplication a(argc, argv);
          QLocale loc;
      
          qDebug() << "Country:" << loc.countryToString(loc.country());
      
          dumpAndReadDate("ddd");
          dumpAndReadDate("ddd MM");
          dumpAndReadDate("ddd MM yy");
          dumpAndReadDate("ddd MM d"); //false
          dumpAndReadDate("ddd MM dd"); //false
          dumpAndReadDate("ddd MM dddd"); //true
      
          return a.exec();
      }
      

      Use cases marked as "false" are the ones that fail. No use cases could fail here, since the current date is being serialized and read back using the same format string.

      Locale is English/US, so nothing to see here as well.

      Attachments

        Issue Links

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

          Activity

            People

              leonlee Leonard Lee
              dcrocha Daniel Rocha
              Votes:
              0 Vote for this issue
              Watchers:
              6 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Gerrit Reviews

                  There are no open Gerrit changes