Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
qtimezonelocale_p.h
Go to the documentation of this file.
1// Copyright (C) 2024 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#ifndef QTIMEZONELOCALE_P_H
6#define QTIMEZONELOCALE_P_H
7
8//
9// W A R N I N G
10// -------------
11//
12// This file is not part of the Qt API. It exists for the convenience
13// of internal files. This header file may change from version to version
14// without notice, or even be removed.
15//
16// We mean it.
17//
18#include <private/qglobal_p.h>
19
20#include <QtCore/qstring.h>
21#include <QtCore/qtimezone.h>
22#if QT_CONFIG(datestring)
23# include "private/qttemporalpattern_p.h"
24#endif
25
26#if QT_CONFIG(icu)
27#include <unicode/ucal.h>
28#else
29#include <QtCore/private/qlocale_p.h> // for DataRange
30#endif
31
34// #define QT_CLDR_ZONE_DEBUG
35
36QT_BEGIN_NAMESPACE
37
38namespace QtTimeZoneLocale {
39#if QT_CONFIG(icu)
42 const QByteArray &localeCode);
43
44bool ucalKnownTimeZoneId(const QString &id);
45#else
46
47QList<QByteArrayView> ianaIdsForTerritory(QLocale::Territory territory);
48
49QList<qsizetype> fallbackLocalesFor(qsizetype index); // qlocale.cpp
50
51#if QT_CONFIG(datestring)
52// See comments in QTZL.cpp; qlocale.cpp has a fallback implementation.
55 const QDateTime &when, int offsetSeconds);
56#endif // datestring
57
58// Define data types for QTZL_data_p.h
59
60// Accessor methods returning DataRange:
61#define rangeGetter(name)
62 constexpr QLocaleData::DataRange name() const
63 { return { m_ ## name ## _idx, m_ ## name ## _size }; }
64// Indices of starts of formats within their tables:
65#define declFieldIndex(name) quint16 m_ ## name ## _idx;
66#define declBigFieldIndex(name) quint32 m_ ## name ## _idx;
67// Lengths of formats:
68#define declFieldSize(name) quint8 m_ ## name ## _size;
69// Generic, standard, daylight-saving triples:
70#define forEachNameType(X, form) X(form ## Generic) X(form ## Standard) X(form ## DaylightSaving)
71// Mapping TimeType to the appropriate one of those:
72#define timeTypeRange(form)
73 constexpr QLocaleData::DataRange form ## Name(QTimeZone::TimeType timeType) const
74 {
75 switch (timeType) {
76 case QTimeZone::StandardTime: return form ## Standard();
77 case QTimeZone::DaylightTime: return form ## DaylightSaving();
78 case QTimeZone::GenericTime: return form ## Generic();
79 }
80 Q_UNREACHABLE_RETURN({});
81 }
82// Mostly form is short or long and we want to append Name.
83// See kludge below for regionFormat, for which that's not the name the method wants.
84
86{
87#ifdef QT_CLDR_ZONE_DEBUG
88 // Only included when this define is set, for the sake of asserting
89 // consistency with QLocaleData at matching index in tables.
91#endif
92
93 // Indices for this locale:
94 quint32 m_exemplarTableStart; // first LocaleZoneExemplar
95 quint32 m_metaLongTableStart; // first LocaleMetaZoneLongNames
96 quint16 m_metaShortTableStart; // first LocaleMetaZoneShortNames
97 quint16 m_zoneTableStart; // first LocaleZoneNames
98
99 // Zone-independent formats:
100#define forEachField(X)
101 X(posHourFormat) X(negHourFormat) X(offsetGmtFormat) X(fallbackFormat)
102 forEachNameType(X, regionFormat)
103 // Hour formats: HH is hour, mm is minutes (always use two digits for each).
104 // GMT format: %0 is an hour format's result.
105 // Region formats: %0 is exemplar city or territory.
106 // Fallback format: %0 is exemplar city or territory, %1 is meta-zone name.
107
111
112#undef forEachField
113#define regionFormatName regionFormatRange // kludge naming
114 timeTypeRange(regionFormat)
115#undef regionFormatName
116};
117
118// Sorted by localeIndex, then ianaIdIndex
120{
121 quint16 localeIndex; // Index in locale data tables
122 quint16 ianaIdIndex; // Location in IANA ID table
123 constexpr QByteArrayView ianaId() const; // Defined in QTZL.cpp
124 rangeGetter(exemplarCity);
127};
128
129// Sorted by localeIndex, then ianaIdIndex
131{
132 quint16 localeIndex; // Index in locale data tables
133 quint16 ianaIdIndex; // Location in IANA ID table
134 constexpr QByteArrayView ianaId() const; // Defined in QTZL.cpp
135 constexpr QLocaleData::DataRange name(QTimeZone::NameType nameType,
136 QTimeZone::TimeType timeType) const
137 {
138 return nameType == QTimeZone::ShortName ? shortName(timeType) : longName(timeType);
139 }
140 timeTypeRange(long)
141 timeTypeRange(short)
142#define forEach32BitField(X) forEachNameType(X, long)
143#define forEach16BitField(X) forEachNameType(X, short)
144#define forEachField(X) forEach32BitField(X) forEach16BitField(X)
145 // Localized name of exemplar city for zone.
146 // Long and short localized names (length zero for unspecified) for the zone
147 // in its generic, standard and daylight-saving forms.
148
153
154#undef forEachField
155#undef forEach16BitField
156#undef forEach32BitField
157};
158
159// Sorted by localeIndex, then metaIdIndex
161{
162 quint16 localeIndex; // Index in locale data tables
163 quint16 metaIdIndex; // As for MetaZoneData metaZoneTable[].
164 timeTypeRange(long)
165#define forEachField(X) forEachNameType(X, long)
166 // Long localized names (length zero for unspecified) for the
167 // metazone in its generic, standard and daylight-saving forms.
168
172
173#undef forEachField
174};
175
176// Sorted by localeIndex, then metaIdIndex
178{
179 quint16 localeIndex; // Index in locale data tables
180 quint16 metaIdIndex; // metaZoneTable[metaZoneKey - 1].metaIdIndex
181 timeTypeRange(short)
182#define forEachField(X) forEachNameType(X, short)
183 // Short localized names (length zero for unspecified) for the
184 // metazone in its generic, standard and daylight-saving forms.
185
189
190#undef forEachField
191};
192
193#undef timeTypeRange
194#undef forEachNameType
195#undef declFieldSize
196#undef declFieldIndex
197#undef rangeGetter
198#endif
199} // QtTimeZoneLocale
200
201QT_END_NAMESPACE
202
203#endif // QTIMEZONELOCALE_P_H
QList< qsizetype > fallbackLocalesFor(qsizetype index)
QList< QByteArrayView > ianaIdsForTerritory(QLocale::Territory territory)
QT_REQUIRE_CONFIG(animation)
#define rangeGetter(name)
Definition qlocale_p.h:640
#define forEachField(X)
#define timeTypeRange(form)
QT_REQUIRE_CONFIG(timezone_locale)
#define forEach16BitField(X)
#define forEach32BitField(X)
static bool ucalOffsetsAtTime(UCalendar *m_ucal, qint64 atMSecsSinceEpoch, int *utcOffset, int *dstOffset)
static int ucalDaylightOffset(const QByteArray &id)
static QList< QByteArray > uenumToIdList(UEnumeration *uenum)
QT_REQUIRE_CONFIG(timezone)
constexpr QByteArrayView ianaId() const
constexpr QLocaleData::DataRange name(QTimeZone::NameType nameType, QTimeZone::TimeType timeType) const
constexpr QByteArrayView ianaId() const