10#include <QtCore/qdatastream.h>
11#include <QtCore/qdatetime.h>
21#if QT_CONFIG(timezone)
25#ifdef QT_NO_SYSTEMLOCALE
27 return new QIcuTimeZonePrivate();
32#if defined(Q_OS_DARWIN)
33 return new QMacTimeZonePrivate();
34#elif defined(Q_OS_ANDROID)
35 return new QAndroidTimeZonePrivate();
36#elif defined(Q_OS_UNIX)
37 return new QTzTimeZonePrivate();
39 return new QIcuTimeZonePrivate();
40#elif defined(Q_OS_WIN)
41 return new QWinTimeZonePrivate();
52#ifdef QT_NO_SYSTEMLOCALE
54 return new QIcuTimeZonePrivate(ianaId);
59#if defined(Q_OS_DARWIN)
60 return new QMacTimeZonePrivate(ianaId);
61#elif defined(Q_OS_ANDROID)
62 return new QAndroidTimeZonePrivate(ianaId);
63#elif defined(Q_OS_UNIX)
64 return new QTzTimeZonePrivate(ianaId);
66 return new QIcuTimeZonePrivate(ianaId);
67#elif defined(Q_OS_WIN)
68 return new QWinTimeZonePrivate(ianaId);
75class QTimeZoneSingleton
78 QTimeZoneSingleton() : backend(newBackendTimeZone()) {}
287#if QT_CONFIG(timezone)
378QTimeZone::Data::Data() noexcept :
d(
nullptr)
384QTimeZone::Data::Data(
const Data &
other)
noexcept
386#if QT_CONFIG(timezone)
396#if QT_CONFIG(timezone)
402QTimeZone::Data::~Data()
404#if QT_CONFIG(timezone)
405 if (!isShort() &&
d && !
d->ref.deref())
411QTimeZone::Data &QTimeZone::Data::operator=(
const QTimeZone::Data &
other)
noexcept
413#if QT_CONFIG(timezone)
414 if (!
other.isShort())
415 return *
this =
other.d;
416 if (!isShort() &&
d && !
d->ref.deref())
430 static_assert(
sizeof(
ShortData) <=
sizeof(Data::d));
435#if QT_CONFIG(timezone)
441 if (
d && !
d->ref.deref())
471 d = newBackendTimeZone();
472 else if (global_tz->backend->isTimeZoneIdAvailable(ianaId))
473 d = newBackendTimeZone(ianaId);
505 :
d((offsetSeconds >= MinUtcOffsetSecs && offsetSeconds <= MaxUtcOffsetSecs)
535 :
d(isTimeZoneIdAvailable(ianaId) ?
nullptr
580QTimeZone QTimeZone::asBackendZone()
const
586 return systemTimeZone();
751 if (!
other.d.isShort()) {
752 if (d.d ==
other.d.d)
754#if QT_CONFIG(timezone)
755 return d.d &&
other.d.d && *d.d == *
other.d.d;
772 return !(*
this ==
other);
781#if QT_CONFIG(timezone)
783 return d.d && d->isValid();
788#if QT_CONFIG(timezone)
801 switch (d.s.spec()) {
805 return systemTimeZoneId();
837 return systemTimeZone().territory();
839 return d->territory();
844#if QT_DEPRECATED_SINCE(6, 6)
869QString QTimeZone::comment()
const
895QString QTimeZone::displayName(
const QDateTime &atDateTime, NameType nameType,
899 switch (d.s.spec()) {
901 return systemTimeZone().displayName(atDateTime, nameType, locale);
934QString QTimeZone::displayName(TimeType timeType, NameType nameType,
938 switch (d.s.spec()) {
940 return systemTimeZone().displayName(timeType, nameType, locale);
949 return d->displayName(timeType, nameType, locale);
970 switch (d.s.spec()) {
972 return systemTimeZone().abbreviation(atDateTime);
1003int QTimeZone::offsetFromUtc(
const QDateTime &atDateTime)
const
1006 switch (d.s.spec()) {
1008 return systemTimeZone().offsetFromUtc(atDateTime);
1038int QTimeZone::standardTimeOffset(
const QDateTime &atDateTime)
const
1041 switch (d.s.spec()) {
1043 return systemTimeZone().standardTimeOffset(atDateTime);
1073int QTimeZone::daylightTimeOffset(
const QDateTime &atDateTime)
const
1076 switch (d.s.spec()) {
1078 return systemTimeZone().daylightTimeOffset(atDateTime);
1086 }
else if (hasDaylightTime()) {
1102bool QTimeZone::hasDaylightTime()
const
1105 switch (d.s.spec()) {
1107 return systemTimeZone().hasDaylightTime();
1116 return d->hasDaylightTime();
1129bool QTimeZone::isDaylightTime(
const QDateTime &atDateTime)
const
1132 switch (d.s.spec()) {
1134 return systemTimeZone().isDaylightTime(atDateTime);
1142 }
else if (hasDaylightTime()) {
1161QTimeZone::OffsetData QTimeZone::offsetData(
const QDateTime &forDateTime)
const
1164 switch (d.s.spec()) {
1166 return systemTimeZone().offsetData(forDateTime);
1169 return { abbreviation(forDateTime), forDateTime, int(d.s.offset), int(d.s.offset), 0 };
1192bool QTimeZone::hasTransitions()
const
1195 switch (d.s.spec()) {
1197 return systemTimeZone().hasTransitions();
1206 return d->hasTransitions();
1226QTimeZone::OffsetData QTimeZone::nextTransition(
const QDateTime &afterDateTime)
const
1229 switch (d.s.spec()) {
1231 return systemTimeZone().nextTransition(afterDateTime);
1239 }
else if (hasTransitions()) {
1261QTimeZone::OffsetData QTimeZone::previousTransition(
const QDateTime &beforeDateTime)
const
1264 switch (d.s.spec()) {
1266 return systemTimeZone().previousTransition(beforeDateTime);
1274 }
else if (hasTransitions()) {
1292QTimeZone::OffsetDataList QTimeZone::transitions(
const QDateTime &fromDateTime,
1295 OffsetDataList
list;
1297 switch (d.s.spec()) {
1299 return systemTimeZone().transitions(fromDateTime, toDateTime);
1307 }
else if (hasTransitions()) {
1334 QByteArray sys = global_tz->backend->systemTimeZoneId();
1338 auto zone = systemTimeZone();
1339 if (zone.isValid() && !zone.id().isEmpty())
1360 return QTimeZone(global_tz->backend->systemTimeZoneId());
1387bool QTimeZone::isTimeZoneIdAvailable(
const QByteArray &ianaId)
1389#if defined(Q_OS_UNIX) && !(defined(Q_OS_ANDROID) || defined(Q_OS_DARWIN))
1400 || global_tz->backend->isTimeZoneIdAvailable(ianaId);
1407 std::set_union(l1.
begin(), l1.
end(),
1409 std::back_inserter(
result));
1559template <
typename Stream,
typename Wrap>
1560void QTimeZone::Data::serialize(Stream &
out,
const Wrap &
wrap)
const
1565 out <<
wrap(
"QTimeZone::UTC");
1568 out <<
wrap(
"QTimeZone::LocalTime");
1571 out <<
wrap(
"AheadOfUtcBy") << int(
s.offset);
1579#if QT_CONFIG(timezone)
1580 if constexpr (std::is_same<Stream, QDataStream>::value) {
1590#ifndef QT_NO_DATASTREAM
1596 const auto toQString = [](
const char *
text) {
1600 tz.d.serialize(ds, toQString);
1613 }
else if (ianaId ==
"OffsetFromUtc"_L1) {
1619 ds >> ianaId >> utcOffset >>
name >> abbreviation >> territory >> comment;
1620#if QT_CONFIG(timezone)
1625 if (!
tz.isValid() ||
tz.hasDaylightTime()
1634 }
else if (ianaId ==
"AheadOfUtcBy"_L1) {
1638 }
else if (ianaId ==
"QTimeZone::UTC"_L1) {
1640 }
else if (ianaId ==
"QTimeZone::LocalTime"_L1) {
1642#if QT_CONFIG(timezone)
1651#ifndef QT_NO_DEBUG_STREAM
1655 const auto asIs = [](
const char *
text) {
return text; };
1657 dbg.nospace() <<
"QTimeZone(";
1658 tz.d.serialize(dbg, asIs);
1659 dbg.nospace() <<
')';
bool isEmpty() const noexcept
Returns true if the byte array has size 0; otherwise returns false.
\inmodule QtCore\reentrant
\inmodule QtCore\reentrant
qint64 toMSecsSinceEpoch() const
static QDateTime fromMSecsSinceEpoch(qint64 msecs, const QTimeZone &timeZone)
qsizetype size() const noexcept
void reserve(qsizetype size)
\macro QT_RESTRICTED_CAST_FROM_ASCII
static QString fromUtf8(QByteArrayView utf8)
This is an overloaded member function, provided for convenience. It differs from the above function o...
QByteArray toUtf8() const &
static QByteArray utcQByteArray()
static QByteArray windowsIdToDefaultIanaId(const QByteArray &windowsId)
static QList< QByteArray > windowsIdToIanaIds(const QByteArray &windowsId)
static QTimeZone::OffsetData toOffsetData(const Data &data)
static QByteArray ianaIdToWindowsId(const QByteArray &ianaId)
static QTimeZone::OffsetData invalidOffsetData()
static constexpr qint64 invalidSeconds()
static bool isValidId(const QByteArray &ianaId)
static constexpr int MaxUtcOffsetSecs
~QTimeZone()
Destroys the time zone.
bool isValid() const
Returns true if this time zone is valid.
QTimeZone & operator=(const QTimeZone &other)
Assignment operator, assign other to this.
QTimeZone() noexcept
Create a null/invalid time zone instance.
static QTimeZone fromSecondsAheadOfUtc(int offset)
bool operator!=(const QTimeZone &other) const
Returns true if this time zone is not equal to the other time zone.
constexpr Qt::TimeSpec timeSpec() const noexcept
bool operator==(const QTimeZone &other) const
Returns true if this time representation is equal to the other.
QList< QByteArray > availableTimeZoneIds() const override
static qint64 offsetFromUtcString(const QByteArray &id)
bool isTimeZoneIdAvailable(const QByteArray &ianaId) const override
QString abbreviation(qint64 atMSecsSinceEpoch) const override
QString displayName(QTimeZone::TimeType timeType, QTimeZone::NameType nameType, const QLocale &locale) const override
list append(new Employee("Blackpool", "Stephen"))
Combined button and popup list for selecting options.
QDateTimePrivate::QDateTimeShortData ShortData
#define Q_GLOBAL_STATIC(TYPE, NAME,...)
GLenum GLuint GLintptr offset
static QT_BEGIN_NAMESPACE QAsn1Element wrap(quint8 type, const QAsn1Element &child)
#define QStringLiteral(str)
QDataStream & operator>>(QDataStream &ds, QTimeZone &tz)
QDataStream & operator<<(QDataStream &ds, const QTimeZone &tz)
static QString invalidId()
QTextStream out(stdout)
[7]