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) {}
87 static constexpr int MinUtcOffsetSecs = -16 * 3600;
90 static constexpr int MaxUtcOffsetSecs = +16 * 3600;
94 enum Initialization { LocalTime, UTC };
97 Q_IMPLICIT QTimeZone(Initialization spec)
noexcept
98 : d(ShortData(spec == UTC ? Qt::UTC : Qt::LocalTime)) {}
100#if QT_CONFIG(timezone)
101 explicit QTimeZone(
int offsetSeconds);
102 explicit QTimeZone(
const QByteArray &ianaId);
103 QTimeZone(
const QByteArray &zoneId,
int offsetSeconds,
const QString &name,
104 const QString &abbreviation, QLocale::Territory territory = QLocale::AnyTerritory,
105 const QString &comment = QString());
108 QTimeZone(
const QTimeZone &other)
noexcept;
109 QTimeZone(QTimeZone &&other)
noexcept : d(std::move(other.d)) {}
112 QTimeZone &operator=(
const QTimeZone &other);
113 QT_MOVE_ASSIGNMENT_OPERATOR_IMPL_VIA_PURE_SWAP(QTimeZone)
115 void swap(QTimeZone &other)
noexcept
118#if QT_CORE_REMOVED_SINCE(6
, 7
)
119 bool operator==(
const QTimeZone &other)
const;
120 bool operator!=(
const QTimeZone &other)
const;
123 bool isValid()
const;
125 static QTimeZone fromDurationAheadOfUtc(std::chrono::seconds offset)
127 return QTimeZone((offset.count() >= MinUtcOffsetSecs && offset.count() <= MaxUtcOffsetSecs)
128 ? ShortData(offset.count() ? Qt::OffsetFromUTC : Qt::UTC,
130 : ShortData(Qt::TimeZone));
132 static QTimeZone fromSecondsAheadOfUtc(
int offset)
134 return fromDurationAheadOfUtc(std::chrono::seconds{offset});
136 constexpr Qt::TimeSpec timeSpec()
const noexcept {
return d.s.spec(); }
137 constexpr int fixedSecondsAheadOfUtc()
const noexcept
138 {
return timeSpec() == Qt::OffsetFromUTC ?
int(d.s.offset) : 0; }
140 static constexpr bool isUtcOrFixedOffset(Qt::TimeSpec spec)
noexcept
141 {
return spec == Qt::UTC || spec == Qt::OffsetFromUTC; }
142 constexpr bool isUtcOrFixedOffset()
const noexcept {
return isUtcOrFixedOffset(timeSpec()); }
144#if QT_CONFIG(timezone)
145 QTimeZone asBackendZone()
const;
161 QString abbreviation;
164 int standardTimeOffset;
165 int daylightTimeOffset;
167 typedef QList<OffsetData> OffsetDataList;
169 bool hasAlternativeName(QByteArrayView alias)
const;
170 QByteArray id()
const;
171 QLocale::Territory territory()
const;
172# if QT_DEPRECATED_SINCE(6
, 6
)
173 QT_DEPRECATED_VERSION_X_6_6(
"Use territory() instead")
174 QLocale::Country country()
const;
176 QString comment()
const;
178 QString displayName(
const QDateTime &atDateTime, NameType nameType = DefaultName,
179 const QLocale &locale = QLocale())
const;
180 QString displayName(TimeType timeType, NameType nameType = DefaultName,
181 const QLocale &locale = QLocale())
const;
182 QString abbreviation(
const QDateTime &atDateTime)
const;
184 int offsetFromUtc(
const QDateTime &atDateTime)
const;
185 int standardTimeOffset(
const QDateTime &atDateTime)
const;
186 int daylightTimeOffset(
const QDateTime &atDateTime)
const;
188 bool hasDaylightTime()
const;
189 bool isDaylightTime(
const QDateTime &atDateTime)
const;
191 OffsetData offsetData(
const QDateTime &forDateTime)
const;
193 bool hasTransitions()
const;
194 OffsetData nextTransition(
const QDateTime &afterDateTime)
const;
195 OffsetData previousTransition(
const QDateTime &beforeDateTime)
const;
196 OffsetDataList transitions(
const QDateTime &fromDateTime,
const QDateTime &toDateTime)
const;
198 static QByteArray systemTimeZoneId();
199 static QTimeZone systemTimeZone();
200 static QTimeZone utc();
202 static bool isTimeZoneIdAvailable(
const QByteArray &ianaId);
204 static QList<QByteArray> availableTimeZoneIds();
205 static QList<QByteArray> availableTimeZoneIds(QLocale::Territory territory);
206 static QList<QByteArray> availableTimeZoneIds(
int offsetSeconds);
208 static QByteArray ianaIdToWindowsId(
const QByteArray &ianaId);
209 static QByteArray windowsIdToDefaultIanaId(
const QByteArray &windowsId);
210 static QByteArray windowsIdToDefaultIanaId(
const QByteArray &windowsId,
211 QLocale::Territory territory);
212 static QList<QByteArray> windowsIdToIanaIds(
const QByteArray &windowsId);
213 static QList<QByteArray> windowsIdToIanaIds(
const QByteArray &windowsId,
214 QLocale::Territory territory);
216# if defined(Q_OS_DARWIN) || defined(Q_QDOC)
217 static QTimeZone fromCFTimeZone(CFTimeZoneRef timeZone);
218 CFTimeZoneRef toCFTimeZone()
const Q_DECL_CF_RETURNS_RETAINED;
219 static QTimeZone fromNSTimeZone(
const NSTimeZone *timeZone);
220 NSTimeZone *toNSTimeZone()
const Q_DECL_NS_RETURNS_AUTORELEASED;
223# if __cpp_lib_chrono >= 201907L
|| defined(Q_QDOC)
224 QT_POST_CXX17_API_IN_EXPORTED_CLASS
225 static QTimeZone fromStdTimeZonePtr(
const std::chrono::time_zone *timeZone)
229 const std::string_view timeZoneName = timeZone->name();
230 return QTimeZone(QByteArrayView(timeZoneName).toByteArray());
235 friend Q_CORE_EXPORT
bool comparesEqual(
const QTimeZone &lhs,
const QTimeZone &rhs)
noexcept;
236 Q_DECLARE_EQUALITY_COMPARABLE(QTimeZone)
238#ifndef QT_NO_DATASTREAM
239 friend Q_CORE_EXPORT QDataStream &operator<<(QDataStream &ds,
const QTimeZone &tz);
241#ifndef QT_NO_DEBUG_STREAM
242 friend Q_CORE_EXPORT QDebug operator<<(QDebug dbg,
const QTimeZone &tz);
244 QTimeZone(QTimeZonePrivate &dd);
245 friend class QTimeZonePrivate;
246 friend class QDateTime;
247 friend class QDateTimePrivate;