29#if Q_BYTE_ORDER == Q_LITTLE_ENDIAN
32 qintptr offset :
sizeof(
void *) * 8 - 2;
34#if Q_BYTE_ORDER == Q_BIG_ENDIAN
42 constexpr ShortData(Qt::TimeSpec spec,
int secondsAhead = 0)
43#if Q_BYTE_ORDER == Q_BIG_ENDIAN
44 : offset(spec == Qt::OffsetFromUTC ? secondsAhead : 0),
45 mode((
int(spec) + 1) & 3)
47 : mode((
int(spec) + 1) & 3),
48 offset(spec == Qt::OffsetFromUTC ? secondsAhead : 0)
52 friend constexpr bool operator==(ShortData lhs, ShortData rhs)
53 {
return lhs.mode == rhs.mode && lhs.offset == rhs.offset; }
54 constexpr Qt::TimeSpec spec()
const {
return Qt::TimeSpec((mode + 3) & 3); }
60 Data(ShortData sd) : s(sd) {}
61 Data(
const Data &other)
noexcept;
62 Data(Data &&other)
noexcept : d(std::exchange(other.d,
nullptr)) {}
63 Data &operator=(
const Data &other)
noexcept;
64 Data &operator=(Data &&other)
noexcept { swap(other);
return *
this; }
67 void swap(Data &other)
noexcept { qt_ptr_swap(d, other.d); }
69 bool isShort()
const {
return s.mode; }
72 template <
typename Stream,
typename Wrap>
73 void serialize(Stream &out,
const Wrap &wrap)
const;
75 Data(QTimeZonePrivate *dptr)
noexcept;
76 Data &operator=(QTimeZonePrivate *dptr)
noexcept;
77 const QTimeZonePrivate *operator->()
const { Q_ASSERT(!isShort());
return d; }
78 QTimeZonePrivate *operator->() { Q_ASSERT(!isShort());
return d; }
80 QTimeZonePrivate *d =
nullptr;
83 QTimeZone(ShortData sd) : d(sd) {}
84 QTimeZone(Qt::TimeSpec) Q_DECL_EQ_DELETE_X(
85 "Would be treated as int offsetSeconds. "
86 "Use QTimeZone::UTC or QTimeZone::LocalTime instead.");
90 static constexpr int MinUtcOffsetSecs = -16 * 3600;
93 static constexpr int MaxUtcOffsetSecs = +16 * 3600;
97 enum Initialization { LocalTime, UTC };
100 Q_IMPLICIT QTimeZone(Initialization spec)
noexcept
101 : d(ShortData(spec == UTC ? Qt::UTC : Qt::LocalTime)) {}
103#if QT_CONFIG(timezone)
104 explicit QTimeZone(
int offsetSeconds);
105 explicit QTimeZone(
const QByteArray &ianaId);
106 QTimeZone(
const QByteArray &zoneId,
int offsetSeconds,
const QString &name,
107 const QString &abbreviation, QLocale::Territory territory = QLocale::AnyTerritory,
108 const QString &comment = QString());
111 QTimeZone(
const QTimeZone &other)
noexcept;
112 QTimeZone(QTimeZone &&other)
noexcept : d(std::move(other.d)) {}
115 QTimeZone &operator=(
const QTimeZone &other);
116 QT_MOVE_ASSIGNMENT_OPERATOR_IMPL_VIA_PURE_SWAP(QTimeZone)
118 void swap(QTimeZone &other)
noexcept
121#if QT_CORE_REMOVED_SINCE(6
, 7
)
122 bool operator==(
const QTimeZone &other)
const;
123 bool operator!=(
const QTimeZone &other)
const;
126 bool isValid()
const;
128 static QTimeZone fromDurationAheadOfUtc(std::chrono::seconds offset)
130 return QTimeZone((offset.count() >= MinUtcOffsetSecs && offset.count() <= MaxUtcOffsetSecs)
131 ? ShortData(offset.count() ? Qt::OffsetFromUTC : Qt::UTC,
133 : ShortData(Qt::TimeZone));
135 static QTimeZone fromSecondsAheadOfUtc(
int offset)
137 return fromDurationAheadOfUtc(std::chrono::seconds{offset});
139 constexpr Qt::TimeSpec timeSpec()
const noexcept {
return d.s.spec(); }
140 constexpr int fixedSecondsAheadOfUtc()
const noexcept
141 {
return timeSpec() == Qt::OffsetFromUTC ?
int(d.s.offset) : 0; }
143 static constexpr bool isUtcOrFixedOffset(Qt::TimeSpec spec)
noexcept
144 {
return spec == Qt::UTC || spec == Qt::OffsetFromUTC; }
145 constexpr bool isUtcOrFixedOffset()
const noexcept {
return isUtcOrFixedOffset(timeSpec()); }
147#if QT_CONFIG(timezone)
148 QTimeZone asBackendZone()
const;
164 QString abbreviation;
167 int standardTimeOffset;
168 int daylightTimeOffset;
170 typedef QList<OffsetData> OffsetDataList;
172 bool hasAlternativeName(QByteArrayView alias)
const;
173 QByteArray id()
const;
174 QLocale::Territory territory()
const;
175# if QT_DEPRECATED_SINCE(6
, 6
)
176 QT_DEPRECATED_VERSION_X_6_6(
"Use territory() instead")
177 QLocale::Country country()
const;
179 QString comment()
const;
181 QString displayName(
const QDateTime &atDateTime, NameType nameType = DefaultName,
182 const QLocale &locale = QLocale())
const;
183 QString displayName(TimeType timeType, NameType nameType = DefaultName,
184 const QLocale &locale = QLocale())
const;
185 QString abbreviation(
const QDateTime &atDateTime)
const;
187 int offsetFromUtc(
const QDateTime &atDateTime)
const;
188 int standardTimeOffset(
const QDateTime &atDateTime)
const;
189 int daylightTimeOffset(
const QDateTime &atDateTime)
const;
191 bool hasDaylightTime()
const;
192 bool isDaylightTime(
const QDateTime &atDateTime)
const;
194 OffsetData offsetData(
const QDateTime &forDateTime)
const;
196 bool hasTransitions()
const;
197 OffsetData nextTransition(
const QDateTime &afterDateTime)
const;
198 OffsetData previousTransition(
const QDateTime &beforeDateTime)
const;
199 OffsetDataList transitions(
const QDateTime &fromDateTime,
const QDateTime &toDateTime)
const;
201 static QByteArray systemTimeZoneId();
202 static QTimeZone systemTimeZone();
203 static QTimeZone utc();
205 static bool isTimeZoneIdAvailable(
const QByteArray &ianaId);
207 static QList<QByteArray> availableTimeZoneIds();
208 static QList<QByteArray> availableTimeZoneIds(QLocale::Territory territory);
209 static QList<QByteArray> availableTimeZoneIds(
int offsetSeconds);
211 static QByteArray ianaIdToWindowsId(
const QByteArray &ianaId);
212 static QByteArray windowsIdToDefaultIanaId(
const QByteArray &windowsId);
213 static QByteArray windowsIdToDefaultIanaId(
const QByteArray &windowsId,
214 QLocale::Territory territory);
215 static QList<QByteArray> windowsIdToIanaIds(
const QByteArray &windowsId);
216 static QList<QByteArray> windowsIdToIanaIds(
const QByteArray &windowsId,
217 QLocale::Territory territory);
219# if defined(Q_OS_DARWIN) || defined(Q_QDOC)
220 static QTimeZone fromCFTimeZone(CFTimeZoneRef timeZone);
221 CFTimeZoneRef toCFTimeZone()
const Q_DECL_CF_RETURNS_RETAINED;
222 static QTimeZone fromNSTimeZone(
const NSTimeZone *timeZone);
223 NSTimeZone *toNSTimeZone()
const Q_DECL_NS_RETURNS_AUTORELEASED;
226# if __cpp_lib_chrono >= 201907L
|| defined(Q_QDOC)
227 QT_POST_CXX17_API_IN_EXPORTED_CLASS
228 static QTimeZone fromStdTimeZonePtr(
const std::chrono::time_zone *timeZone)
232 const std::string_view timeZoneName = timeZone->name();
233 return QTimeZone(QByteArrayView(timeZoneName).toByteArray());
238 friend Q_CORE_EXPORT
bool comparesEqual(
const QTimeZone &lhs,
const QTimeZone &rhs)
noexcept;
239 Q_DECLARE_EQUALITY_COMPARABLE(QTimeZone)
241#ifndef QT_NO_DATASTREAM
242 friend Q_CORE_EXPORT QDataStream &operator<<(QDataStream &ds,
const QTimeZone &tz);
244#ifndef QT_NO_DEBUG_STREAM
245 friend Q_CORE_EXPORT QDebug operator<<(QDebug dbg,
const QTimeZone &tz);
247 QTimeZone(QTimeZonePrivate &dd);
248 friend class QTimeZonePrivate;
249 friend class QDateTime;
250 friend class QDateTimePrivate;