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

QTimeZone::abbreviation( ) crashes on some time zones

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed
    • Priority: P2: Important
    • Resolution: Done
    • Affects Version/s: 5.2.0
    • Fix Version/s: 5.2.0 RC1
    • Component/s: Core: Date/Time
    • Labels:
      None
    • Commits:
      8e6258f059140ce735391b6438d5976dc9469e95 6ad97bfa736c97b50019d0192f55959848e7067a

      Description

      QTimeZone::abbreviation() returns the abbreviated timezone, e.g. "EST" for a given region and local time.

      On some time zones it works, but on others it crashes with the error:
      ASSERT failure in QList<T>::at: "index out of range", file ../../include/QtCore/../../src/corelib/tools/qlist.h, line 472

      The "out of range" error suggests that the abbreviation data base is incomplete, though I haven't located exactly which code line triggers it.

      The following sample code for a main.cpp reproduces the error (in America/Curacao, but other zones also trigger it):

      #include <QTimeZone>
      #include <iostream>
      
      
      int main(int argc, char *argv[])
      {
          QTimeZone qtz( QTimeZone::systemTimeZoneId() );
      
          QDateTime timeNow( QDateTime::currentDateTime() );
      
          std::cout << "1) Test system time zone" << std::endl;
          std::cout << "time zone id=" << qtz.id().data() << std::endl;
          std::cout << "display name=" << qtz.displayName(timeNow).toStdString() << std::endl;
          std::cout << "abbreviation=" << qtz.abbreviation(timeNow).toStdString() << std::endl;
      
          QList<QByteArray> tzonelist( QTimeZone::availableTimeZoneIds() );
      
          // test Australia/Sydney: expect successful abbreviation=EST
          std::cout << std::endl << "2) Test Sydney" << std::endl;
          int iSydney=312;
          QTimeZone qtzSydney( tzonelist.at(iSydney) );
          std::cout << "time zone id=" << qtzSydney.id().data() << std::endl;
          std::cout << "display name=" << qtzSydney.displayName(timeNow).toStdString() << std::endl;
          std::cout << "abbreviation=" << qtzSydney.abbreviation(timeNow).toStdString() << std::endl;
      
          // test America/Curacao: expect "index out of range" error
          std::cout << std::endl << "3) Test Curacao" << std::endl;
          int iCuracao=92;
          QTimeZone qtzCuracao( tzonelist.at(iCuracao) );
          std::cout << "time zone id=" << qtzCuracao.id().data() << std::endl;
          std::cout << "display name=" << qtzCuracao.displayName(timeNow).toStdString() << std::endl;
          std::cout << "abbreviation=" << qtzCuracao.abbreviation(timeNow).toStdString() << std::endl;
      
          return 0;
      }
      

        Attachments

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

          Activity

            People

            Assignee:
            johnlayt John Layt
            Reporter:
            rizzer Drew Parsons
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved:

                Gerrit Reviews

                There are no open Gerrit changes