4#ifndef QCALENDARMATH_P_H
5#define QCALENDARMATH_P_H
18#include <QtCore/private/qglobal_p.h>
19#include <QtCore/QtAlgorithms>
28#define QCALMATH_ISPOW2(b) ((b > 0
) && !(b & (b - 1
)))
35template <
typename Int>
36inline constexpr bool isPowerOfTwo(Int b) {
return b > 0 && (b & (b - 1)) == 0; }
37#define QCALMATH_ISPOW2(b) QRoundingDownPrivate::isPowerOfTwo(b)
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
61template <
unsigned b,
typename Int, std::enable_if_t<(
int(b) < 2),
bool> =
true>
64 static_assert(b,
"Division by 0 is undefined");
66 static_assert(!b ||
int(b) > 0,
"Denominator is too big");
67 static_assert(
int(b) < 1 || b > 1,
"Division by 1 is fautous");
68 struct R { Int quotient; Int remainder; };
72template <
unsigned b,
typename Int,
77 struct R { Int quotient; Int remainder; };
78 if constexpr (std::is_signed_v<Int>) {
81 return R { Int(a /
int(b) - 1), Int(a %
int(b) - 1 +
int(b)) };
84 return R { Int(a /
int(b)), Int(a %
int(b)) };
87template <
unsigned b,
typename Int,
92 constexpr unsigned w = qCountTrailingZeroBits(b);
93 struct R { Int quotient; Int remainder; };
94 if constexpr (std::is_signed_v<Int>) {
96 return R { Int((a + 1) /
int(b) - 1), Int(a &
int(b - 1)) };
98 return R { Int(a >> w), Int(a &
int(b - 1)) };
101#undef QCALMATH_ISPOW2
104template <
unsigned b,
typename Int>
constexpr Int
qDiv(Int a) {
return qDivMod<b>(a).quotient; }
105template <
unsigned b,
typename Int>
constexpr Int
qMod(Int a) {
return qDivMod<b>(a).remainder; }
114inline constexpr unsigned FiveMonths = 31 + 30 + 31 + 30 + 31;
119 struct R { qint64 year; qint64 days; };
133 struct R {
int year;
int month;
int day; };
136 const auto month5Day = qDivMod<
FiveMonths>(5 * dayInYear + 2);
138 const auto yearMonth = qDivMod<12>(month5Day.quotient + 2);
139 return R { yearMonth.quotient, yearMonth.remainder + 1, qDiv<5>(month5Day.remainder) + 1 };
\macro Q_ATOMIC_INTnn_IS_SUPPORTED
The QCalendarBackend class provides basic calendaring functions.
The QGregorianCalendar class implements the Gregorian calendar.
The QJulianCalendar class provides Julian calendar system implementation.
The QMilankovicCalendar class provides Milanković calendar system implementation.
The QRomanCalendar class is a shared base for calendars based on the ancient Roman calendar.
const QCalendarBackend * fromEnum(QCalendar::System system)
QStringList availableCalendars()
const QCalendarBackend * fromName(QAnyStringView name)
void registerCustomBackend(QCalendarBackend *backend, const QStringList &names)
bool isGregorian(const QCalendarBackend *backend) const
bool isBeingDestroyed() const
const QCalendarBackend * fromIndex(size_t index)
QStringList backendNames(const QCalendarBackend *backend)
const QCalendarBackend * gregorian()
constexpr qint64 LeapDayGregorian1Bce
constexpr auto dayInYearToYmd(int dayInYear)
constexpr auto yearMonthToYearDays(int year, int month)
constexpr unsigned FourYears
constexpr unsigned FiveMonths
constexpr bool isPowerOfTwo(Int b)
constexpr Int qDiv(Int a)
constexpr Int qMod(Int a)
constexpr auto qDivMod(Int)
Q_GLOBAL_STATIC(QtPrivate::QCalendarRegistry, calendarRegistry)
#define QCALMATH_ISPOW2(b)
quint16 m_longMonthStandalone_size
QLocaleData::DataRange monthName(QLocale::FormatType type) const
quint16 m_shortMonthStandalone_idx
quint8 m_narrowMonthStandalone_size
quint8 m_shortMonthStandalone_size
quint16 m_longMonthStandalone_idx
quint16 m_narrowMonthStandalone_idx
QLocaleData::DataRange standaloneMonthName(QLocale::FormatType type) const
quint8 m_narrowMonth_size
quint16 m_narrowMonth_idx
bool operator()(QAnyStringView lhs, QAnyStringView rhs) const