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

QDate::fromString cannot parse date with negative year

    XMLWordPrintable

Details

    • Bug
    • Resolution: Done
    • P3: Somewhat important
    • None
    • 5.11.2
    • Core: Date/Time
    • None
    • Windows
    • 5
    • 91140eb7268bc36efceef0459e7b124ce333829e (qt/qtbase/dev)
    • Qt6_Foundation_Sprint 17, Qt6_Foundation_Sprint 18, Qt6_Foundation_Sprint 19, Qt6_Foundation_Sprint 20, Qt6_Foundation_Sprint 21

    Description

      QDate QDate::fromString(const QString &string, const QString &format) const

      cannot parse dates with negative year, although the documentation states that yyyy The year as four digit number. If the year is negative, a minus sign is prepended in addition.

      QDate::fromString( "-0010-01-01", "yyyy-MM-dd" );

       results in an invalid date.

      Instead

      QString QDate::toString(const QString &format) const

      correctly handles dates with negative years.

      In fact

      QDate( -10, 1, 1 ).toString( "yyyy-MM-dd" );

       correctly creates the string "-0010-01-01".

      Attachments

        Issue Links

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

          Activity

            People

              andreasbuhr Andreas Buhr
              andreaerdna Andrea Giudiceandrea
              Maurice Kalinowski Maurice Kalinowski
              Alex Blasche Alex Blasche
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Gerrit Reviews

                  There are no open Gerrit changes