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
4#ifndef QTIMEZONELOCALE_P_H
5#define QTIMEZONELOCALE_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 internal files. This header file may change from version to version
13// without notice, or even be removed.
14//
15// We mean it.
16//
17#include <private/qglobal_p.h>
18
19#include <QtCore/qstring.h>
20#include <QtCore/qtimezone.h>
21
22#if QT_CONFIG(icu)
23#include <unicode/ucal.h>
24#else
25#include <QtCore/private/qlocale_p.h> // for DataRange
26#endif
27
30// #define QT_CLDR_ZONE_DEBUG
31
32QT_BEGIN_NAMESPACE
33
34namespace QtTimeZoneLocale {
35#if QT_CONFIG(icu)
36QString ucalTimeZoneDisplayName(UCalendar *ucal, QTimeZone::TimeType timeType,
37 QTimeZone::NameType nameType,
38 const QByteArray &localeCode);
39#else
40
41QList<QByteArrayView> ianaIdsForTerritory(QLocale::Territory territory);
42
43QList<qsizetype> fallbackLocalesFor(qsizetype index); // qlocale.cpp
44
45// Note: "repurposes" QLocale::FormatType with its own twisted meaning.
46// See comments in QTZL.cpp; qlocale.cpp has a fallback implementation.
47QString zoneOffsetFormat(const QLocale &locale, qsizetype locInd, QLocale::FormatType width,
48 const QDateTime &when, int offsetSeconds);
49
50// Define data types for QTZL_data_p.h
51
52// Accessor methods returning DataRange:
53#define rangeGetter(name)
54 constexpr QLocaleData::DataRange name() const
55 { return { m_ ## name ## _idx, m_ ## name ## _size }; }
56// Indices of starts of formats within their tables:
57#define declFieldIndex(name) quint16 m_ ## name ## _idx;
58#define declBigFieldIndex(name) quint32 m_ ## name ## _idx;
59// Lengths of formats:
60#define declFieldSize(name) quint8 m_ ## name ## _size;
61// Generic, standard, daylight-saving triples:
62#define forEachNameType(X, form) X(form ## Generic) X(form ## Standard) X(form ## DaylightSaving)
63// Mapping TimeType to the appropriate one of those:
64#define timeTypeRange(form)
65 constexpr QLocaleData::DataRange form ## Name(QTimeZone::TimeType timeType) const
66 {
67 switch (timeType) {
68 case QTimeZone::StandardTime: return form ## Standard();
69 case QTimeZone::DaylightTime: return form ## DaylightSaving();
70 case QTimeZone::GenericTime: return form ## Generic();
71 }
72 Q_UNREACHABLE_RETURN({});
73 }
74// Mostly form is short or long and we want to append Name.
75// See kludge below for regionFormat, for which that's not the name the method wants.
76
78{
79#ifdef QT_CLDR_ZONE_DEBUG
80 // Only included when this define is set, for the sake of asserting
81 // consistency with QLocaleData at matching index in tables.
83#endif
84
85 // Indices for this locale:
86 quint32 m_exemplarTableStart; // first LocaleZoneExemplar
87 quint32 m_metaLongTableStart; // first LocaleMetaZoneLongNames
88 quint16 m_metaShortTableStart; // first LocaleMetaZoneShortNames
89 quint16 m_zoneTableStart; // first LocaleZoneNames
90
91 // Zone-independent formats:
92#define forEachField(X)
93 X(posHourFormat) X(negHourFormat) X(offsetGmtFormat) X(fallbackFormat)
94 forEachNameType(X, regionFormat)
95 // Hour formats: HH is hour, mm is minutes (always use two digits for each).
96 // GMT format: %0 is an hour format's result.
97 // Region formats: %0 is exemplar city or territory.
98 // Fallback format: %0 is exemplar city or territory, %1 is meta-zone name.
99
103
104#undef forEachField
105#define regionFormatName regionFormatRange // kludge naming
106 timeTypeRange(regionFormat)
107#undef regionFormatName
108};
109
110// Sorted by localeIndex, then ianaIdIndex
112{
113 quint16 localeIndex; // Index in locale data tables
114 quint16 ianaIdIndex; // Location in IANA ID table
115 constexpr QByteArrayView ianaId() const; // Defined in QTZL.cpp
116 rangeGetter(exemplarCity);
119};
120
121// Sorted by localeIndex, then ianaIdIndex
123{
124 quint16 localeIndex; // Index in locale data tables
125 quint16 ianaIdIndex; // Location in IANA ID table
126 constexpr QByteArrayView ianaId() const; // Defined in QTZL.cpp
127 constexpr QLocaleData::DataRange name(QTimeZone::NameType nameType,
128 QTimeZone::TimeType timeType) const
129 {
130 return nameType == QTimeZone::ShortName ? shortName(timeType) : longName(timeType);
131 }
132 timeTypeRange(long)
133 timeTypeRange(short)
134#define forEach32BitField(X) forEachNameType(X, long)
135#define forEach16BitField(X) forEachNameType(X, short)
136#define forEachField(X) forEach32BitField(X) forEach16BitField(X)
137 // Localized name of exemplar city for zone.
138 // Long and short localized names (length zero for unspecified) for the zone
139 // in its generic, standard and daylight-saving forms.
140
145
146#undef forEachField
147#undef forEach16BitField
148#undef forEach32BitField
149};
150
151// Sorted by localeIndex, then metaIdIndex
153{
154 quint16 localeIndex; // Index in locale data tables
155 quint16 metaIdIndex; // metaZoneTable[metaZoneKey - 1].metaIdIndex
156 timeTypeRange(long)
157#define forEachField(X) forEachNameType(X, long)
158 // Long localized names (length zero for unspecified) for the
159 // metazone in its generic, standard and daylight-saving forms.
160
164
165#undef forEachField
166};
167
168// Sorted by localeIndex, then metaIdIndex
170{
171 quint16 localeIndex; // Index in locale data tables
172 quint16 metaIdIndex; // metaZoneTable[metaZoneKey - 1].metaIdIndex
173 timeTypeRange(short)
174#define forEachField(X) forEachNameType(X, short)
175 // Short localized names (length zero for unspecified) for the
176 // metazone in its generic, standard and daylight-saving forms.
177
181
182#undef forEachField
183};
184
185#undef timeTypeRange
186#undef forEachNameType
187#undef declFieldSize
188#undef declFieldIndex
189#undef rangeGetter
190#endif
191} // QtTimeZoneLocale
192
193QT_END_NAMESPACE
194
195#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:485
#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)
constexpr QByteArrayView ianaId() const
constexpr QLocaleData::DataRange name(QTimeZone::NameType nameType, QTimeZone::TimeType timeType) const
constexpr QByteArrayView ianaId() const