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
qislamiccivilcalendar.cpp
Go to the documentation of this file.
1// Copyright (C) 2021 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
4#include "qglobal.h"
6#include "qcalendarmath_p.h"
7
9
10using namespace QRoundingDown;
11
39{
40 return QStringLiteral("Islamic Civil");
41}
42
44{
45 return {
46 QStringLiteral("Islamic Civil"),
47 QStringLiteral("islamic-civil"), // CLDR name
48 QStringLiteral("islamicc"), // old CLDR name, still (2018) used by Mozilla
49 // Until we have a concrete implementation that knows all the needed ephemerides:
50 QStringLiteral("Islamic"),
51 };
52}
53
55{
56 if (year == QCalendar::Unspecified)
57 return false;
58 if (year < 0)
59 ++year;
60 return qMod<30>(year * 11 + 14) < 11;
61}
62
63// First day of first year (Gregorian 622 CE July 19th) is the base date here:
64constexpr qint64 EpochJd = 1948440;
65// Each 30 years has 11 leap years of 355 days and 19 ordinary years of 354:
66constexpr unsigned ThirtyYears = 11 * 355 + 19 * 354;
67// The first eleven months of the year alternate 30, 29, ..., 29, 30 days in length.
68constexpr unsigned ElevenMonths = 6 * 30 + 5 * 29;
69
70bool QIslamicCivilCalendar::dateToJulianDay(int year, int month, int day, qint64 *jd) const
71{
72 Q_ASSERT(jd);
73 if (!isDateValid(year, month, day))
74 return false;
75
76 *jd = qDiv<30>(qint64(ThirtyYears) * (year > 0 ? year - 1 : year) + 14)
77 + qDiv<11>(ElevenMonths * (month - 1) + 5)
78 + day + EpochJd - 1;
79 return true;
80}
81
83{
84 const auto year30Day = qDivMod<ThirtyYears>(30 * (jd - EpochJd) + 15);
85 // Its remainder changes by 30 per day, except roughly yearly.
86 const auto month11Day = qDivMod<ElevenMonths>(11 * qDiv<30>(year30Day.remainder) + 5);
87 // Its remainder changes by 11 per day except roughly monthly.
88 const int month = month11Day.quotient + 1;
89 const int day = qDiv<11>(month11Day.remainder) + 1;
90 const int y = year30Day.quotient + 1;
91 return QCalendar::YearMonthDay(y > 0 ? y : y - 1, month, day);
92}
93
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 retu...
@ Unspecified
Definition qcalendar.h:57
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.
QString name() const override
Returns the primary name of the calendar.
QCalendar::YearMonthDay julianDayToDate(qint64 jd) const override
Computes the year, month, and day in this calendar for the given Julian day number jd.
static QStringList nameList()
\inmodule QtCore
\macro QT_RESTRICTED_CAST_FROM_ASCII
Definition qstring.h:129
Combined button and popup list for selecting options.
constexpr unsigned ElevenMonths
constexpr qint64 EpochJd
constexpr unsigned ThirtyYears
GLint y
#define Q_ASSERT(cond)
Definition qrandom.cpp:47
#define QStringLiteral(str)
long long qint64
Definition qtypes.h:60