30#if Q_BYTE_ORDER == Q_LITTLE_ENDIAN
33 qintptr offset :
sizeof(
void *) * 8 - 2;
35#if Q_BYTE_ORDER == Q_BIG_ENDIAN
43 constexpr ShortData(Qt::TimeSpec spec,
int secondsAhead = 0)
44#if Q_BYTE_ORDER == Q_BIG_ENDIAN
45 : offset(spec == Qt::OffsetFromUTC ? secondsAhead : 0),
46 mode((
int(spec) + 1) & 3)
48 : mode((
int(spec) + 1) & 3),
49 offset(spec == Qt::OffsetFromUTC ? secondsAhead : 0)
53 friend constexpr bool operator==(ShortData lhs, ShortData rhs)
54 {
return lhs.mode == rhs.mode && lhs.offset == rhs.offset; }
55 constexpr Qt::TimeSpec spec()
const {
return Qt::TimeSpec((mode + 3) & 3); }
61 Data(ShortData sd) : s(sd) {}
62 Data(
const Data &other)
noexcept;
63 Data(Data &&other)
noexcept : d(std::exchange(other.d,
nullptr)) {}
64 Data &operator=(
const Data &other)
noexcept;
65 Data &operator=(Data &&other)
noexcept { swap(other);
return *
this; }
68 void swap(Data &other)
noexcept { qt_ptr_swap(d, other.d); }
70 bool isShort()
const {
return s.mode; }
73 template <
typename Stream,
typename Wrap>
74 void serialize(Stream &out,
const Wrap &wrap)
const;
76 Data(QTimeZonePrivate *dptr)
noexcept;
77 Data &operator=(QTimeZonePrivate *dptr)
noexcept;
78 const QTimeZonePrivate *operator->()
const { Q_ASSERT(!isShort());
return d; }
79 QTimeZonePrivate *operator->() { Q_ASSERT(!isShort());
return d; }
81 QTimeZonePrivate *d =
nullptr;
85 friend class QTypeInfo<Data>;
87 QTimeZone(ShortData sd) : d(sd) {}
88 QTimeZone(Qt::TimeSpec) Q_DECL_EQ_DELETE_X(
89 "Would be treated as int offsetSeconds. "
90 "Use QTimeZone::UTC or QTimeZone::LocalTime instead.");
94 static constexpr int MinUtcOffsetSecs = -16 * 3600;
97 static constexpr int MaxUtcOffsetSecs = +16 * 3600;
101 enum Initialization { LocalTime, UTC };
103 QTimeZone()
noexcept;
104 Q_IMPLICIT QTimeZone(Initialization spec)
noexcept
105 : d(ShortData(spec == UTC ? Qt::UTC : Qt::LocalTime)) {}
107#if QT_CONFIG(timezone)
108 explicit QTimeZone(
int offsetSeconds);
109 explicit QTimeZone(
const QByteArray &ianaId);
110 QTimeZone(
const QByteArray &zoneId,
int offsetSeconds,
const QString &name,
111 const QString &abbreviation, QLocale::Territory territory = QLocale::AnyTerritory,
112 const QString &comment = QString());
115 QTimeZone(
const QTimeZone &other)
noexcept;
116 QTimeZone(QTimeZone &&other)
noexcept : d(std::move(other.d)) {}
119 QTimeZone &operator=(
const QTimeZone &other);
120 QT_MOVE_ASSIGNMENT_OPERATOR_IMPL_VIA_PURE_SWAP(QTimeZone)
122 void swap(QTimeZone &other)
noexcept
125#if QT_CORE_REMOVED_SINCE(6
, 7
)
126 bool operator==(
const QTimeZone &other)
const;
127 bool operator!=(
const QTimeZone &other)
const;
130 bool isValid()
const;
132 static QTimeZone fromDurationAheadOfUtc(std::chrono::seconds offset)
134 return QTimeZone((offset.count() >= MinUtcOffsetSecs && offset.count() <= MaxUtcOffsetSecs)
135 ? ShortData(offset.count() ? Qt::OffsetFromUTC : Qt::UTC,
137 : ShortData(Qt::TimeZone));
139 static QTimeZone fromSecondsAheadOfUtc(
int offset)
141 return fromDurationAheadOfUtc(std::chrono::seconds{offset});
143 constexpr Qt::TimeSpec timeSpec()
const noexcept {
return d.s.spec(); }
144 constexpr int fixedSecondsAheadOfUtc()
const noexcept
145 {
return timeSpec() == Qt::OffsetFromUTC ?
int(d.s.offset) : 0; }
147 static constexpr bool isUtcOrFixedOffset(Qt::TimeSpec spec)
noexcept
148 {
return spec == Qt::UTC || spec == Qt::OffsetFromUTC; }
149 constexpr bool isUtcOrFixedOffset()
const noexcept {
return isUtcOrFixedOffset(timeSpec()); }
151#if QT_CONFIG(timezone)
152 QTimeZone asBackendZone()
const;
168 QString abbreviation;
171 int standardTimeOffset;
172 int daylightTimeOffset;
174 typedef QList<OffsetData> OffsetDataList;
176 bool hasAlternativeName(QByteArrayView alias)
const;
177 QByteArray id()
const;
178 QLocale::Territory territory()
const;
179# if QT_DEPRECATED_SINCE(6
, 6
)
180 QT_DEPRECATED_VERSION_X_6_6(
"Use territory() instead")
181 QLocale::Country country()
const;
183 QString comment()
const;
185 QString displayName(
const QDateTime &atDateTime, NameType nameType = DefaultName,
186 const QLocale &locale = QLocale())
const;
187 QString displayName(TimeType timeType, NameType nameType = DefaultName,
188 const QLocale &locale = QLocale())
const;
189 QString abbreviation(
const QDateTime &atDateTime)
const;
191 int offsetFromUtc(
const QDateTime &atDateTime)
const;
192 int standardTimeOffset(
const QDateTime &atDateTime)
const;
193 int daylightTimeOffset(
const QDateTime &atDateTime)
const;
195 bool hasDaylightTime()
const;
196 bool isDaylightTime(
const QDateTime &atDateTime)
const;
198 OffsetData offsetData(
const QDateTime &forDateTime)
const;
200 bool hasTransitions()
const;
201 OffsetData nextTransition(
const QDateTime &afterDateTime)
const;
202 OffsetData previousTransition(
const QDateTime &beforeDateTime)
const;
203 OffsetDataList transitions(
const QDateTime &fromDateTime,
const QDateTime &toDateTime)
const;
205 static QByteArray systemTimeZoneId();
206 static QTimeZone systemTimeZone();
207 static QTimeZone utc();
209 static bool isTimeZoneIdAvailable(
const QByteArray &ianaId);
211 static QList<QByteArray> availableTimeZoneIds();
212 static QList<QByteArray> availableTimeZoneIds(QLocale::Territory territory);
213 static QList<QByteArray> availableTimeZoneIds(
int offsetSeconds);
215 static QByteArray ianaIdToWindowsId(
const QByteArray &ianaId);
216 static QByteArray windowsIdToDefaultIanaId(
const QByteArray &windowsId);
217 static QByteArray windowsIdToDefaultIanaId(
const QByteArray &windowsId,
218 QLocale::Territory territory);
219 static QList<QByteArray> windowsIdToIanaIds(
const QByteArray &windowsId);
220 static QList<QByteArray> windowsIdToIanaIds(
const QByteArray &windowsId,
221 QLocale::Territory territory);
223# if defined(Q_OS_DARWIN) || defined(Q_QDOC)
224 static QTimeZone fromCFTimeZone(CFTimeZoneRef timeZone);
225 CFTimeZoneRef toCFTimeZone()
const Q_DECL_CF_RETURNS_RETAINED;
226 static QTimeZone fromNSTimeZone(
const NSTimeZone *timeZone);
227 NSTimeZone *toNSTimeZone()
const Q_DECL_NS_RETURNS_AUTORELEASED;
230# if __cpp_lib_chrono >= 201907L
|| defined(Q_QDOC)
231 QT_POST_CXX17_API_IN_EXPORTED_CLASS
232 static QTimeZone fromStdTimeZonePtr(
const std::chrono::time_zone *timeZone)
236 const std::string_view timeZoneName = timeZone->name();
237 return QTimeZone(QByteArrayView(timeZoneName).toByteArray());
242 friend Q_CORE_EXPORT
bool comparesEqual(
const QTimeZone &lhs,
const QTimeZone &rhs)
noexcept;
243 Q_DECLARE_EQUALITY_COMPARABLE(QTimeZone)
245#ifndef QT_NO_DATASTREAM
246 friend Q_CORE_EXPORT QDataStream &operator<<(QDataStream &ds,
const QTimeZone &tz);
248#ifndef QT_NO_DEBUG_STREAM
249 friend Q_CORE_EXPORT QDebug operator<<(QDebug dbg,
const QTimeZone &tz);
251 QTimeZone(QTimeZonePrivate &dd);
252 friend class QTimeZonePrivate;
253 friend class QDateTime;
254 friend class QDateTimePrivate;