Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
Loading...
Searching...
No Matches
QGregorianCalendar Class Reference

The QGregorianCalendar class implements the Gregorian calendar. More...

#include <qgregoriancalendar_p.h>

+ Inheritance diagram for QGregorianCalendar:
+ Collaboration diagram for QGregorianCalendar:

Public Member Functions

QString name () const override
 Returns the primary name of the calendar.
 
bool isLeapYear (int year) const override
 Returns true if the specified year is a leap year for this calendar.
 
bool dateToJulianDay (int year, int month, int day, qint64 *jd) const override
 Computes the Julian day number corresponding to the specified year, month, and day.
 
QCalendar::YearMonthDay julianDayToDate (qint64 jd) const override
 Computes the year, month, and day in this calendar for the given Julian day number jd.
 
qint64 matchCenturyToWeekday (const QCalendar::YearMonthDay &parts, int dow) const override
 
- Public Member Functions inherited from QRomanCalendar
int daysInMonth (int month, int year=QCalendar::Unspecified) const override
 Returns number of days in the month number month, in year year.
 
int minimumDaysInMonth () const override
 Returns the minimum number of days in any valid month of any valid year.
 
bool isLunar () const override
 Returns true if this calendar is a lunar calendar.
 
bool isLuniSolar () const override
 Returns true if this calendar is a lunisolar calendar.
 
bool isSolar () const override
 Returns true if this calendar is a solar calendar.
 
QString monthName (const QLocale &locale, int month, int year, QLocale::FormatType format) const override
 Returns the name of the specified month in the given year for the chosen locale, using the given format to determine how complete the name is.
 
QString standaloneMonthName (const QLocale &locale, int month, int year, QLocale::FormatType format) const override
 Returns the standalone name of the specified month in the chosen locale, using the specified format to determine how complete the name is.
 
- Public Member Functions inherited from QCalendarBackend
 QCalendarBackend ()=default
 
virtual ~QCalendarBackend ()
 Destroys the calendar backend.
 
QStringList names () const
 Returns list of names this backend was registered with.
 
QCalendar::System calendarSystem () const
 The calendar system of this calendar.
 
QCalendar::SystemId calendarId () const
 
virtual int daysInYear (int year) const
 Returns the total number of days in the year number year.
 
virtual int monthsInYear (int year) const
 Returns the total number of months in the year number year.
 
virtual bool isDateValid (int year, int month, int day) const
 Returns true if the date specified by year, month, and day is valid for this calendar; otherwise returns false.
 
virtual bool isProleptic () const
 Returns true if this calendar is a proleptic calendar.
 
virtual bool hasYearZero () const
 Returns true if year number 0 is considered a valid year in this calendar.
 
virtual int maximumDaysInMonth () const
 Returns the maximum number of days in a month for any year.
 
virtual int maximumMonthsInYear () const
 Returns the maximum number of months possible in any year.
 
virtual int dayOfWeek (qint64 jd) const
 Returns the day of the week for the given Julian Day Number jd.
 
virtual QString weekDayName (const QLocale &locale, int day, QLocale::FormatType format) const
 Returns the name of the specified day of the week in the chosen locale, using the specified format to determine how complete the name is.
 
virtual QString standaloneWeekDayName (const QLocale &locale, int day, QLocale::FormatType format) const
 Returns the standalone name of the specified day of the week in the chosen locale, using the specified format to determine how complete the name is.
 
virtual QString dateTimeToString (QStringView format, const QDateTime &datetime, QDate dateOnly, QTime timeOnly, const QLocale &locale) const
 Returns a string representing a given date, time or date-time.
 
bool isGregorian () const
 
QCalendar::SystemId registerCustomBackend (const QStringList &names)
 Register this backend as a custom backend.
 

Static Public Member Functions

static QStringList nameList ()
 
static int weekDayOfJulian (qint64 jd)
 
static bool leapTest (int year)
 
static int monthLength (int month, int year)
 
static bool validParts (int year, int month, int day)
 
static QCalendar::YearMonthDay partsFromJulian (qint64 jd)
 
static std::optional< qint64julianFromParts (int year, int month, int day)
 
static int yearStartWeekDay (int year)
 
static int yearSharingWeekDays (QDate date)
 
- Static Public Member Functions inherited from QCalendarBackend
static QStringList availableCalendars ()
 Returns a list of names of the available calendar systems.
 

Additional Inherited Members

- Protected Member Functions inherited from QRomanCalendar
const QCalendarLocalelocaleMonthIndexData () const override
 
const char16_t * localeMonthData () const override
 

Detailed Description

The QGregorianCalendar class implements the Gregorian calendar.

Since
5.14

\inmodule QtCore

Definition at line 24 of file qgregoriancalendar_p.h.

Member Function Documentation

◆ dateToJulianDay()

bool QGregorianCalendar::dateToJulianDay ( int year,
int month,
int day,
qint64 * jd ) const
overridevirtual

Computes the Julian day number corresponding to the specified year, month, and day.

Returns true and sets jd if there is such a date in this calendar; otherwise, returns false.

See also
QCalendar::partsFromDate(), julianDayToDate()

Implements QCalendarBackend.

Definition at line 99 of file qgregoriancalendar.cpp.

References julianFromParts().

+ Here is the call graph for this function:

◆ isLeapYear()

bool QGregorianCalendar::isLeapYear ( int year) const
overridevirtual

Returns true if the specified year is a leap year for this calendar.

See also
daysInYear(), isDateValid()

Implements QCalendarBackend.

