Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Toggle main menu visibility
Loading...
Searching...
No Matches
qmilankoviccalendar.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
// Qt-Security score:significant reason:default
4
5
#
include
"qglobal.h"
6
#
include
"qmilankoviccalendar_p.h"
7
#
include
"qcalendarmath_p.h"
8
9
#
include
<
QtCore
/
qdatetime
.
h
>
10
11
QT_BEGIN_NAMESPACE
12
13
using
namespace
QRoundingDown;
14
15
/*!
16
\since 5.14
17
\internal
18
19
\class QMilankovicCalendar
20
\inmodule QtCore
21
\brief The QMilankovicCalendar class provides Milanković calendar system
22
implementation.
23
24
The Revised Julian calendar, also known as the Milanković calendar, or,
25
less formally, new calendar, is a calendar, developed and proposed by the
26
Serbian scientist Milutin Milanković in 1923, which effectively discontinued
27
the 340 years of divergence between the naming of dates sanctioned by those
28
Eastern Orthodox churches adopting it and the Gregorian calendar that has
29
come to predominate worldwide. This calendar was intended to replace the
30
ecclesiastical calendar based on the Julian calendar hitherto in use by all
31
of the Eastern Orthodox Church. The Revised Julian calendar temporarily
32
aligned its dates with the Gregorian calendar proclaimed in 1582 by Pope
33
Gregory XIII for adoption by the Christian world. The calendar has been
34
adopted by the Orthodox churches of Constantinople, Albania, Alexandria,
35
Antioch, Bulgaria, Cyprus, Greece, Poland, and Romania.
36
37
Source: \l {https://en.wikipedia.org/wiki/Revised_Julian_calendar}{Wikipedia
38
page on Milanković Calendar}
39
*/
40
41
QString QMilankovicCalendar::name()
const
42
{
43
return
QStringLiteral(
"Milankovic"
);
44
}
45
46
QStringList QMilankovicCalendar::nameList()
47
{
48
return
{ QStringLiteral(
"Milankovic"
) };
49
}
50
51
bool
QMilankovicCalendar::isLeapYear(
int
year)
const
52
{
53
if
(year == QCalendar::Unspecified)
54
return
false
;
55
if
(year <= 0)
56
++year;
57
if
(qMod<4>(year))
58
return
false
;
59
const
auto
yeardm = qDivMod<100>(year);
60
if
(yeardm.remainder == 0) {
61
const
qint16 century = qMod<9>(yeardm.quotient);
62
if
(century != 2 && century != 6)
63
return
false
;
64
}
65
return
true
;
66
}
67
68
using
namespace
QRomanCalendrical
;
69
// End a Milankovic nine-century cycle on 1 BC, Feb 28 (Gregorian Feb 29):
70
constexpr
qint64
MilankovicBaseJd
= LeapDayGregorian1Bce;
71
// Leap years every 4 years, except for 7 turn-of-century years per nine centuries:
72
constexpr
unsigned
NineCenturies
= 365 * 900 + 900 / 4 - 7;
73
// When the turn-of-century is a leap year, the century has 25 leap years in it:
74
constexpr
unsigned
LeapCentury
= 365 * 100 + 25;
75
76
bool
QMilankovicCalendar::dateToJulianDay(
int
year,
int
month,
int
day, qint64 *jd)
const
77
{
78
Q_ASSERT(jd);
79
if
(!isDateValid(year, month, day))
80
return
false
;
81
82
const
auto
yearDays = yearMonthToYearDays(year, month);
83
const
auto
centuryYear = qDivMod<100>(yearDays.year);
84
const
qint64 fromYear = qDiv<9>(NineCenturies * centuryYear.quotient + 6)
85
+ qDiv<100>(LeapCentury * centuryYear.remainder);
86
*jd = fromYear + yearDays.days + day + MilankovicBaseJd;
87
return
true
;
88
}
89
90
QCalendar::YearMonthDay QMilankovicCalendar::julianDayToDate(qint64 jd)
const
91
{
92
using
Bound = std::numeric_limits<
int
>;
93
constexpr
qint64 maxInt = Bound::max();
94
95
const
auto
century9Day = qDivMod<NineCenturies>(9 * (jd - MilankovicBaseJd) - 7);
96
// Its remainder changes by 9 per day, except roughly once per century.
97
const
auto
year100Day = qDivMod<LeapCentury>(100 * qDiv<9>(century9Day.remainder) + 99);
98
// Its remainder changes by 100 per day, except roughly once per year.
99
const
auto
ymd = dayInYearToYmd(qDiv<100>(year100Day.remainder));
100
101
const
qint64 y = 100 * century9Day.quotient + year100Day.quotient + ymd.year;
102
// We'll be subtracting 1 if negative, so -maxInt is the lower bound, not Bound::min().
103
if
(y > maxInt || y < -maxInt)
104
return
{};
105
106
int
year =
static_cast
<
int
>(y);
107
return
QCalendar::YearMonthDay(year > 0 ? year : year - 1, ymd.month, ymd.day);
108
}
109
110
QT_END_NAMESPACE
QRomanCalendrical
Definition
qcalendarmath_p.h:112
QT_BEGIN_NAMESPACE
Combined button and popup list for selecting options.
Definition
qsequentialanimationgroup.cpp:47
MilankovicBaseJd
constexpr qint64 MilankovicBaseJd
Definition
qmilankoviccalendar.cpp:70
NineCenturies
constexpr unsigned NineCenturies
Definition
qmilankoviccalendar.cpp:72
LeapCentury
constexpr unsigned LeapCentury
Definition
qmilankoviccalendar.cpp:74
qtbase
src
corelib
time
qmilankoviccalendar.cpp
Generated on
for Qt by
1.18.0