1/****************************************************************************
2**
3** Copyright (C) 2019 The Qt Company Ltd.
4** Contact: https://www.qt.io/licensing/
5**
6** This file is part of the QtCore module of the Qt Toolkit.
7**
8** $QT_BEGIN_LICENSE:LGPL$
9** Commercial License Usage
10** Licensees holding valid commercial Qt licenses may use this file in
11** accordance with the commercial license agreement provided with the
12** Software or, alternatively, in accordance with the terms contained in
13** a written agreement between you and The Qt Company. For licensing terms
14** and conditions see https://www.qt.io/terms-conditions. For further
15** information use the contact form at https://www.qt.io/contact-us.
16**
17** GNU Lesser General Public License Usage
18** Alternatively, this file may be used under the terms of the GNU Lesser
19** General Public License version 3 as published by the Free Software
20** Foundation and appearing in the file LICENSE.LGPL3 included in the
21** packaging of this file. Please review the following information to
22** ensure the GNU Lesser General Public License version 3 requirements
23** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
24**
25** GNU General Public License Usage
26** Alternatively, this file may be used under the terms of the GNU
27** General Public License version 2.0 or (at your option) the GNU General
28** Public license version 3 or any later version approved by the KDE Free
29** Qt Foundation. The licenses are as published by the Free Software
30** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
31** included in the packaging of this file. Please review the following
32** information to ensure the GNU General Public License requirements will
33** be met: https://www.gnu.org/licenses/gpl-2.0.html and
34** https://www.gnu.org/licenses/gpl-3.0.html.
35**
36** $QT_END_LICENSE$
37**
38****************************************************************************/
39
40#ifndef QCALENDAR_BACKEND_P_H
41#define QCALENDAR_BACKEND_P_H
42
43//
44// W A R N I N G
45// -------------
46//
47// This file is not part of the Qt API. It exists for the convenience
48// of calendar implementations. This header file may change from version to
49// version without notice, or even be removed.
50//
51// We mean it.
52//
53
54#include <QtCore/qobjectdefs.h>
55#include <QtCore/qcalendar.h>
56#include <QtCore/qstringlist.h>
57#include <QtCore/qstring.h>
58#include <QtCore/qmap.h>
59
60QT_BEGIN_NAMESPACE
61
62// Locale-related parts, mostly handled in ../text/qlocale.cpp
63struct QLocaleDataEntry {
64 quint16 index, size;
65};
66
67struct QCalendarLocale {
68 quint16 m_language_id, m_script_id, m_country_id;
69 // Month name indexes:
70 QLocaleDataEntry m_standalone_short;
71 QLocaleDataEntry m_standalone_long;
72 QLocaleDataEntry m_standalone_narrow;
73 QLocaleDataEntry m_short;
74 QLocaleDataEntry m_long;
75 QLocaleDataEntry m_narrow;
76};
77
78// Partial implementation, of methods with common forms, in qcalendar.cpp
79class Q_CORE_EXPORT QCalendarBackend
80{
81 friend class QCalendar;
82public:
83 virtual ~QCalendarBackend();
84 virtual QString name() const = 0;
85 virtual QCalendar::System calendarSystem() const;
86 // Date queries:
87 virtual int daysInMonth(int month, int year = QCalendar::Unspecified) const = 0;
88 virtual int daysInYear(int year) const;
89 virtual int monthsInYear(int year) const;
90 virtual bool isDateValid(int year, int month, int day) const;
91 // Properties of the calendar:
92 virtual bool isLeapYear(int year) const = 0;
93 virtual bool isLunar() const = 0;
94 virtual bool isLuniSolar() const = 0;
95 virtual bool isSolar() const = 0;
96 virtual bool isProleptic() const;
97 virtual bool hasYearZero() const;
98 virtual int maximumDaysInMonth() const;
99 virtual int minimumDaysInMonth() const;
100 virtual int maximumMonthsInYear() const;
101 // Julian Day conversions:
102 virtual bool dateToJulianDay(int year, int month, int day, qint64 *jd) const = 0;
103 virtual QCalendar::YearMonthDay julianDayToDate(qint64 jd) const = 0;
104 // Day of week and week numbering:
105 virtual int dayOfWeek(qint64 jd) const;
106
107 // Names of months and week-days (implemented in qlocale.cpp):
108 virtual QString monthName(const QLocale &locale, int month, int year,
109 QLocale::FormatType format) const;
110 virtual QString standaloneMonthName(const QLocale &locale, int month, int year,
111 QLocale::FormatType format) const;
112 virtual QString weekDayName(const QLocale &locale, int day,
113 QLocale::FormatType format) const;
114 virtual QString standaloneWeekDayName(const QLocale &locale, int day,
115 QLocale::FormatType format) const;
116
117 // Formatting of date-times (implemented in qlocale.cpp):
118 virtual QString dateTimeToString(QStringView format, const QDateTime &datetime,
119 const QDate &dateOnly, const QTime &timeOnly,
120 const QLocale &locale) const;
121
122 // Calendar enumeration by name:
123 static QStringList availableCalendars();
124
125protected:
126 QCalendarBackend(const QString &name, QCalendar::System system = QCalendar::System::User);
127
128 // Locale support:
129 virtual const QCalendarLocale *localeMonthIndexData() const = 0;
130 virtual const ushort *localeMonthData() const = 0;
131
132 bool registerAlias(const QString &name);
133
134private:
135 // QCalendar's access to its registry:
136 static const QCalendarBackend *fromName(QStringView name);
137 static const QCalendarBackend *fromName(QLatin1String name);
138 // QCalendar's access to singletons:
139 static const QCalendarBackend *fromEnum(QCalendar::System system);
140};
141
142QT_END_NAMESPACE
143
144#endif // QCALENDAR_BACKEND_P_H
145

source code of qtbase/src/corelib/time/qcalendarbackend_p.h