10#include <QtCore/qdatastream.h>
11#include <QtCore/qdatetime.h>
21#if QT_CONFIG(timezone)
25#if defined(Q_OS_DARWIN)
26 return new QMacTimeZonePrivate();
27#elif defined(Q_OS_ANDROID)
28 return new QAndroidTimeZonePrivate();
29#elif defined(Q_OS_UNIX)
30 return new QTzTimeZonePrivate();
32 return new QIcuTimeZonePrivate();
33#elif defined(Q_OS_WIN)
34 return new QWinTimeZonePrivate();
44#if defined(Q_OS_DARWIN)
45 return new QMacTimeZonePrivate(ianaId);
46#elif defined(Q_OS_ANDROID)
47 return new QAndroidTimeZonePrivate(ianaId);
48#elif defined(Q_OS_UNIX)
49 return new QTzTimeZonePrivate(ianaId);
51 return new QIcuTimeZonePrivate(ianaId);
52#elif defined(Q_OS_WIN)
53 return new QWinTimeZonePrivate(ianaId);
59class QTimeZoneSingleton
62 QTimeZoneSingleton() : backend(newBackendTimeZone()) {}
69 QExplicitlySharedDataPointer<QTimeZonePrivate> backend;
274#if QT_CONFIG(timezone)
365QTimeZone::Data::Data() noexcept :
d(
nullptr)
371QTimeZone::Data::Data(
const Data &
other)
noexcept
373#if QT_CONFIG(timezone)
383#if QT_CONFIG(timezone)
389QTimeZone::Data::~Data()
391#if QT_CONFIG(timezone)
392 if (!isShort() && d && !d->
ref.
deref())
398QTimeZone::Data &QTimeZone::Data::operator=(
const QTimeZone::Data &
other)
noexcept
400#if QT_CONFIG(timezone)
401 if (!
other.isShort())
402 return *
this =
other.d;
403 if (!isShort() && d && !d->
ref.
deref())
417 static_assert(
sizeof(
ShortData) <=
sizeof(Data::d));
422#if QT_CONFIG(timezone)
459 d = newBackendTimeZone();
461 d = newBackendTimeZone(ianaId);
465 if (!
name.isEmpty() &&
name != ianaId)
466 d = newBackendTimeZone(
name);
530 || global_tz->backend->isTimeZoneIdAvailable(zoneId)
572QTimeZone QTimeZone::asBackendZone()
const
578 return systemTimeZone();
754 return rhs.d.isShort() && lhs.d.s == rhs.d.s;
756 if (!rhs.d.isShort()) {
757 if (lhs.d.d == rhs.d.d)
759#if QT_CONFIG(timezone)
760 return lhs.d.d && rhs.d.d && *lhs.d.d == *rhs.d.d;
773#if QT_CONFIG(timezone)
780#if QT_CONFIG(timezone)
815 switch (d.s.spec()) {
819 return systemTimeZoneId();
851 return systemTimeZone().territory();
858#if QT_DEPRECATED_SINCE(6, 6)
883QString QTimeZone::comment()
const
909QString QTimeZone::displayName(
const QDateTime &atDateTime, NameType nameType,
913 switch (d.s.spec()) {
915 return systemTimeZone().displayName(atDateTime, nameType, locale);
919 atDateTime.toMSecsSinceEpoch(), nameType, locale);
925 return d->
displayName(atDateTime.toMSecsSinceEpoch(), nameType, locale);
948QString QTimeZone::displayName(TimeType timeType, NameType nameType,
952 switch (d.s.spec()) {
954 return systemTimeZone().displayName(timeType, nameType, locale);
984 switch (d.s.spec()) {
986 return systemTimeZone().abbreviation(atDateTime);
1017int QTimeZone::offsetFromUtc(
const QDateTime &atDateTime)
const
1020 switch (d.s.spec()) {
1022 return systemTimeZone().offsetFromUtc(atDateTime);
1052int QTimeZone::standardTimeOffset(
const QDateTime &atDateTime)
const
1055 switch (d.s.spec()) {
1057 return systemTimeZone().standardTimeOffset(atDateTime);
1087int QTimeZone::daylightTimeOffset(
const QDateTime &atDateTime)
const
1090 switch (d.s.spec()) {
1092 return systemTimeZone().daylightTimeOffset(atDateTime);
1100 }
else if (hasDaylightTime()) {
1116bool QTimeZone::hasDaylightTime()
const
1119 switch (d.s.spec()) {
1121 return systemTimeZone().hasDaylightTime();
1143bool QTimeZone::isDaylightTime(
const QDateTime &atDateTime)
const
1146 switch (d.s.spec()) {
1148 return systemTimeZone().isDaylightTime(atDateTime);
1156 }
else if (hasDaylightTime()) {
1175QTimeZone::OffsetData QTimeZone::offsetData(
const QDateTime &forDateTime)
const
1178 switch (d.s.spec()) {
1180 return systemTimeZone().offsetData(forDateTime);
1183 return { abbreviation(forDateTime), forDateTime, int(d.s.offset), int(d.s.offset), 0 };
1206bool QTimeZone::hasTransitions()
const
1209 switch (d.s.spec()) {
1211 return systemTimeZone().hasTransitions();
1240QTimeZone::OffsetData QTimeZone::nextTransition(
const QDateTime &afterDateTime)
const
1243 switch (d.s.spec()) {
1245 return systemTimeZone().nextTransition(afterDateTime);
1253 }
else if (hasTransitions()) {
1275QTimeZone::OffsetData QTimeZone::previousTransition(
const QDateTime &beforeDateTime)
const
1278 switch (d.s.spec()) {
1280 return systemTimeZone().previousTransition(beforeDateTime);
1288 }
else if (hasTransitions()) {
1308QTimeZone::OffsetDataList QTimeZone::transitions(
const QDateTime &fromDateTime,
1311 OffsetDataList
list;
1313 switch (d.s.spec()) {
1315 return systemTimeZone().transitions(fromDateTime, toDateTime);
1323 }
else if (hasTransitions()) {
1362 QByteArray sys = global_tz->backend->systemTimeZoneId();
1366 return systemTimeZone().id();
1391 const auto sys =
QTimeZone(global_tz->backend->systemTimeZoneId());
1392 if (!sys.isValid()) {
1393 static bool neverWarned =
true;
1396 neverWarned =
false;
1397 qWarning(
"Unable to determine system time zone: "
1398 "please check your system configuration.");
1431bool QTimeZone::isTimeZoneIdAvailable(
const QByteArray &ianaId)
1433#if defined(Q_OS_UNIX) && !(defined(Q_OS_ANDROID) || defined(Q_OS_DARWIN))
1445 || global_tz->backend->isTimeZoneIdAvailable(ianaId);
1448static QList<QByteArray> set_union(
const QList<QByteArray> &l1,
const QList<QByteArray> &l2)
1450 QList<QByteArray>
result;
1451 result.reserve(l1.size() + l2.size());
1452 std::set_union(l1.begin(), l1.end(),
1453 l2.begin(), l2.end(),
1454 std::back_inserter(
result));
1470QList<QByteArray> QTimeZone::availableTimeZoneIds()
1508QList<QByteArray> QTimeZone::availableTimeZoneIds(
int offsetSeconds)
1575QList<QByteArray> QTimeZone::windowsIdToIanaIds(
const QByteArray &windowsId)
1594QList<QByteArray> QTimeZone::windowsIdToIanaIds(
const QByteArray &windowsId,
1612template <
typename Stream,
typename Wrap>
1613void QTimeZone::Data::serialize(Stream &
out,
const Wrap &
wrap)
const
1618 out <<
wrap(
"QTimeZone::UTC");
1621 out <<
wrap(
"QTimeZone::LocalTime");
1624 out <<
wrap(
"AheadOfUtcBy") << int(
s.offset);
1632#if QT_CONFIG(timezone)
1633 if constexpr (std::is_same<Stream, QDataStream>::value) {
1643#ifndef QT_NO_DATASTREAM
1649 const auto toQString = [](
const char *
text) {
1653 tz.d.serialize(ds, toQString);
1666 }
else if (ianaId ==
"OffsetFromUtc"_L1) {
1672 ds >> ianaId >> utcOffset >>
name >> abbreviation >> territory >> comment;
1673#if QT_CONFIG(timezone)
1678 if (!
tz.isValid() ||
tz.hasDaylightTime()
1687 }
else if (ianaId ==
"AheadOfUtcBy"_L1) {
1691 }
else if (ianaId ==
"QTimeZone::UTC"_L1) {
1693 }
else if (ianaId ==
"QTimeZone::LocalTime"_L1) {
1695#if QT_CONFIG(timezone)
1704#ifndef QT_NO_DEBUG_STREAM
1708 const auto asIs = [](
const char *
text) {
return text; };
1710 dbg.nospace() <<
"QTimeZone(";
1711 tz.d.serialize(dbg, asIs);
1712 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)
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 &
virtual bool hasDaylightTime() const
virtual bool isDaylightTime(qint64 atMSecsSinceEpoch) const
static QByteArray utcQByteArray()
static QByteArray aliasToIana(QByteArrayView alias)
static QByteArray windowsIdToDefaultIanaId(const QByteArray &windowsId)
virtual Data nextTransition(qint64 afterMSecsSinceEpoch) const
virtual Data data(qint64 forMSecsSinceEpoch) const
virtual bool hasTransitions() const
virtual Data previousTransition(qint64 beforeMSecsSinceEpoch) const
virtual QString displayName(qint64 atMSecsSinceEpoch, QTimeZone::NameType nameType, const QLocale &locale) const
virtual int daylightTimeOffset(qint64 atMSecsSinceEpoch) const
virtual QLocale::Territory territory() const
virtual QString comment() const
virtual void serialize(QDataStream &ds) const
static QList< QByteArray > windowsIdToIanaIds(const QByteArray &windowsId)
virtual QString abbreviation(qint64 atMSecsSinceEpoch) const
static QTimeZone::OffsetData toOffsetData(const Data &data)
DataList transitions(qint64 fromMSecsSinceEpoch, qint64 toMSecsSinceEpoch) const
virtual int standardTimeOffset(qint64 atMSecsSinceEpoch) const
static QByteArray ianaIdToWindowsId(const QByteArray &ianaId)
virtual int offsetFromUtc(qint64 atMSecsSinceEpoch) const
static QTimeZone::OffsetData invalidOffsetData()
static constexpr qint64 invalidSeconds()
static bool isValidId(const QByteArray &ianaId)
static constexpr int MaxUtcOffsetSecs
friend Q_CORE_EXPORT QDataStream & operator<<(QDataStream &ds, const QTimeZone &tz)
~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)
constexpr Qt::TimeSpec timeSpec() const noexcept
static constexpr int MinUtcOffsetSecs
QList< QByteArray > availableTimeZoneIds() const override
static qint64 offsetFromUtcString(QByteArrayView id)
bool isTimeZoneIdAvailable(const QByteArray &ianaId) const override
QString abbreviation(qint64 atMSecsSinceEpoch) const override
QString displayName(qint64 atMSecsSinceEpoch, 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
typedef QByteArray(EGLAPIENTRYP PFNQGSGETDISPLAYSPROC)()
#define Q_GLOBAL_STATIC(TYPE, NAME,...)
GLenum GLuint GLintptr offset
static QT_BEGIN_NAMESPACE QAsn1Element wrap(quint8 type, const QAsn1Element &child)
#define QStringLiteral(str)
static QString invalidId()
bool comparesEqual(const QTimeZone &lhs, const QTimeZone &rhs) noexcept
Q_CORE_EXPORT QDataStream & operator>>(QDataStream &ds, QTimeZone &tz)
QTextStream out(stdout)
[7]