mirror of https://github.com/qt/qtbase.git
QTimeZone - Change from Olson ID to IANA ID
Complete changes from using Olsen/Olson in the code to IANA. Completes a change started in 5.2 release branch on the public occurrences. Change-Id: Ib077fcda2c77eef6f04ec28901d8d2d7210b8c72 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
This commit is contained in:
parent
20a03d5612
commit
19be46414a
|
@ -77,26 +77,26 @@ static QTimeZonePrivate *newBackendTimeZone()
|
|||
}
|
||||
|
||||
// Create named time zone using appropriate backend
|
||||
static QTimeZonePrivate *newBackendTimeZone(const QByteArray &olsenId)
|
||||
static QTimeZonePrivate *newBackendTimeZone(const QByteArray &ianaId)
|
||||
{
|
||||
#ifdef QT_NO_SYSTEMLOCALE
|
||||
#ifdef QT_USE_ICU
|
||||
return new QIcuTimeZonePrivate(olsenId);
|
||||
return new QIcuTimeZonePrivate(ianaId);
|
||||
#else
|
||||
return new QUtcTimeZonePrivate(olsenId);
|
||||
return new QUtcTimeZonePrivate(ianaId);
|
||||
#endif // QT_USE_ICU
|
||||
#else
|
||||
#if defined Q_OS_MAC
|
||||
return new QMacTimeZonePrivate(olsenId);
|
||||
return new QMacTimeZonePrivate(ianaId);
|
||||
#elif defined Q_OS_UNIX
|
||||
return new QTzTimeZonePrivate(olsenId);
|
||||
return new QTzTimeZonePrivate(ianaId);
|
||||
// Registry based timezone backend not available on WinRT
|
||||
#elif defined Q_OS_WIN && !defined Q_OS_WINRT
|
||||
return new QWinTimeZonePrivate(olsenId);
|
||||
return new QWinTimeZonePrivate(ianaId);
|
||||
#elif defined QT_USE_ICU
|
||||
return new QIcuTimeZonePrivate(olsenId);
|
||||
return new QIcuTimeZonePrivate(ianaId);
|
||||
#else
|
||||
return new QUtcTimeZonePrivate(olsenId);
|
||||
return new QUtcTimeZonePrivate(ianaId);
|
||||
#endif // System Locales
|
||||
#endif // QT_NO_SYSTEMLOCALE
|
||||
}
|
||||
|
@ -933,18 +933,18 @@ QDataStream &operator<<(QDataStream &ds, const QTimeZone &tz)
|
|||
|
||||
QDataStream &operator>>(QDataStream &ds, QTimeZone &tz)
|
||||
{
|
||||
QString olsenId;
|
||||
ds >> olsenId;
|
||||
if (olsenId == QStringLiteral("OffsetFromUtc")) {
|
||||
QString ianaId;
|
||||
ds >> ianaId;
|
||||
if (ianaId == QStringLiteral("OffsetFromUtc")) {
|
||||
int utcOffset;
|
||||
QString name;
|
||||
QString abbreviation;
|
||||
int country;
|
||||
QString comment;
|
||||
ds >> olsenId >> utcOffset >> name >> abbreviation >> country >> comment;
|
||||
tz = QTimeZone(olsenId.toUtf8(), utcOffset, name, abbreviation, (QLocale::Country) country, comment);
|
||||
ds >> ianaId >> utcOffset >> name >> abbreviation >> country >> comment;
|
||||
tz = QTimeZone(ianaId.toUtf8(), utcOffset, name, abbreviation, (QLocale::Country) country, comment);
|
||||
} else {
|
||||
tz = QTimeZone(olsenId.toUtf8());
|
||||
tz = QTimeZone(ianaId.toUtf8());
|
||||
}
|
||||
return ds;
|
||||
}
|
||||
|
|
|
@ -85,21 +85,21 @@ static QByteArray windowsId(const QWindowsData *windowsData)
|
|||
return (windowsIdData + windowsData->windowsIdIndex);
|
||||
}
|
||||
|
||||
// Return the Olsen ID literal for a given QWindowsData
|
||||
static QByteArray olsenId(const QWindowsData *windowsData)
|
||||
// Return the IANA ID literal for a given QWindowsData
|
||||
static QByteArray ianaId(const QWindowsData *windowsData)
|
||||
{
|
||||
return (olsenIdData + windowsData->olsenIdIndex);
|
||||
return (ianaIdData + windowsData->ianaIdIndex);
|
||||
}
|
||||
|
||||
// Return the Olsen ID literal for a given QZoneData
|
||||
static QByteArray olsenId(const QZoneData *zoneData)
|
||||
// Return the IANA ID literal for a given QZoneData
|
||||
static QByteArray ianaId(const QZoneData *zoneData)
|
||||
{
|
||||
return (olsenIdData + zoneData->olsenIdIndex);
|
||||
return (ianaIdData + zoneData->ianaIdIndex);
|
||||
}
|
||||
|
||||
static QByteArray utcId(const QUtcData *utcData)
|
||||
{
|
||||
return (olsenIdData + utcData->olsenIdIndex);
|
||||
return (ianaIdData + utcData->ianaIdIndex);
|
||||
}
|
||||
|
||||
static quint16 toWindowsIdKey(const QByteArray &winId)
|
||||
|
@ -172,7 +172,7 @@ QLocale::Country QTimeZonePrivate::country() const
|
|||
// Default fall-back mode, use the zoneTable to find Region of known Zones
|
||||
for (int i = 0; i < zoneDataTableSize; ++i) {
|
||||
const QZoneData *data = zoneData(i);
|
||||
if (olsenId(data).split(' ').contains(m_id))
|
||||
if (ianaId(data).split(' ').contains(m_id))
|
||||
return (QLocale::Country)data->country;
|
||||
}
|
||||
return QLocale::AnyCountry;
|
||||
|
@ -361,14 +361,14 @@ QSet<QByteArray> QTimeZonePrivate::availableTimeZoneIds(QLocale::Country country
|
|||
// First get all Zones in the Zones table belonging to the Region
|
||||
for (int i = 0; i < zoneDataTableSize; ++i) {
|
||||
if (zoneData(i)->country == country)
|
||||
regionSet += olsenId(zoneData(i)).split(' ').toSet();
|
||||
regionSet += ianaId(zoneData(i)).split(' ').toSet();
|
||||
}
|
||||
|
||||
// Then select just those that are available
|
||||
QSet<QByteArray> set;
|
||||
foreach (const QByteArray &olsenId, availableTimeZoneIds()) {
|
||||
if (regionSet.contains(olsenId))
|
||||
set << olsenId;
|
||||
foreach (const QByteArray &ianaId, availableTimeZoneIds()) {
|
||||
if (regionSet.contains(ianaId))
|
||||
set << ianaId;
|
||||
}
|
||||
|
||||
return set;
|
||||
|
@ -385,16 +385,16 @@ QSet<QByteArray> QTimeZonePrivate::availableTimeZoneIds(int offsetFromUtc) const
|
|||
for (int j = 0; j < zoneDataTableSize; ++j) {
|
||||
const QZoneData *data = zoneData(j);
|
||||
if (data->windowsIdKey == winData->windowsIdKey)
|
||||
offsetSet += olsenId(data).split(' ').toSet();
|
||||
offsetSet += ianaId(data).split(' ').toSet();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Then select just those that are available
|
||||
QSet<QByteArray> set;
|
||||
foreach (const QByteArray &olsenId, availableTimeZoneIds()) {
|
||||
if (offsetSet.contains(olsenId))
|
||||
set << olsenId;
|
||||
foreach (const QByteArray &ianaId, availableTimeZoneIds()) {
|
||||
if (offsetSet.contains(ianaId))
|
||||
set << ianaId;
|
||||
}
|
||||
|
||||
return set;
|
||||
|
@ -443,17 +443,17 @@ QTimeZone::OffsetData QTimeZonePrivate::toOffsetData(const QTimeZonePrivate::Dat
|
|||
}
|
||||
|
||||
// If the format of the ID is valid
|
||||
bool QTimeZonePrivate::isValidId(const QByteArray &olsenId)
|
||||
bool QTimeZonePrivate::isValidId(const QByteArray &ianaId)
|
||||
{
|
||||
// Rules for defining TZ/Olsen names as per ftp://ftp.iana.org/tz/code/Theory
|
||||
// Rules for defining TZ/IANA names as per ftp://ftp.iana.org/tz/code/Theory
|
||||
// * Use only valid POSIX file name components
|
||||
// * Within a file name component, use only ASCII letters, `.', `-' and `_'.
|
||||
// * Do not use digits
|
||||
// * A file name component must not exceed 14 characters or start with `-'
|
||||
// Aliases such as "Etc/GMT+7" and "SystemV/EST5EDT" are valid so we need to accept digits
|
||||
if (olsenId.contains(' '))
|
||||
if (ianaId.contains(' '))
|
||||
return false;
|
||||
QList<QByteArray> parts = olsenId.split('/');
|
||||
QList<QByteArray> parts = ianaId.split('/');
|
||||
foreach (const QByteArray &part, parts) {
|
||||
if (part.size() > 14 || part.size() < 1)
|
||||
return false;
|
||||
|
@ -487,7 +487,7 @@ QByteArray QTimeZonePrivate::ianaIdToWindowsId(const QByteArray &id)
|
|||
{
|
||||
for (int i = 0; i < zoneDataTableSize; ++i) {
|
||||
const QZoneData *data = zoneData(i);
|
||||
if (olsenId(data).split(' ').contains(id))
|
||||
if (ianaId(data).split(' ').contains(id))
|
||||
return toWindowsIdLiteral(data->windowsIdKey);
|
||||
}
|
||||
return QByteArray();
|
||||
|
@ -499,7 +499,7 @@ QByteArray QTimeZonePrivate::windowsIdToDefaultIanaId(const QByteArray &windowsI
|
|||
for (int i = 0; i < windowsDataTableSize; ++i) {
|
||||
const QWindowsData *data = windowsData(i);
|
||||
if (data->windowsIdKey == windowsIdKey)
|
||||
return olsenId(data);
|
||||
return ianaId(data);
|
||||
}
|
||||
return QByteArray();
|
||||
}
|
||||
|
@ -522,7 +522,7 @@ QList<QByteArray> QTimeZonePrivate::windowsIdToIanaIds(const QByteArray &windows
|
|||
for (int i = 0; i < zoneDataTableSize; ++i) {
|
||||
const QZoneData *data = zoneData(i);
|
||||
if (data->windowsIdKey == windowsIdKey)
|
||||
list << olsenId(data).split(' ');
|
||||
list << ianaId(data).split(' ');
|
||||
}
|
||||
|
||||
// Return the full list in alpha order
|
||||
|
@ -538,7 +538,7 @@ QList<QByteArray> QTimeZonePrivate::windowsIdToIanaIds(const QByteArray &windows
|
|||
const QZoneData *data = zoneData(i);
|
||||
// Return the region matches in preference order
|
||||
if (data->windowsIdKey == windowsIdKey && data->country == (quint16) country)
|
||||
return olsenId(data).split(' ');
|
||||
return ianaId(data).split(' ');
|
||||
}
|
||||
|
||||
return QList<QByteArray>();
|
||||
|
|
|
@ -74,19 +74,19 @@ QT_BEGIN_NAMESPACE
|
|||
|
||||
struct QZoneData {
|
||||
quint16 windowsIdKey; // Windows ID Key
|
||||
quint16 country; // Country of Olsen ID's, AnyCountry means No Country
|
||||
quint16 olsenIdIndex; // All Olsen ID's for the Windows ID and Country, space separated
|
||||
quint16 country; // Country of IANA ID's, AnyCountry means No Country
|
||||
quint16 ianaIdIndex; // All IANA ID's for the Windows ID and Country, space separated
|
||||
};
|
||||
|
||||
struct QWindowsData {
|
||||
quint16 windowsIdKey; // Windows ID Key
|
||||
quint16 windowsIdIndex; // Windows ID Literal
|
||||
quint16 olsenIdIndex; // Default Olsen ID for the Windows ID
|
||||
quint16 ianaIdIndex; // Default IANA ID for the Windows ID
|
||||
qint32 offsetFromUtc; // Standard Time Offset from UTC, used for quick look-ups
|
||||
};
|
||||
|
||||
struct QUtcData {
|
||||
quint16 olsenIdIndex; // Olsen ID's
|
||||
quint16 ianaIdIndex; // IANA ID's
|
||||
qint32 offsetFromUtc; // Offset form UTC is seconds
|
||||
};
|
||||
|
||||
|
@ -123,7 +123,7 @@ struct QUtcData {
|
|||
Do not change this data, only generate it using cldr2qtimezone.py.
|
||||
*/
|
||||
|
||||
// Windows ID Key, Country Enum, Olsen ID Index
|
||||
// Windows ID Key, Country Enum, IANA ID Index
|
||||
static const QZoneData zoneDataTable[] = {
|
||||
{ 95, 157, 0 }, // W. Central Africa Standard Time / Nigeria
|
||||
{ 36, 73, 13 }, // FLE Standard Time / Finland
|
||||
|
@ -463,7 +463,7 @@ static const QZoneData zoneDataTable[] = {
|
|||
{ 0, 0, 0 } // Trailing zeroes
|
||||
};
|
||||
|
||||
// Windows ID Key, Windows ID Index, Olsen ID Index, UTC Offset
|
||||
// Windows ID Key, Windows ID Index, IANA ID Index, UTC Offset
|
||||
static const QWindowsData windowsDataTable[] = {
|
||||
{ 1, 0, 997, 16200 }, // Afghanistan Standard Time
|
||||
{ 2, 26, 6863,-32400 }, // Alaskan Standard Time
|
||||
|
@ -567,7 +567,7 @@ static const QWindowsData windowsDataTable[] = {
|
|||
{ 0, 0, 0, 0 } // Trailing zeroes
|
||||
};
|
||||
|
||||
// Olsen ID Index, UTC Offset
|
||||
// IANA ID Index, UTC Offset
|
||||
static const QUtcData utcDataTable[] = {
|
||||
{ 7257, 0 }, // UTC
|
||||
{ 7261,-50400 }, // UTC-14:00
|
||||
|
@ -730,7 +730,7 @@ static const char windowsIdData[] = {
|
|||
0x75, 0x74, 0x73, 0x6b, 0x20, 0x53, 0x74, 0x61, 0x6e, 0x64, 0x61, 0x72, 0x64, 0x20, 0x54, 0x69, 0x6d, 0x65, 0x0
|
||||
};
|
||||
|
||||
static const char olsenIdData[] = {
|
||||
static const char ianaIdData[] = {
|
||||
0x41, 0x66, 0x72, 0x69, 0x63, 0x61, 0x2f, 0x4c, 0x61, 0x67, 0x6f, 0x73, 0x0, 0x45, 0x75, 0x72, 0x6f, 0x70, 0x65, 0x2f,
|
||||
0x48, 0x65, 0x6c, 0x73, 0x69, 0x6e, 0x6b, 0x69, 0x0, 0x41, 0x73, 0x69, 0x61, 0x2f, 0x48, 0x6f, 0x6e, 0x67, 0x5f, 0x4b,
|
||||
0x6f, 0x6e, 0x67, 0x0, 0x50, 0x61, 0x63, 0x69, 0x66, 0x69, 0x63, 0x2f, 0x45, 0x6e, 0x64, 0x65, 0x72, 0x62, 0x75, 0x72,
|
||||
|
|
|
@ -277,12 +277,12 @@ QIcuTimeZonePrivate::QIcuTimeZonePrivate()
|
|||
}
|
||||
|
||||
// Create a named time zone
|
||||
QIcuTimeZonePrivate::QIcuTimeZonePrivate(const QByteArray &olsenId)
|
||||
QIcuTimeZonePrivate::QIcuTimeZonePrivate(const QByteArray &ianaId)
|
||||
: m_ucal(0)
|
||||
{
|
||||
// Need to check validity here as ICu will create a GMT tz if name is invalid
|
||||
if (availableTimeZoneIds().contains(olsenId))
|
||||
init(olsenId);
|
||||
if (availableTimeZoneIds().contains(ianaId))
|
||||
init(ianaId);
|
||||
}
|
||||
|
||||
QIcuTimeZonePrivate::QIcuTimeZonePrivate(const QIcuTimeZonePrivate &other)
|
||||
|
@ -307,9 +307,9 @@ QTimeZonePrivate *QIcuTimeZonePrivate::clone()
|
|||
return new QIcuTimeZonePrivate(*this);
|
||||
}
|
||||
|
||||
void QIcuTimeZonePrivate::init(const QByteArray &olsenId)
|
||||
void QIcuTimeZonePrivate::init(const QByteArray &ianaId)
|
||||
{
|
||||
m_id = olsenId;
|
||||
m_id = ianaId;
|
||||
|
||||
const QString id = QString::fromUtf8(m_id);
|
||||
UErrorCode status = U_ZERO_ERROR;
|
||||
|
|
|
@ -64,10 +64,10 @@ QMacTimeZonePrivate::QMacTimeZonePrivate()
|
|||
}
|
||||
|
||||
// Create a named time zone
|
||||
QMacTimeZonePrivate::QMacTimeZonePrivate(const QByteArray &olsenId)
|
||||
QMacTimeZonePrivate::QMacTimeZonePrivate(const QByteArray &ianaId)
|
||||
: m_nstz(0)
|
||||
{
|
||||
init(olsenId);
|
||||
init(ianaId);
|
||||
}
|
||||
|
||||
QMacTimeZonePrivate::QMacTimeZonePrivate(const QMacTimeZonePrivate &other)
|
||||
|
@ -86,12 +86,12 @@ QTimeZonePrivate *QMacTimeZonePrivate::clone()
|
|||
return new QMacTimeZonePrivate(*this);
|
||||
}
|
||||
|
||||
void QMacTimeZonePrivate::init(const QByteArray &olsenId)
|
||||
void QMacTimeZonePrivate::init(const QByteArray &ianaId)
|
||||
{
|
||||
if (availableTimeZoneIds().contains(olsenId)) {
|
||||
m_nstz = [NSTimeZone timeZoneWithName:QCFString::toNSString(QString::fromUtf8(olsenId))];
|
||||
if (availableTimeZoneIds().contains(ianaId)) {
|
||||
m_nstz = [NSTimeZone timeZoneWithName:QCFString::toNSString(QString::fromUtf8(ianaId))];
|
||||
if (m_nstz)
|
||||
m_id = olsenId;
|
||||
m_id = ianaId;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -143,7 +143,7 @@ public:
|
|||
static Data invalidData();
|
||||
static QTimeZone::OffsetData invalidOffsetData();
|
||||
static QTimeZone::OffsetData toOffsetData(const Data &data);
|
||||
static bool isValidId(const QByteArray &olsenId);
|
||||
static bool isValidId(const QByteArray &ianaId);
|
||||
static QString isoOffsetFormat(int offsetFromUtc);
|
||||
|
||||
static QByteArray ianaIdToWindowsId(const QByteArray &ianaId);
|
||||
|
@ -217,7 +217,7 @@ public:
|
|||
// Create default time zone
|
||||
QIcuTimeZonePrivate();
|
||||
// Create named time zone
|
||||
QIcuTimeZonePrivate(const QByteArray &olsenId);
|
||||
QIcuTimeZonePrivate(const QByteArray &ianaId);
|
||||
QIcuTimeZonePrivate(const QIcuTimeZonePrivate &other);
|
||||
~QIcuTimeZonePrivate();
|
||||
|
||||
|
@ -247,7 +247,7 @@ public:
|
|||
QSet<QByteArray> availableTimeZoneIds(int offsetFromUtc) const Q_DECL_OVERRIDE;
|
||||
|
||||
private:
|
||||
void init(const QByteArray &olsenId);
|
||||
void init(const QByteArray &ianaId);
|
||||
|
||||
UCalendar *m_ucal;
|
||||
};
|
||||
|
@ -260,7 +260,7 @@ public:
|
|||
// Create default time zone
|
||||
QTzTimeZonePrivate();
|
||||
// Create named time zone
|
||||
QTzTimeZonePrivate(const QByteArray &olsenId);
|
||||
QTzTimeZonePrivate(const QByteArray &ianaId);
|
||||
QTzTimeZonePrivate(const QTzTimeZonePrivate &other);
|
||||
~QTzTimeZonePrivate();
|
||||
|
||||
|
@ -296,7 +296,7 @@ public:
|
|||
QSet<QByteArray> availableTimeZoneIds(QLocale::Country country) const Q_DECL_OVERRIDE;
|
||||
|
||||
private:
|
||||
void init(const QByteArray &olsenId);
|
||||
void init(const QByteArray &ianaId);
|
||||
|
||||
struct QTzTransitionTime {
|
||||
qint64 atMSecsSinceEpoch;
|
||||
|
@ -327,7 +327,7 @@ public:
|
|||
// Create default time zone
|
||||
QMacTimeZonePrivate();
|
||||
// Create named time zone
|
||||
QMacTimeZonePrivate(const QByteArray &olsenId);
|
||||
QMacTimeZonePrivate(const QByteArray &ianaId);
|
||||
QMacTimeZonePrivate(const QMacTimeZonePrivate &other);
|
||||
~QMacTimeZonePrivate();
|
||||
|
||||
|
@ -378,7 +378,7 @@ public:
|
|||
// Create default time zone
|
||||
QWinTimeZonePrivate();
|
||||
// Create named time zone
|
||||
QWinTimeZonePrivate(const QByteArray &olsenId);
|
||||
QWinTimeZonePrivate(const QByteArray &ianaId);
|
||||
QWinTimeZonePrivate(const QWinTimeZonePrivate &other);
|
||||
~QWinTimeZonePrivate();
|
||||
|
||||
|
@ -408,7 +408,7 @@ public:
|
|||
QSet<QByteArray> availableTimeZoneIds() const Q_DECL_OVERRIDE;
|
||||
|
||||
private:
|
||||
void init(const QByteArray &olsenId);
|
||||
void init(const QByteArray &ianaId);
|
||||
QWinTransitionRule ruleForYear(int year) const;
|
||||
QTimeZonePrivate::Data ruleToData(const QWinTransitionRule &rule, qint64 atMSecsSinceEpoch,
|
||||
QTimeZone::TimeType type) const;
|
||||
|
|
|
@ -523,12 +523,12 @@ QTzTimeZonePrivate::QTzTimeZonePrivate()
|
|||
}
|
||||
|
||||
// Create a named time zone
|
||||
QTzTimeZonePrivate::QTzTimeZonePrivate(const QByteArray &olsenId)
|
||||
QTzTimeZonePrivate::QTzTimeZonePrivate(const QByteArray &ianaId)
|
||||
#ifdef QT_USE_ICU
|
||||
: m_icu(0)
|
||||
#endif // QT_USE_ICU
|
||||
{
|
||||
init(olsenId);
|
||||
init(ianaId);
|
||||
}
|
||||
|
||||
QTzTimeZonePrivate::QTzTimeZonePrivate(const QTzTimeZonePrivate &other)
|
||||
|
@ -550,19 +550,19 @@ QTimeZonePrivate *QTzTimeZonePrivate::clone()
|
|||
return new QTzTimeZonePrivate(*this);
|
||||
}
|
||||
|
||||
void QTzTimeZonePrivate::init(const QByteArray &olsenId)
|
||||
void QTzTimeZonePrivate::init(const QByteArray &ianaId)
|
||||
{
|
||||
QFile tzif;
|
||||
if (olsenId.isEmpty()) {
|
||||
if (ianaId.isEmpty()) {
|
||||
// Open system tz
|
||||
tzif.setFileName(QStringLiteral("/etc/localtime"));
|
||||
if (!tzif.open(QIODevice::ReadOnly))
|
||||
return;
|
||||
} else {
|
||||
// Open named tz, try modern path first, if fails try legacy path
|
||||
tzif.setFileName(QLatin1String("/usr/share/zoneinfo/") + QString::fromLocal8Bit(olsenId));
|
||||
tzif.setFileName(QLatin1String("/usr/share/zoneinfo/") + QString::fromLocal8Bit(ianaId));
|
||||
if (!tzif.open(QIODevice::ReadOnly)) {
|
||||
tzif.setFileName(QLatin1String("/usr/lib/zoneinfo/") + QString::fromLocal8Bit(olsenId));
|
||||
tzif.setFileName(QLatin1String("/usr/lib/zoneinfo/") + QString::fromLocal8Bit(ianaId));
|
||||
if (!tzif.open(QIODevice::ReadOnly))
|
||||
return;
|
||||
}
|
||||
|
@ -667,10 +667,10 @@ void QTzTimeZonePrivate::init(const QByteArray &olsenId)
|
|||
m_tranTimes.append(tran);
|
||||
}
|
||||
|
||||
if (olsenId.isEmpty())
|
||||
if (ianaId.isEmpty())
|
||||
m_id = systemTimeZoneId();
|
||||
else
|
||||
m_id = olsenId;
|
||||
m_id = ianaId;
|
||||
}
|
||||
|
||||
QLocale::Country QTzTimeZonePrivate::country() const
|
||||
|
@ -912,55 +912,55 @@ QTimeZonePrivate::Data QTzTimeZonePrivate::previousTransition(qint64 beforeMSecs
|
|||
QByteArray QTzTimeZonePrivate::systemTimeZoneId() const
|
||||
{
|
||||
// Check TZ env var first, if not populated try find it
|
||||
QByteArray olsenId = qgetenv("TZ");
|
||||
if (!olsenId.isEmpty() && olsenId.at(0) == ':')
|
||||
olsenId = olsenId.mid(1);
|
||||
QByteArray ianaId = qgetenv("TZ");
|
||||
if (!ianaId.isEmpty() && ianaId.at(0) == ':')
|
||||
ianaId = ianaId.mid(1);
|
||||
|
||||
// On Debian Etch and later /etc/localtime is real file with name held in /etc/timezone
|
||||
if (olsenId.isEmpty()) {
|
||||
if (ianaId.isEmpty()) {
|
||||
QFile tzif(QStringLiteral("/etc/timezone"));
|
||||
if (tzif.open(QIODevice::ReadOnly)) {
|
||||
// TODO QTextStream inefficient, replace later
|
||||
QTextStream ts(&tzif);
|
||||
if (!ts.atEnd())
|
||||
olsenId = ts.readLine().toUtf8();
|
||||
ianaId = ts.readLine().toUtf8();
|
||||
}
|
||||
}
|
||||
|
||||
// On other distros /etc/localtime is symlink to real file so can extract name from the path
|
||||
if (olsenId.isEmpty()) {
|
||||
if (ianaId.isEmpty()) {
|
||||
const QString path = QFile::symLinkTarget(QStringLiteral("/etc/localtime"));
|
||||
if (!path.isEmpty()) {
|
||||
// /etc/localtime is a symlink to the current TZ file, so extract from path
|
||||
int index = path.indexOf(QLatin1String("/zoneinfo/")) + 10;
|
||||
olsenId = path.mid(index).toUtf8();
|
||||
ianaId = path.mid(index).toUtf8();
|
||||
}
|
||||
}
|
||||
|
||||
// On some Red Hat distros /etc/localtime is real file with name held in /etc/sysconfig/clock
|
||||
// in a line like ZONE="Europe/Oslo" or TIMEZONE="Europe/Oslo"
|
||||
if (olsenId.isEmpty()) {
|
||||
if (ianaId.isEmpty()) {
|
||||
QFile tzif(QStringLiteral("/etc/sysconfig/clock"));
|
||||
if (tzif.open(QIODevice::ReadOnly)) {
|
||||
// TODO QTextStream inefficient, replace later
|
||||
QTextStream ts(&tzif);
|
||||
QString line;
|
||||
while (olsenId.isEmpty() && !ts.atEnd() && ts.status() == QTextStream::Ok) {
|
||||
while (ianaId.isEmpty() && !ts.atEnd() && ts.status() == QTextStream::Ok) {
|
||||
line = ts.readLine();
|
||||
if (line.left(5) == QStringLiteral("ZONE=")) {
|
||||
olsenId = line.mid(6, line.size() - 7).toUtf8();
|
||||
ianaId = line.mid(6, line.size() - 7).toUtf8();
|
||||
} else if (line.left(9) == QStringLiteral("TIMEZONE=")) {
|
||||
olsenId = line.mid(10, line.size() - 11).toUtf8();
|
||||
ianaId = line.mid(10, line.size() - 11).toUtf8();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Give up for now and return UTC
|
||||
if (olsenId.isEmpty())
|
||||
olsenId = QByteArrayLiteral("UTC");
|
||||
if (ianaId.isEmpty())
|
||||
ianaId = QByteArrayLiteral("UTC");
|
||||
|
||||
return olsenId;
|
||||
return ianaId;
|
||||
}
|
||||
|
||||
QSet<QByteArray> QTzTimeZonePrivate::availableTimeZoneIds() const
|
||||
|
|
|
@ -334,10 +334,10 @@ QWinTimeZonePrivate::QWinTimeZonePrivate()
|
|||
}
|
||||
|
||||
// Create a named time zone
|
||||
QWinTimeZonePrivate::QWinTimeZonePrivate(const QByteArray &olsenId)
|
||||
QWinTimeZonePrivate::QWinTimeZonePrivate(const QByteArray &ianaId)
|
||||
: QTimeZonePrivate()
|
||||
{
|
||||
init(olsenId);
|
||||
init(ianaId);
|
||||
}
|
||||
|
||||
QWinTimeZonePrivate::QWinTimeZonePrivate(const QWinTimeZonePrivate &other)
|
||||
|
@ -356,14 +356,14 @@ QTimeZonePrivate *QWinTimeZonePrivate::clone()
|
|||
return new QWinTimeZonePrivate(*this);
|
||||
}
|
||||
|
||||
void QWinTimeZonePrivate::init(const QByteArray &olsenId)
|
||||
void QWinTimeZonePrivate::init(const QByteArray &ianaId)
|
||||
{
|
||||
if (olsenId.isEmpty()) {
|
||||
if (ianaId.isEmpty()) {
|
||||
m_windowsId = windowsSystemZoneId();
|
||||
m_id = systemTimeZoneId();
|
||||
} else {
|
||||
m_windowsId = ianaIdToWindowsId(olsenId);
|
||||
m_id = olsenId;
|
||||
m_windowsId = ianaIdToWindowsId(ianaId);
|
||||
m_id = ianaId;
|
||||
}
|
||||
|
||||
if (!m_windowsId.isEmpty()) {
|
||||
|
@ -626,26 +626,26 @@ QByteArray QWinTimeZonePrivate::systemTimeZoneId() const
|
|||
{
|
||||
const QLocale::Country country = userCountry();
|
||||
const QByteArray windowsId = windowsSystemZoneId();
|
||||
QByteArray olsenId;
|
||||
QByteArray ianaId;
|
||||
// If we have a real country, then try get a specific match for that country
|
||||
if (country != QLocale::AnyCountry)
|
||||
olsenId = windowsIdToDefaultIanaId(windowsId, country);
|
||||
ianaId = windowsIdToDefaultIanaId(windowsId, country);
|
||||
// If we don't have a real country, or there wasn't a specific match, try the global default
|
||||
if (olsenId.isEmpty()) {
|
||||
olsenId = windowsIdToDefaultIanaId(windowsId);
|
||||
if (ianaId.isEmpty()) {
|
||||
ianaId = windowsIdToDefaultIanaId(windowsId);
|
||||
// If no global default then probably an unknown Windows ID so return UTC
|
||||
if (olsenId.isEmpty())
|
||||
if (ianaId.isEmpty())
|
||||
return QByteArrayLiteral("UTC");
|
||||
}
|
||||
return olsenId;
|
||||
return ianaId;
|
||||
}
|
||||
|
||||
QSet<QByteArray> QWinTimeZonePrivate::availableTimeZoneIds() const
|
||||
{
|
||||
QSet<QByteArray> set;
|
||||
foreach (const QByteArray &winId, availableWindowsIds()) {
|
||||
foreach (const QByteArray &olsenId, windowsIdToIanaIds(winId))
|
||||
set << olsenId;
|
||||
foreach (const QByteArray &ianaId, windowsIdToIanaIds(winId))
|
||||
set << ianaId;
|
||||
}
|
||||
return set;
|
||||
}
|
||||
|
|
|
@ -296,7 +296,7 @@ if mapTimezones:
|
|||
if attribute[0] == u'territory':
|
||||
data['countryCode'] = attribute[1]
|
||||
if attribute[0] == u'type':
|
||||
data['olsenList'] = attribute[1]
|
||||
data['ianaList'] = attribute[1]
|
||||
|
||||
data['windowsKey'] = windowsIdToKey(data['windowsId'])
|
||||
if data['windowsKey'] <= 0:
|
||||
|
@ -304,7 +304,7 @@ if mapTimezones:
|
|||
|
||||
countryId = 0
|
||||
if data['countryCode'] == u'001':
|
||||
defaultDict[data['windowsKey']] = data['olsenList']
|
||||
defaultDict[data['windowsKey']] = data['ianaList']
|
||||
else:
|
||||
data['countryId'] = enumdata.countryCodeToId(data['countryCode'])
|
||||
if data['countryId'] < 0:
|
||||
|
@ -342,17 +342,17 @@ newTempFile.write("\n\
|
|||
*/\n\n" % (str(datetime.date.today()), versionNumber, generationDate) )
|
||||
|
||||
windowsIdData = ByteArrayData()
|
||||
olsenIdData = ByteArrayData()
|
||||
ianaIdData = ByteArrayData()
|
||||
|
||||
# Write Windows/Olsen table
|
||||
newTempFile.write("// Windows ID Key, Country Enum, Olsen ID Index\n")
|
||||
# Write Windows/IANA table
|
||||
newTempFile.write("// Windows ID Key, Country Enum, IANA ID Index\n")
|
||||
newTempFile.write("static const QZoneData zoneDataTable[] = {\n")
|
||||
for index in windowsIdDict:
|
||||
data = windowsIdDict[index]
|
||||
newTempFile.write(" { %6d,%6d,%6d }, // %s / %s\n" \
|
||||
% (data['windowsKey'],
|
||||
data['countryId'],
|
||||
olsenIdData.append(data['olsenList']),
|
||||
ianaIdData.append(data['ianaList']),
|
||||
data['windowsId'],
|
||||
data['country']))
|
||||
newTempFile.write(" { 0, 0, 0 } // Trailing zeroes\n")
|
||||
|
@ -361,13 +361,13 @@ newTempFile.write("};\n\n")
|
|||
print "Done Zone Data"
|
||||
|
||||
# Write Windows ID key table
|
||||
newTempFile.write("// Windows ID Key, Windows ID Index, Olsen ID Index, UTC Offset\n")
|
||||
newTempFile.write("// Windows ID Key, Windows ID Index, IANA ID Index, UTC Offset\n")
|
||||
newTempFile.write("static const QWindowsData windowsDataTable[] = {\n")
|
||||
for windowsKey in windowsIdList:
|
||||
newTempFile.write(" { %6d,%6d,%6d,%6d }, // %s\n" \
|
||||
% (windowsKey,
|
||||
windowsIdData.append(windowsIdList[windowsKey][0]),
|
||||
olsenIdData.append(defaultDict[windowsKey]),
|
||||
ianaIdData.append(defaultDict[windowsKey]),
|
||||
windowsIdList[windowsKey][1],
|
||||
windowsIdList[windowsKey][0]))
|
||||
newTempFile.write(" { 0, 0, 0, 0 } // Trailing zeroes\n")
|
||||
|
@ -376,12 +376,12 @@ newTempFile.write("};\n\n")
|
|||
print "Done Windows Data Table"
|
||||
|
||||
# Write UTC ID key table
|
||||
newTempFile.write("// Olsen ID Index, UTC Offset\n")
|
||||
newTempFile.write("// IANA ID Index, UTC Offset\n")
|
||||
newTempFile.write("static const QUtcData utcDataTable[] = {\n")
|
||||
for index in utcIdList:
|
||||
data = utcIdList[index]
|
||||
newTempFile.write(" { %6d,%6d }, // %s\n" \
|
||||
% (olsenIdData.append(data[0]),
|
||||
% (ianaIdData.append(data[0]),
|
||||
data[1],
|
||||
data[0]))
|
||||
newTempFile.write(" { 0, 0 } // Trailing zeroes\n")
|
||||
|
@ -394,9 +394,9 @@ newTempFile.write("static const char windowsIdData[] = {\n")
|
|||
newTempFile.write(wrap_list(windowsIdData.data))
|
||||
newTempFile.write("\n};\n\n")
|
||||
|
||||
# Write out Olsen ID's data
|
||||
newTempFile.write("static const char olsenIdData[] = {\n")
|
||||
newTempFile.write(wrap_list(olsenIdData.data))
|
||||
# Write out IANA ID's data
|
||||
newTempFile.write("static const char ianaIdData[] = {\n")
|
||||
newTempFile.write(wrap_list(ianaIdData.data))
|
||||
newTempFile.write("\n};\n")
|
||||
|
||||
print "Done ID Data Table"
|
||||
|
|
Loading…
Reference in New Issue