6.0.0-rc4Source

QCalendar Class

The QCalendar class describes calendar systems. More…

Header#include <QCalendar>
CMaketarget_link_libraries(app PRIVATE Nt::Core)
ModuleNt Core C++ Classes
Since5.14

List of all members, including inherited members

Public Types

enumSystem

Public Functions

QCalendar()
QCalendar(System system)
QCalendar(QAnyStringView name)
boolisValid() const
intdaysInMonth(int month, int year = Unspecified) const
intdaysInYear(int year) const
intmonthsInYear(int year) const
boolisDateValid(int year, int month, int day) const
boolisLeapYear(int year) const
boolisGregorian() const
boolisLunar() const
boolisLuniSolar() const
boolisSolar() const
boolisProleptic() const
boolhasYearZero() const
intmaximumDaysInMonth() const
intminimumDaysInMonth() const
intmaximumMonthsInYear() const
QStringname() const
QDatedateFromParts(int year, int month, int day) const
QDatedateFromParts(const YearMonthDay &parts) const
YearMonthDaypartsFromDate(QDate date) const
intdayOfWeek(QDate date) const
QStringmonthName(const QLocale &locale, int month, int year = Unspecified, QLocale::FormatType format = QLocale::LongFormat) const
QStringstandaloneMonthName(const QLocale &locale, int month, int year = Unspecified, QLocale::FormatType format = QLocale::LongFormat) const
QStringweekDayName(const QLocale &locale, int day, QLocale::FormatType format = QLocale::LongFormat) const
QStringstandaloneWeekDayName(const QLocale &locale, int day, QLocale::FormatType format = QLocale::LongFormat) const

Static Public Members

Detailed Description

QDate stores a day as a Julian day number, independent of any calendar. A QCalendar converts between that day and its year, month and day in a calendar system, and names the months:

const QCalendar persian(QCalendar::System::Jalali);
const QDate nowruz = persian.dateFromParts(1403, 1, 1); // 2024-03-20
const QCalendar::YearMonthDay parts = persian.partsFromDate(QDate(2024, 6, 1));
int day = QDate(2024, 6, 1).day(persian);                // 12

As in Qt, the calendars have no year zero: year -1 (1 BCE) is directly followed by year 1.

See also QDate and QLocale.

Differences from Qt

Only the built-in systems exist; custom calendars cannot be registered and the SystemId API is not provided. The Jalali calendar uses the 33-year arithmetic leap rule and the Islamic civil calendar the tabular rule, as in Qt. Month names of the Jalali and Islamic calendars are in English. QDate::toString() and QLocale have no QCalendar overloads.

Member Type Documentation

enum QCalendar::System

ConstantDescription
QCalendar::GregorianThe proleptic Gregorian calendar, which QDate uses by default.
QCalendar::JulianThe proleptic Julian calendar.
QCalendar::MilankovicThe Revised Julian calendar of Milutin Milanković.
QCalendar::JalaliThe Solar Hijri (Persian) calendar.
QCalendar::IslamicCivilThe tabular Islamic civil calendar.

Member Function Documentation

QCalendar::QCalendar()

Constructs a Gregorian calendar.

[explicit] QCalendar::QCalendar(System system)

Constructs a calendar of the system system. The calendar is invalid for System::User.

[explicit] QCalendar::QCalendar(QAnyStringView name)

Constructs the calendar called name, ignoring case: "Gregorian", "Julian", "Milankovic", "Jalali" (or "Persian") and "Islamic Civil" (or "islamic-civil", "islamicc"). The calendar is invalid if the name is not known.

See also availableCalendars().

[static] QStringList QCalendar::availableCalendars()

Returns the names of the supported calendars.

QDate QCalendar::dateFromParts(int year, int month, int day) const

Returns the date of day of month of year in the calendar, or an invalid date if it does not exist.

See also partsFromDate().

QDate QCalendar::dateFromParts(const YearMonthDay &parts) const

This is an overloaded function.

Returns the date of parts in the calendar.

int QCalendar::dayOfWeek(QDate date) const

Returns the day of the week of date, from 1 (Monday) to 7 (Sunday), or 0 for an invalid date. The week is the same in every supported calendar.

int QCalendar::daysInMonth(int month, int year = Unspecified) const

Returns the number of days in month of year, or 0 if the month does not exist. If year is Unspecified, the largest length the month can have is returned.

int QCalendar::daysInYear(int year) const

Returns the number of days in year, or 0 for an invalid year.

bool QCalendar::hasYearZero() const

Returns false; the supported calendars have no year zero.

bool QCalendar::isDateValid(int year, int month, int day) const

Returns true if day of month of year exists in the calendar; otherwise returns false.

bool QCalendar::isGregorian() const

Returns true if the calendar is the Gregorian calendar; otherwise returns false.

bool QCalendar::isLeapYear(int year) const

Returns true if year is a leap year of the calendar; otherwise returns false.

bool QCalendar::isLunar() const

Returns true if the months of the calendar follow the moon, which is the case for the Islamic civil calendar; otherwise returns false.

bool QCalendar::isLuniSolar() const

Returns false; none of the supported calendars is lunisolar.

bool QCalendar::isProleptic() const

Returns true if the calendar is extended to dates before it was introduced, as the Gregorian, Julian and Milanković calendars are; otherwise returns false.

bool QCalendar::isSolar() const

Returns true if the years of the calendar follow the sun; otherwise returns false.

bool QCalendar::isValid() const

Returns true if the calendar is one of the supported systems; otherwise returns false.

int QCalendar::maximumDaysInMonth() const

Returns the largest number of days a month of the calendar can have.

int QCalendar::maximumMonthsInYear() const

Returns the largest number of months a year of the calendar can have, 12.

int QCalendar::minimumDaysInMonth() const

Returns the smallest number of days a month of the calendar can have.

QString QCalendar::monthName(const QLocale &locale, int month, int year = Unspecified, QLocale::FormatType format = QLocale::LongFormat) const

Returns the name of month in the form format. The Gregorian, Julian and Milanković calendars use the month names of locale; the Jalali and Islamic calendars use English names. year is accepted for compatibility.

int QCalendar::monthsInYear(int year) const

Returns the number of months in year: 12 for every supported system, or 0 for an invalid year.

QString QCalendar::name() const

Returns the name of the calendar, such as "Gregorian", or an empty string if it is invalid.

YearMonthDay QCalendar::partsFromDate(QDate date) const

Returns the year, month and day of date in the calendar, or an invalid YearMonthDay if the date or the calendar is invalid.

See also dateFromParts().

QString QCalendar::standaloneMonthName(const QLocale &locale, int month, int year = Unspecified, QLocale::FormatType format = QLocale::LongFormat) const

Returns the name of month in the form format, as used on its own. See monthName() for locale and year.

QString QCalendar::standaloneWeekDayName(const QLocale &locale, int day, QLocale::FormatType format = QLocale::LongFormat) const

Returns the name of day (1 is Monday) in the form format in locale, as used on its own.

QString QCalendar::weekDayName(const QLocale &locale, int day, QLocale::FormatType format = QLocale::LongFormat) const

Returns the name of day (1 is Monday) in the form format in locale.

Member Variable Documentation

[static, constexpr] int QCalendar::Unspecified

A value meaning "not specified", for the optional year argument of some functions.