Definition at line 60 of file qgregoriancalendar.cpp.

References leapTest().

+ Here is the call graph for this function:

◆ julianDayToDate()

QCalendar::YearMonthDay QGregorianCalendar::julianDayToDate ( qint64 jd) const
overridevirtual

Computes the year, month, and day in this calendar for the given Julian day number jd.

If the given day falls outside this calendar's scope (e.g. before the start-date of a non-proleptic calendar), the returned structure's isValid() is false; otherwise, its year, month, and day fields provide this calendar's description of the date.

See also
QCalendar::dateFromParts(), dateToJulianDay()

Implements QCalendarBackend.

Definition at line 107 of file qgregoriancalendar.cpp.

References partsFromJulian().

+ Here is the call graph for this function:

◆ julianFromParts()

std::optional< qint64 > QGregorianCalendar::julianFromParts ( int year,
int month,
int day )
static

Definition at line 234 of file qgregoriancalendar.cpp.

References BaseJd, validParts(), and QRomanCalendrical::yearMonthToYearDays().

Referenced by QDate::QDate(), QLocalTime::computeSystemMillisRange(), dateToJulianDay(), QDate::dayOfYear(), QDateTimePrivate::expressUtcAsLocal(), fixedDate(), matchCenturyToWeekday(), millisToWithinRange(), and QDate::setDate().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ leapTest()

bool QGregorianCalendar::leapTest ( int year)
static

Definition at line 65 of file qgregoriancalendar.cpp.

References QCalendar::Unspecified.

Referenced by QDate::daysInYear(), QDate::isLeapYear(), isLeapYear(), monthLength(), systemTimeYearMatching(), and yearSharingWeekDays().

+ Here is the caller graph for this function:

◆ matchCenturyToWeekday()

qint64 QGregorianCalendar::matchCenturyToWeekday ( const QCalendar::YearMonthDay & parts,
int dow ) const
overridevirtual
Since
6.7 Adjusts century of parts to match dow.

Preserves parts.month and parts.day while adjusting parts.year by a multiple of 100 (taking the absence of year zero into account, when relevant) to obtain a date for which dayOfWeek() is dow. Prefers smaller changes over larger and increases to the century over decreases of the same magnitude. Returns the Julian Day number for the selected date or std::numeric_limits<qint64>::min(), a.k.a. QDate::nullJd(), if there is no date matching these requirements.

The base-class provides a brute-force implementation that steps outwards from the given date by centures, above and below by up to 14 centuries, in search of a matching date. This is neither computationally efficient nor elegant but should work as advertised for calendars in which every month-day combination does appear on all days of the week, across sufficiently many centuries.

Reimplemented from QCalendarBackend.

Definition at line 113 of file qgregoriancalendar.cpp.

References QCalendar::YearMonthDay::day, julianFromParts(), QCalendar::YearMonthDay::month, Q_ASSERT, Qt::Tuesday, weekDayOfJulian(), and QCalendar::YearMonthDay::year.

+ Here is the call graph for this function:

◆ monthLength()

int QGregorianCalendar::monthLength ( int month,
int year )
static

Definition at line 78 of file qgregoriancalendar.cpp.

References leapTest().

Referenced by QDate::daysInMonth(), fixedDate(), and validParts().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ name()

QString QGregorianCalendar::name ( ) const
overridevirtual

Returns the primary name of the calendar.

Implements QCalendarBackend.

Definition at line 47 of file qgregoriancalendar.cpp.

References QStringLiteral.

◆ nameList()

QStringList QGregorianCalendar::nameList ( )
static

Definition at line 52 of file qgregoriancalendar.cpp.

References QStringLiteral.

◆ partsFromJulian()

QCalendar::YearMonthDay QGregorianCalendar::partsFromJulian ( qint64 jd)
static

Definition at line 245 of file qgregoriancalendar.cpp.

References BaseJd, QRomanCalendrical::FiveMonths, FourCenturies, QRomanCalendrical::FourYears, and Q_ASSERT.

Referenced by QDate::addMonths(), QDate::addYears(), QDate::day(), QDate::daysInMonth(), QDateTimePrivate::expressUtcAsLocal(), QDate::getDate(), julianDayToDate(), millisToWithinRange(), QDate::month(), and QDate::year().

+ Here is the caller graph for this function:

◆ validParts()

bool QGregorianCalendar::validParts ( int year,
int month,
int day )
static

Definition at line 89 of file qgregoriancalendar.cpp.

References monthLength().

Referenced by QDate::isValid(), and julianFromParts().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ weekDayOfJulian()

int QGregorianCalendar::weekDayOfJulian ( qint64 jd)
static

Definition at line 94 of file qgregoriancalendar.cpp.

Referenced by QDate::dayOfWeek(), and matchCenturyToWeekday().

+ Here is the caller graph for this function:

◆ yearSharingWeekDays()

int QGregorianCalendar::yearSharingWeekDays ( QDate date)
static

Definition at line 172 of file qgregoriancalendar.cpp.

References date, QDate::day(), QCalendarBackend::dayOfWeek(), leapTest(), QDate::month(), Q_ASSERT, QDate::year(), and yearStartWeekDay().

Referenced by macDateToString(), and QSystemLocalePrivate::toString().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ yearStartWeekDay()

int QGregorianCalendar::yearStartWeekDay ( int year)
static

Definition at line 165 of file qgregoriancalendar.cpp.

Referenced by systemTimeYearMatching(), and yearSharingWeekDays().

+ Here is the caller graph for this function:

The documentation for this class was generated from the following files: