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

The need for broken-down date difference, and duration

    XMLWordPrintable

    Details

    • Type: Suggestion
    • Status: Closed
    • Priority: Not Evaluated
    • Resolution: Duplicate
    • Affects Version/s: None
    • Fix Version/s: None
    • Component/s: Core: Date/Time
    • Labels:
      None
    • Platform/s:
      All

      Description

      In my application, I am showing and comparing the age of certain historical events. The users should be able to read: "The king was assassinated 108 years, 9 months and two days ago". And also some sentences in these lines: "The twins died 5 years apart"...

      All the dates are manipulated and stored (in a MariaDB database) using QDate class.

      It would be very nice to have the means to calculate the difference between two points in the calendar, resulting in a human-readable form. It quickly gets tricky when dealing with multiple calendar systems. I would very much like QDate objects to have an operator- implemented which either:

      • Returns an instance of a new object (QTimePeriod? QDatePeriod?)
      • Or, returns a tuple of three numbers (QCalendar::YearMonthDay)

      The latter option is suboptimal for two reasons. First, because the concept of the time period is calendar-specific. That is two years in the Islamic Civil calendar are about 20 days shorter than two years in the Gregorian calendar, for example. Second is that the time periods in a calendar system need an origin to form a vector space. That is, for example, "two months"; if added to February 1st, 2019, is a different time period than if added to September 1st, 2019. Thus we need to define the starting date to be able to uniquely identify a time period. (Maybe to arithmetically compare them, or to convert them to a "durations"?)

      So we could have: 

      QDate d1;
      QDate d2;
      QTimePeriod p = d2 - d1;
      qDebug() << p.years() << p.months() << p.days(); // Note the plurals please
      qDebug() << p.toDays();    // is equal to d1.daysTo(d2);
      qDebug() << p.toMonths();
      qDebug() << p.toYears();
      
      QCalendar c{QCalendar::System::Jalali};
      qDebug() << p.years(c) << p.months(c) << p.days(c); // Note the calendar argument please
      

      This could be extended to QDateTime or QTime as well.

      Please note that a date difference is a different concept compared to a duration.

        Attachments

          Issue Links

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

            Activity

              People

              Assignee:
              Eddy Edward Welbourne
              Reporter:
              soroush Soroush Rabiei
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved:

                  Gerrit Reviews

                  There are no open Gerrit changes