diff options
author | Edward Welbourne <edward.welbourne@qt.io> | 2023-11-24 11:52:31 +0100 |
---|---|---|
committer | Edward Welbourne <edward.welbourne@qt.io> | 2023-12-08 11:40:36 +0100 |
commit | b8fac538032cee6eb6f4e5dcbb5a31485bb59e46 (patch) | |
tree | 581cd2961d5a7815421f8d1feea9c7bd68aa6939 /src/corelib/time/qcalendarbackend_p.h | |
parent | c5864a96a6670d9cece5eaa18cab8c4c339f8706 (diff) |
Add QCalendar::matchCenturyToWeekday()
This takes a YearMonthDay and a day-of-the-week, returning a QDate
that (if possible, else invalid) has the given day of the week and
differs from the YearMonthDay only in the century. This is useful when
resolving dates with only two-digit year information, which can be
disambiguated by the day of the week. Added tests of the new API.
This adds a new virtual method to QCalendarBackend, for which that
base class does provide a brute force implementation, so derived
classes do not need to add implementations. It is, however, a
binary-incompatible change for any backend plugins that may be in use
to implement custom calendars.
Worked out the details for the Gregorian calendar to make it possible
to compute the right century (and whether any century works) without
trial-and-error searching. Coded that up as its implementation of the
new method.
[ChangeLog][QtCore][QCalendar] Added a matchCenturyToWeekday() method
for use when resolving dates given day, month and last two digits of
the year, along with day of the week. Any custom calendar backend
plugins shall need a recompile and may, optionally, implement the new
virtual method behind this.
Change-Id: I6003c8d9423d6bfb833957bb5120f2d423219c7a
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Diffstat (limited to 'src/corelib/time/qcalendarbackend_p.h')
-rw-r--r-- | src/corelib/time/qcalendarbackend_p.h | 3 |
1 files changed, 2 insertions, 1 deletions
diff --git a/src/corelib/time/qcalendarbackend_p.h b/src/corelib/time/qcalendarbackend_p.h index 6f2782f506..88bb71b22e 100644 --- a/src/corelib/time/qcalendarbackend_p.h +++ b/src/corelib/time/qcalendarbackend_p.h @@ -86,8 +86,9 @@ public: // Julian Day conversions: virtual bool dateToJulianDay(int year, int month, int day, qint64 *jd) const = 0; virtual QCalendar::YearMonthDay julianDayToDate(qint64 jd) const = 0; - // Day of week and week numbering: + // Day of week: virtual int dayOfWeek(qint64 jd) const; + virtual qint64 matchCenturyToWeekday(const QCalendar::YearMonthDay &parts, int dow) const; // Names of months and week-days (implemented in qlocale.cpp): virtual QString monthName(const QLocale &locale, int month, int year, |