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

QDate::fromString cannot parse date with negative year

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Done
    • Icon: P3: Somewhat important 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

      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".

        For Gerrit Dashboard: QTBUG-84334
        # Subject Branch Project Status CR V

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

              Created:
              Updated:
              Resolved:

                There are no open Gerrit changes