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

QDateTime::toString( Qt::ISODate ) lacks prefixed 0's on years below 1000

    XMLWordPrintable

Details

    • Bug
    • Resolution: Duplicate
    • P2: Important
    • None
    • Some future release
    • Core: Date/Time
    • None

    Description

      QDateTime::toString( Qt::ISODate lacks prefixed 0's on years below 1000. The iso8601 standard dictates that this should be the case.

      Additionally: If the date is in UTC, A Z should be postixed, otherwise an offset for the timezone should be postfixed.

      Additionally: If the date is before 1/1/1 00:00:00 UTC, the method should throw instead of returning an empty string, IMO.

      Test example for first issue:

      void test_early_date() {
        QDateTime d_datetime_def ( QDate( 1, 1, 1 ), QTime( 0, 0, 0 ) );
        std::cout << d_datetime_def.toString().toLocal8Bit().constData() << std::endl;
        std::cout << d_datetime_def.toString( Qt::ISODate ).toLocal8Bit().constData() << std::endl;
        std::cout << d_datetime_def.toUTC().toString().toLocal8Bit().constData() << std::endl;
        std::cout << d_datetime_def.toUTC().toString( Qt::ISODate ).toLocal8Bit().constData() << std::endl;
      
        d_datetime_def = QDateTime( QDate( 999, 6, 7 ), QTime( 12, 13, 14 ) );
        std::cout << d_datetime_def.toString().toLocal8Bit().constData() << std::endl;
        std::cout << d_datetime_def.toString( Qt::ISODate ).toLocal8Bit().constData() << std::endl;
        std::cout << d_datetime_def.toUTC().toString().toLocal8Bit().constData() << std::endl;
        std::cout << d_datetime_def.toUTC().toString( Qt::ISODate ).toLocal8Bit().constData() << std::endl;
      }
      

      Outputs (when running in a timezone of +01:00):

      Sat Jan 1 00:00:00 1
      1-01-01T00:00:00
      Fri Dec 31 23:00:00 -1
      (NOTHING)
      Wed Jun 7 12:13:14 999
      999-06-07T12:13:14
      Wed Jun 7 11:13:14 999
      999-06-07T11:13:14
      

      Expected

      Sat Jan 1 00:00:00 1
      0001-01-01T00:00:00
      Fri Dec 31 23:00:00 -1
      "*ERROR*"
      Wed Jun 7 12:13:14 999
      0999-06-07T12:13:14
      Wed Jun 7 11:13:14 999
      0999-06-07T11:13:14
      

      Preferred

      Sat Jan 1 00:00:00 1
      0001-01-01T00:00:00+01:00
      Fri Dec 31 23:00:00 -1
      "*ERROR*"
      Wed Jun 7 12:13:14 999
      0999-06-07T12:13:14+01:00
      Wed Jun 7 11:13:14 999
      0999-06-07T11:13:14Z
      

      Attachments

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

        Activity

          People

            Unassigned Unassigned
            mbd@dbc.dk Mads Bondo Dydensborg
            Votes:
            7 Vote for this issue
            Watchers:
            10 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes