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
qjuliancalendar.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
"qjuliancalendar_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 QJulianCalendar
20
\inmodule QtCore
21
\brief The QJulianCalendar class provides Julian calendar system
22
implementation.
23
24
\section1 Julian Calendar
25
26
The Julian calendar, proposed by Julius Caesar in 46 BC (708 AUC), was a
27
reform of the Roman calendar. It took effect on 1 January 45 BC (AUC 709),
28
by edict. It was the predominant calendar in the Roman world, most of
29
Europe, and in European settlements in the Americas and elsewhere, until it
30
was refined and gradually replaced by the Gregorian calendar,
31
promulgated in 1582 by Pope Gregory XIII.
32
33
The Julian calendar gains against the mean tropical year at the rate of one
34
day in 128 years. For the Gregorian calendar, the figure is one day in
35
3030 years. The difference in the average length of the year
36
between Julian (365.25 days) and Gregorian (365.2425 days) is 0.002%.
37
38
Source: \l {https://en.wikipedia.org/wiki/Julian_calendar}{Wikipedia page on
39
Julian Calendar}
40
*/
41
42
QString QJulianCalendar::name()
const
43
{
44
return
QStringLiteral(
"Julian"
);
45
}
46
47
QStringList QJulianCalendar::nameList()
48
{
49
return
{ QStringLiteral(
"Julian"
) };
50
}
51
52
bool
QJulianCalendar::isLeapYear(
int
year)
const
53
{
54
if
(year == QCalendar::Unspecified || !year)
55
return
false
;
56
57
return
qMod<4>(year < 0 ? year + 1 : year) == 0;
58
}
59
60
// Julian Day 0 was January the first in the proleptic Julian calendar's 4713 BC.
61
using
namespace
QRomanCalendrical
;
62
// End a Julian four-year cycle on 1 BC's leap day (Gregorian Feb 27th):
63
constexpr
qint64
JulianBaseJd
= LeapDayGregorian1Bce - 2;
64
65
bool
QJulianCalendar::dateToJulianDay(
int
year,
int
month,
int
day, qint64 *jd)
const
66
{
67
Q_ASSERT(jd);
68
if
(!isDateValid(year, month, day))
69
return
false
;
70
71
const
auto
yearDays = yearMonthToYearDays(year, month);
72
*jd = qDiv<4>(FourYears * yearDays.year) + yearDays.days + day + JulianBaseJd;
73
return
true
;
74
}
75
76
QCalendar::YearMonthDay QJulianCalendar::julianDayToDate(qint64 jd)
const
77
{
78
const
auto
year4Day = qDivMod<FourYears>(4 * (jd - JulianBaseJd) - 1);
79
// Its remainder changes by 4 per day, except at roughly yearly quotient steps.
80
const
auto
ymd = dayInYearToYmd(qDiv<4>(year4Day.remainder));
81
const
int
y = year4Day.quotient + ymd.year;
82
return
QCalendar::YearMonthDay(y > 0 ? y : y - 1, ymd.month, ymd.day);
83
}
84
85
QT_END_NAMESPACE
QRomanCalendrical
Definition
qcalendarmath_p.h:112
QT_BEGIN_NAMESPACE
Combined button and popup list for selecting options.
Definition
qsequentialanimationgroup.cpp:47
JulianBaseJd
constexpr qint64 JulianBaseJd
Definition
qjuliancalendar.cpp:63
qtbase
src
corelib
time
qjuliancalendar.cpp
Generated on
for Qt by
1.18.0