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);
523 || global_tz->backend->isTimeZoneIdAvailable(zoneId)
565QTimeZone QTimeZone::asBackendZone()
const
571 return systemTimeZone();
747 return rhs.d.isShort() && lhs.d.s == rhs.d.s;
749 if (!rhs.d.isShort()) {
750 if (lhs.d.d == rhs.d.d)
752#if QT_CONFIG(timezone)
753 return lhs.d.d && rhs.d.d && *lhs.d.d == *rhs.d.d;
766#if QT_CONFIG(timezone)
773#if QT_CONFIG(timezone)
808 switch (d.s.spec()) {
812 return systemTimeZoneId();
844 return systemTimeZone().territory();
851#if QT_DEPRECATED_SINCE(6, 6)
876QString QTimeZone::comment()
const
902QString QTimeZone::displayName(
const QDateTime &atDateTime, NameType nameType,
906 switch (d.s.spec()) {
908 return systemTimeZone().displayName(atDateTime, nameType, locale);
912 atDateTime.toMSecsSinceEpoch(), nameType, locale);
918 return d->
displayName(atDateTime.toMSecsSinceEpoch(), nameType, locale);
941QString QTimeZone::displayName(TimeType timeType, NameType nameType,
945 switch (d.s.spec()) {
947 return systemTimeZone().displayName(timeType, nameType, locale);
977 switch (d.s.spec()) {
979 return systemTimeZone().abbreviation(atDateTime);
1010int QTimeZone::offsetFromUtc(
const QDateTime &atDateTime)
const
1013 switch (d.s.spec()) {
1015 return systemTimeZone().offsetFromUtc(atDateTime);
1045int QTimeZone::standardTimeOffset(
const QDateTime &atDateTime)
const
1048 switch (d.s.spec()) {
1050 return systemTimeZone().standardTimeOffset(atDateTime);
1080int QTimeZone::daylightTimeOffset(
const QDateTime &atDateTime)
const
1083 switch (d.s.spec()) {
1085 return systemTimeZone().daylightTimeOffset(atDateTime);
1093 }
else if (hasDaylightTime()) {
1109bool QTimeZone::hasDaylightTime()
const
1112 switch (d.s.spec()) {
1114 return systemTimeZone().hasDaylightTime();
1136bool QTimeZone::isDaylightTime(
const QDateTime &atDateTime)
const
1139 switch (d.s.spec()) {
1141 return systemTimeZone().isDaylightTime(atDateTime);
1149 }
else if (hasDaylightTime()) {
1168QTimeZone::OffsetData QTimeZone::offsetData(
const QDateTime &forDateTime)
const
1171 switch (d.s.spec()) {
1173 return systemTimeZone().offsetData(forDateTime);
1176 return { abbreviation(forDateTime), forDateTime, int(d.s.offset), int(d.s.offset), 0 };
1199bool QTimeZone::hasTransitions()
const
1202 switch (d.s.spec()) {
1204 return systemTimeZone().hasTransitions();
1233QTimeZone::OffsetData QTimeZone::nextTransition(
const QDateTime &afterDateTime)
const
1236 switch (d.s.spec()) {
1238 return systemTimeZone().nextTransition(afterDateTime);
1246 }
else if (hasTransitions()) {
1268QTimeZone::OffsetData QTimeZone::previousTransition(
const QDateTime &beforeDateTime)
const
1271 switch (d.s.spec()) {
1273 return systemTimeZone().previousTransition(beforeDateTime);
1281 }
else if (hasTransitions()) {
1301QTimeZone::OffsetDataList QTimeZone::transitions(
const QDateTime &fromDateTime,
1304 OffsetDataList
list;
1306 switch (d.s.spec()) {
1308 return systemTimeZone().transitions(fromDateTime, toDateTime);
1316 }
else if (hasTransitions()) {
1355 QByteArray sys = global_tz->backend->systemTimeZoneId();
1359 return systemTimeZone().id();
1384 const auto sys =
QTimeZone(global_tz->backend->systemTimeZoneId());
1385 if (!sys.isValid()) {
1386 static bool neverWarned =
true;
1389 neverWarned =
false;
1390 qWarning(
"Unable to determine system time zone: "
1391 "please check your system configuration.");
1424bool QTimeZone::isTimeZoneIdAvailable(
const QByteArray &ianaId)
1426#if defined(Q_OS_UNIX) && !(defined(Q_OS_ANDROID) || defined(Q_OS_DARWIN))
1438 || global_tz->backend->isTimeZoneIdAvailable(ianaId);
1441static QList<QByteArray> set_union(
const QList<QByteArray> &l1,
const QList<QByteArray> &l2)
1443 QList<QByteArray>
result;
1444 result.reserve(l1.size() + l2.size());
1445 std::set_union(l1.begin(), l1.end(),
1446 l2.begin(), l2.end(),
1447 std::back_inserter(
result));
1463QList<QByteArray> QTimeZone::availableTimeZoneIds()
1501QList<QByteArray> QTimeZone::availableTimeZoneIds(
int offsetSeconds)
1568QList<QByteArray> QTimeZone::windowsIdToIanaIds(
const QByteArray &windowsId)
1587QList<QByteArray> QTimeZone::windowsIdToIanaIds(
const QByteArray &windowsId,
1605template <
typename Stream,
typename Wrap>
1606void QTimeZone::Data::serialize(Stream &
out,
const Wrap &
wrap)
const
1611 out <<
wrap(
"QTimeZone::UTC");
1614 out <<
wrap(
"QTimeZone::LocalTime");
1617 out <<
wrap(
"AheadOfUtcBy") << int(
s.offset);
1625#if QT_CONFIG(timezone)
1626 if constexpr (std::is_same<Stream, QDataStream>::value) {
1636#ifndef QT_NO_DATASTREAM
1642 const auto toQString = [](
const char *
text) {
1646 tz.d.serialize(ds, toQString);
1659 }
else if (ianaId ==
"OffsetFromUtc"_L1) {
1665 ds >> ianaId >> utcOffset >>
name >> abbreviation >> territory >> comment;
1666#if QT_CONFIG(timezone)
1671 if (!
tz.isValid() ||
tz.hasDaylightTime()
1680 }
else if (ianaId ==
"AheadOfUtcBy"_L1) {
1684 }
else if (ianaId ==
"QTimeZone::UTC"_L1) {
1686 }
else if (ianaId ==
"QTimeZone::LocalTime"_L1) {
1688#if QT_CONFIG(timezone)
1697#ifndef QT_NO_DEBUG_STREAM
1701 const auto asIs = [](
const char *
text) {
return text; };
1703 dbg.nospace() <<
"QTimeZone(";
1704 tz.d.serialize(dbg, asIs);
1705 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 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]