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#ifndef QCALENDAR_BACKEND_P_H
5#define QCALENDAR_BACKEND_P_H
6
7//
8// W A R N I N G
9// -------------
10//
11// This file is not part of the Qt API. It exists for the convenience
12// of calendar implementations. This header file may change from version to
13// version without notice, or even be removed.
14//
15// We mean it.
16//
17
18#include <QtCore/qobjectdefs.h>
19#include <QtCore/qcalendar.h>
20#include <QtCore/qstringlist.h>
21#include <QtCore/qstring.h>
22#include <QtCore/qmap.h>
23#include <QtCore/qanystringview.h>
24#include <QtCore/private/qlocale_p.h>
25
26QT_BEGIN_NAMESPACE
27
28namespace QtPrivate {
29class QCalendarRegistry;
30}
31
32// Locale-related parts, mostly handled in ../text/qlocale.cpp
33
34struct QCalendarLocale {
35 quint16 m_language_id, m_script_id, m_territory_id;
36
37#define rangeGetter(name) \
38 QLocaleData::DataRange name() const { return { m_ ## name ## _idx, m_ ## name ## _size }; }
39
40 rangeGetter(longMonthStandalone) rangeGetter(longMonth)
41 rangeGetter(shortMonthStandalone) rangeGetter(shortMonth)
42 rangeGetter(narrowMonthStandalone) rangeGetter(narrowMonth)
43#undef rangeGetter
44
45 // Month name indexes:
46 quint16 m_longMonthStandalone_idx, m_longMonth_idx;
47 quint16 m_shortMonthStandalone_idx, m_shortMonth_idx;
48 quint16 m_narrowMonthStandalone_idx, m_narrowMonth_idx;
49
50 // Twelve long month names (separated by commas) can add up to more than 256
51 // QChars - e.g. kde_TZ gets to 264.
52 quint16 m_longMonthStandalone_size, m_longMonth_size;
53 quint8 m_shortMonthStandalone_size, m_shortMonth_size;
54 quint8 m_narrowMonthStandalone_size, m_narrowMonth_size;
55};
56
57// Partial implementation, of methods with common forms, in qcalendar.cpp
58class Q_CORE_EXPORT QCalendarBackend
59{
60 friend class QCalendar;
61 friend class QtPrivate::QCalendarRegistry;
62
63public:
64 virtual ~QCalendarBackend();
65 virtual QString name() const = 0;
66
67 QStringList names() const;
68
69 QCalendar::System calendarSystem() const;
70 QCalendar::SystemId calendarId() const { return m_id; }
71 // Date queries:
72 virtual int daysInMonth(int month, int year = QCalendar::Unspecified) const = 0;
73 virtual int daysInYear(int year) const;
74 virtual int monthsInYear(int year) const;
75 virtual bool isDateValid(int year, int month, int day) const;
76 // Properties of the calendar:
77 virtual bool isLeapYear(int year) const = 0;
78 virtual bool isLunar() const = 0;
79 virtual bool isLuniSolar() const = 0;
80 virtual bool isSolar() const = 0;
81 virtual bool isProleptic() const;
82 virtual bool hasYearZero() const;
83 virtual int maximumDaysInMonth() const;
84 virtual int minimumDaysInMonth() const;
85 virtual int maximumMonthsInYear() const;
86 // Julian Day conversions:
87 virtual bool dateToJulianDay(int year, int month, int day, qint64 *jd) const = 0;
88 virtual QCalendar::YearMonthDay julianDayToDate(qint64 jd) const = 0;
89 // Day of week and week numbering:
90 virtual int dayOfWeek(qint64 jd) const;
91
92 // Names of months and week-days (implemented in qlocale.cpp):
93 virtual QString monthName(const QLocale &locale, int month, int year,
94 QLocale::FormatType format) const;
95 virtual QString standaloneMonthName(const QLocale &locale, int month, int year,
96 QLocale::FormatType format) const;
97 virtual QString weekDayName(const QLocale &locale, int day,
98 QLocale::FormatType format) const;
99 virtual QString standaloneWeekDayName(const QLocale &locale, int day,
100 QLocale::FormatType format) const;
101
102 // Formatting of date-times (implemented in qlocale.cpp):
103 virtual QString dateTimeToString(QStringView format, const QDateTime &datetime,
104 QDate dateOnly, QTime timeOnly,
105 const QLocale &locale) const;
106
107 bool isGregorian() const;
108
109 QCalendar::SystemId registerCustomBackend(const QStringList &names);
110
111 // Calendar enumeration by name:
112 static QStringList availableCalendars();
113
114protected:
115 // Locale support:
116 virtual const QCalendarLocale *localeMonthIndexData() const = 0;
117 virtual const char16_t *localeMonthData() const = 0;
118
119private:
120 QCalendar::SystemId m_id;
121
122 void setIndex(size_t index);
123
124 // QCalendar's access to its registry:
125 static const QCalendarBackend *fromName(QAnyStringView name);
126 static const QCalendarBackend *fromId(QCalendar::SystemId id);
127 // QCalendar's access to singletons:
128 static const QCalendarBackend *fromEnum(QCalendar::System system);
129 static const QCalendarBackend *gregorian();
130};
131
132QT_END_NAMESPACE
133
134#endif // QCALENDAR_BACKEND_P_H
135

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