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
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
4#include "qglobal.h"
5#include "qjuliancalendar_p.h"
7#include "qcalendarmath_p.h"
8
9#include <QtCore/qdatetime.h>
10
12
13using namespace QRoundingDown;
14
42{
43 return QStringLiteral("Julian");
44}
45
47{
48 return { QStringLiteral("Julian") };
49}
50
51bool QJulianCalendar::isLeapYear(int year) const
52{
53 if (year == QCalendar::Unspecified || !year)
54 return false;
55
56 return qMod<4>(year < 0 ? year + 1 : year) == 0;
57}
58
59// Julian Day 0 was January the first in the proleptic Julian calendar's 4713 BC.
60using namespace QRomanCalendrical;
61// End a Julian four-year cycle on 1 BC's leap day (Gregorian Feb 27th):
63
64bool QJulianCalendar::dateToJulianDay(int year, int month, int day, qint64 *jd) const
65{
66 Q_ASSERT(jd);
67 if (!isDateValid(year, month, day))
68 return false;
69
70 const auto yearDays = yearMonthToYearDays(year, month);
71 *jd = qDiv<4>(FourYears * yearDays.year) + yearDays.days + day + JulianBaseJd;
72 return true;
73}
74
76{
77 const auto year4Day = qDivMod<FourYears>(4 * (jd - JulianBaseJd) - 1);
78 // Its remainder changes by 4 per day, except at roughly yearly quotient steps.
79 const auto ymd = dayInYearToYmd(qDiv<4>(year4Day.remainder));
80 const int y = year4Day.quotient + ymd.year;
81 return QCalendar::YearMonthDay(y > 0 ? y : y - 1, ymd.month, ymd.day);
82}
83
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
QString name() const override
Returns the primary name of the calendar.
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.
static QStringList nameList()
QCalendar::YearMonthDay julianDayToDate(qint64 jd) const override
Computes the year, month, and day in this calendar for the given Julian day number jd.
\inmodule QtCore
\macro QT_RESTRICTED_CAST_FROM_ASCII
Definition qstring.h:129
constexpr qint64 LeapDayGregorian1Bce
constexpr auto dayInYearToYmd(int dayInYear)
constexpr auto yearMonthToYearDays(int year, int month)
constexpr unsigned FourYears
Combined button and popup list for selecting options.
constexpr qint64 JulianBaseJd
GLint y
#define Q_ASSERT(cond)
Definition qrandom.cpp:47
#define QStringLiteral(str)
long long qint64
Definition qtypes.h:60