Remove system locale dependency from timezone code that doesn't need it

Various parts of QTimeZone's code were, for no immediately apparent
reason, conditioned on !defined(QT_NO_SYSTEMLOCALE). All are in any
case conditioned on feature timezone; and none had any obvious
relationship with QLocale::system(). Assume this is a fossil left over
from initial development of timezone support and purge.

[ChangeLog][QtCore][QTimeZone] Some features are now available
whenever feature timezone is enabled, that were previously dependent
on system locale support.

Change-Id: I7f2246e17ace22d2aecc9286295ae522ee2a0f5f
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
This commit is contained in:
Edward Welbourne 2024-01-29 14:50:40 +01:00
parent c23d3ca1f0
commit 62b3720a20
4 changed files with 16 additions and 28 deletions

View File

@ -10,7 +10,7 @@
#include <QtCore/qbytearray.h> #include <QtCore/qbytearray.h>
#include <QtCore/qrect.h> #include <QtCore/qrect.h>
#if QT_CONFIG(timezone) && !defined(QT_NO_SYSTEMLOCALE) #if QT_CONFIG(timezone)
#include <QtCore/qtimezone.h> #include <QtCore/qtimezone.h>
#include <QtCore/private/qtimezoneprivate_p.h> #include <QtCore/private/qtimezoneprivate_p.h>
#include <QtCore/private/qcore_mac_p.h> #include <QtCore/private/qcore_mac_p.h>
@ -466,7 +466,7 @@ NSDate *QDateTime::toNSDate() const
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
#if QT_CONFIG(timezone) && !defined(QT_NO_SYSTEMLOCALE) #if QT_CONFIG(timezone)
/*! /*!
\brief Constructs a new QTimeZone containing a copy of the CFTimeZone \a timeZone. \brief Constructs a new QTimeZone containing a copy of the CFTimeZone \a timeZone.

View File

@ -22,13 +22,6 @@ using namespace Qt::StringLiterals;
// Create default time zone using appropriate backend // Create default time zone using appropriate backend
static QTimeZonePrivate *newBackendTimeZone() static QTimeZonePrivate *newBackendTimeZone()
{ {
#ifdef QT_NO_SYSTEMLOCALE
#if QT_CONFIG(icu)
return new QIcuTimeZonePrivate();
#else
return new QUtcTimeZonePrivate();
#endif
#else
#if defined(Q_OS_DARWIN) #if defined(Q_OS_DARWIN)
return new QMacTimeZonePrivate(); return new QMacTimeZonePrivate();
#elif defined(Q_OS_ANDROID) #elif defined(Q_OS_ANDROID)
@ -41,21 +34,13 @@ static QTimeZonePrivate *newBackendTimeZone()
return new QWinTimeZonePrivate(); return new QWinTimeZonePrivate();
#else #else
return new QUtcTimeZonePrivate(); return new QUtcTimeZonePrivate();
#endif // System Locales #endif // Backend selection
#endif // QT_NO_SYSTEMLOCALE
} }
// Create named time zone using appropriate backend // Create named time zone using appropriate backend
static QTimeZonePrivate *newBackendTimeZone(const QByteArray &ianaId) static QTimeZonePrivate *newBackendTimeZone(const QByteArray &ianaId)
{ {
Q_ASSERT(!ianaId.isEmpty()); Q_ASSERT(!ianaId.isEmpty());
#ifdef QT_NO_SYSTEMLOCALE
#if QT_CONFIG(icu)
return new QIcuTimeZonePrivate(ianaId);
#else
return new QUtcTimeZonePrivate(ianaId);
#endif
#else
#if defined(Q_OS_DARWIN) #if defined(Q_OS_DARWIN)
return new QMacTimeZonePrivate(ianaId); return new QMacTimeZonePrivate(ianaId);
#elif defined(Q_OS_ANDROID) #elif defined(Q_OS_ANDROID)
@ -68,8 +53,7 @@ static QTimeZonePrivate *newBackendTimeZone(const QByteArray &ianaId)
return new QWinTimeZonePrivate(ianaId); return new QWinTimeZonePrivate(ianaId);
#else #else
return new QUtcTimeZonePrivate(ianaId); return new QUtcTimeZonePrivate(ianaId);
#endif // System Locales #endif // Backend selection
#endif // QT_NO_SYSTEMLOCALE
} }
class QTimeZoneSingleton class QTimeZoneSingleton
@ -77,10 +61,11 @@ class QTimeZoneSingleton
public: public:
QTimeZoneSingleton() : backend(newBackendTimeZone()) {} QTimeZoneSingleton() : backend(newBackendTimeZone()) {}
// The global_tz is the tz to use in static methods such as availableTimeZoneIds() and // The global_tz is the tz to use in static methods such as
// isTimeZoneIdAvailable() and to create named IANA time zones. This is usually the host // availableTimeZoneIds() and isTimeZoneIdAvailable() and to create named
// system, but may be different if the host resources are insufficient or if // IANA time zones. This is usually the host system, but may be different if
// QT_NO_SYSTEMLOCALE is set. A simple UTC backend is used if no alternative is available. // the host resources are insufficient. A simple UTC backend is used if no
// alternative is available.
QExplicitlySharedDataPointer<QTimeZonePrivate> backend; QExplicitlySharedDataPointer<QTimeZonePrivate> backend;
}; };

View File

@ -13,7 +13,7 @@
#include <chrono> #include <chrono>
#if QT_CONFIG(timezone) && (defined(Q_OS_DARWIN) || defined(Q_QDOC)) && !defined(QT_NO_SYSTEMLOCALE) #if QT_CONFIG(timezone) && (defined(Q_OS_DARWIN) || defined(Q_QDOC))
Q_FORWARD_DECLARE_CF_TYPE(CFTimeZone); Q_FORWARD_DECLARE_CF_TYPE(CFTimeZone);
Q_FORWARD_DECLARE_OBJC_CLASS(NSTimeZone); Q_FORWARD_DECLARE_OBJC_CLASS(NSTimeZone);
#endif #endif
@ -214,7 +214,7 @@ public:
static QList<QByteArray> windowsIdToIanaIds(const QByteArray &windowsId, static QList<QByteArray> windowsIdToIanaIds(const QByteArray &windowsId,
QLocale::Territory territory); QLocale::Territory territory);
# if (defined(Q_OS_DARWIN) || defined(Q_QDOC)) && !defined(QT_NO_SYSTEMLOCALE) # if defined(Q_OS_DARWIN) || defined(Q_QDOC)
static QTimeZone fromCFTimeZone(CFTimeZoneRef timeZone); static QTimeZone fromCFTimeZone(CFTimeZoneRef timeZone);
CFTimeZoneRef toCFTimeZone() const Q_DECL_CF_RETURNS_RETAINED; CFTimeZoneRef toCFTimeZone() const Q_DECL_CF_RETURNS_RETAINED;
static QTimeZone fromNSTimeZone(const NSTimeZone *timeZone); static QTimeZone fromNSTimeZone(const NSTimeZone *timeZone);

View File

@ -756,8 +756,11 @@ static bool isEntryInIanaList(QByteArrayView id, QByteArrayView ianaIds)
} }
/* /*
UTC Offset implementation, used when QT_NO_SYSTEMLOCALE set and ICU is not being used, UTC Offset backend.
or for QDateTimes with a Qt:Spec of Qt::OffsetFromUtc.
Always present, based on UTC-offset zones.
Complements platform-specific backends.
Equivalent to Qt::OffsetFromUtc lightweight time representations.
*/ */
// Create default UTC time zone // Create default UTC time zone