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