7#include <QtCore/qdatetime.h>
14static_assert(qDivMod<2>(-86400).quotient == -43200);
15static_assert(qDivMod<2>(-86400).remainder == 0);
16static_assert(qDivMod<86400>(-86400).quotient == -1);
17static_assert(qDivMod<86400>(-86400).remainder == 0);
18static_assert(qDivMod<86400>(-86401).quotient == -2);
19static_assert(qDivMod<86400>(-86401).remainder == 86399);
20static_assert(qDivMod<86400>(-100000).quotient == -2);
21static_assert(qDivMod<86400>(-100000).remainder == 72800);
22static_assert(qDivMod<86400>(-172799).quotient == -2);
23static_assert(qDivMod<86400>(-172799).remainder == 1);
24static_assert(qDivMod<86400>(-172800).quotient == -2);
25static_assert(qDivMod<86400>(-172800).remainder == 0);
74 return year % 4 == 0 && (year % 100 != 0 || year % 400 == 0);
80 if (month < 1 || month > 12)
86 return 30 | ((month & 1) ^ (month >> 3));
91 return year && 0 < day && day <=
monthLength(month, year);
96 return int(qMod<7>(jd) + 1);
126 int year = parts.
year < 0 ? parts.
year + 1 : parts.
year;
129 const auto yearSplit = qDivMod<100>(year - (parts.
month < 3 ? 1 : 0));
130 const int centuryMod4 = qMod<4>(yearSplit.quotient);
132 static_assert(qMod<7>(36524) == 5);
135 if (qMod<7>(diff * 4 + centuryMod4) < 4) {
137 year += (((qMod<7>(diff) + 3) / 2) % 4 - 1) * 100;
145 }
else if (parts.
month == 2 && parts.
day == 29) {
146 int year = parts.
year < 0 ? parts.
year + 1 : parts.
year;
148 const auto yearSplit = qDivMod<100>(year);
149 if (!yearSplit.remainder) {
150 const auto centuryMod4 = qMod<4>(yearSplit.quotient);
152 if (centuryMod4 == 1)
155 year += (4 - centuryMod4) * 100;
162 return (std::numeric_limits<qint64>::min)();
168 const int y = year - (year < 0 ? 800 : 801);
169 return qMod<7>(
y + qDiv<4>(
y) - qDiv<100>(
y) + qDiv<400>(
y)) + 1;
189 static_assert((400 * 365 + 97) % 7 == 0);
196 int res = (year < 1970
197 ? 2400 - (2000 - (year < 0 ? year + 1 : year)) % 400
198 : year > 2399 ? 2000 + (year - 2000) % 400 : year);
201 const int lastTwo =
res % 100;
203 Q_ASSERT(lastTwo && !(lastTwo & ~31));
205 static constexpr int usual[] = { 2198, 2199, 2098, 2099, 2399, 2298, 2299 };
206 static constexpr int leaps[] = { 2396, 2284, 2296, 2184, 2196, 2084, 2096 };
240 const qint64 y = yearDays.year;
241 const qint64 fromYear = 365 *
y + qDiv<4>(
y) - qDiv<100>(
y) + qDiv<400>(
y);
242 return fromYear + yearDays.days + day +
BaseJd;
248 const qint64 century = qDiv<FourCenturies>(4 * dayNumber - 1);
249 const int dayInCentury = dayNumber - qDiv<4>(
FourCenturies * century);
251 const int yearInCentury = qDiv<FourYears>(4 * dayInCentury - 1);
252 const int dayInYear = dayInCentury - qDiv<4>(
FourYears * yearInCentury);
253 const int m = qDiv<FiveMonths>(5 * dayInYear - 3);
256 const int yearOffset =
m < 10 ? 0 : 1;
258 const int y = 100 * century + yearInCentury + yearOffset;
259 const int month =
m + 3 - 12 * yearOffset;
260 const int day = dayInYear - qDiv<5>(
FiveMonths *
m + 2);
virtual int dayOfWeek(qint64 jd) const
Returns the day of the week for the given Julian Day Number jd.
\inmodule QtCore \reentrant
int month() const
This is an overloaded member function, provided for convenience. It differs from the above function o...
int day() const
This is an overloaded member function, provided for convenience. It differs from the above function o...
int year() const
This is an overloaded member function, provided for convenience. It differs from the above function o...
qint64 matchCenturyToWeekday(const QCalendar::YearMonthDay &parts, int dow) const override
static std::optional< qint64 > julianFromParts(int year, int month, int day)
static int yearStartWeekDay(int year)
QCalendar::YearMonthDay julianDayToDate(qint64 jd) const override
Computes the year, month, and day in this calendar for the given Julian day number jd.
static int monthLength(int month, int year)
static QStringList nameList()
static bool leapTest(int year)
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.
QString name() const override
Returns the primary name of the calendar.
static QCalendar::YearMonthDay partsFromJulian(qint64 jd)
static bool validParts(int year, int month, int day)
static int yearSharingWeekDays(QDate date)
bool isLeapYear(int year) const override
Returns true if the specified year is a leap year for this calendar.
static int weekDayOfJulian(qint64 jd)
\macro QT_RESTRICTED_CAST_FROM_ASCII
constexpr qint64 LeapDayGregorian1Bce
constexpr auto yearMonthToYearDays(int year, int month)
constexpr unsigned FourYears
constexpr unsigned FiveMonths
Combined button and popup list for selecting options.
constexpr unsigned FourCenturies
#define QStringLiteral(str)