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

QDate::fromString cannot parse date with negative year

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed
    • Priority: P3: Somewhat important
    • Resolution: Done
    • Affects Version/s: 5.11.2
    • Fix Version/s: None
    • Component/s: Core: Date/Time
    • Labels:
      None
    • Platform/s:
      Windows
    • Story Points:
      5
    • Commits:
      91140eb7268bc36efceef0459e7b124ce333829e (qt/qtbase/dev)
    • Sprint:
      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

              Assignee:
              andreasbuhr Andreas Buhr
              Reporter:
              andreaerdna Andrea Giudiceandrea
              PM Owner:
              Maurice Kalinowski Maurice Kalinowski
              RnD Owner:
              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