Enable QIcuTimeZonePrivate's support for transitions

The support was previously limited to ICU version 50, with an == check
rather than a >= one, accompanied by a TODO comment to check whether
the API was stable at 51. Nine years have passed since ICU 51 was
released, we're now up to release 70, and now I've finally verified
that the API is stable (and fixed a few bugs in how we use it). So
change the check so that we now do use the transition API.

Fixes: QTBUG-99747
Pick-to: 6.3 6.2
Change-Id: Ica024b6c28a213e0de0a37f196839e8ded193889
Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
This commit is contained in:
Edward Welbourne 2022-03-23 15:32:05 +01:00
parent 934b528715
commit eda8b7b4da

View File

@ -183,8 +183,7 @@ static bool ucalOffsetsAtTime(UCalendar *m_ucal, qint64 atMSecsSinceEpoch,
return false;
}
// ICU Draft api in v50, should be stable in ICU v51. Available in C++ api from ICU v3.8
#if U_ICU_VERSION_MAJOR_NUM == 50
#if U_ICU_VERSION_MAJOR_NUM >= 50
// Qt wrapper around qt_ucal_getTimeZoneTransitionDate & ucal_get
static QTimeZonePrivate::Data ucalTimeZoneTransition(UCalendar *m_ucal,
UTimeZoneTransitionType type,
@ -388,7 +387,7 @@ bool QIcuTimeZonePrivate::hasDaylightTime() const
{
if (ucalDaylightOffset(m_id) != 0)
return true;
#if U_ICU_VERSION_MAJOR_NUM == 50
#if U_ICU_VERSION_MAJOR_NUM >= 50
for (qint64 when = minMSecs(); when != invalidMSecs(); ) {
auto data = nextTransition(when);
if (data.daylightTimeOffset && data.daylightTimeOffset != invalidSeconds())
@ -424,13 +423,12 @@ bool QIcuTimeZonePrivate::isDaylightTime(qint64 atMSecsSinceEpoch) const
QTimeZonePrivate::Data QIcuTimeZonePrivate::data(qint64 forMSecsSinceEpoch) const
{
// Available in ICU C++ api, and draft C api in v50
// TODO When v51 released see if api is stable
QTimeZonePrivate::Data data = invalidData();
#if U_ICU_VERSION_MAJOR_NUM == 50
#if U_ICU_VERSION_MAJOR_NUM >= 50
data = ucalTimeZoneTransition(m_ucal, UCAL_TZ_TRANSITION_PREVIOUS_INCLUSIVE,
forMSecsSinceEpoch);
if (data.atMSecsSinceEpoch == invalidMSecs()) // before first transition
#endif // U_ICU_VERSION_MAJOR_NUM >= 50
#endif
{
ucalOffsetsAtTime(m_ucal, forMSecsSinceEpoch, &data.standardTimeOffset,
&data.daylightTimeOffset);
@ -444,36 +442,33 @@ QTimeZonePrivate::Data QIcuTimeZonePrivate::data(qint64 forMSecsSinceEpoch) cons
bool QIcuTimeZonePrivate::hasTransitions() const
{
// Available in ICU C++ api, and draft C api in v50
// TODO When v51 released see if api is stable
#if U_ICU_VERSION_MAJOR_NUM == 50
#if U_ICU_VERSION_MAJOR_NUM >= 50
return true;
#else
return false;
#endif // U_ICU_VERSION_MAJOR_NUM == 50
#endif
}
QTimeZonePrivate::Data QIcuTimeZonePrivate::nextTransition(qint64 afterMSecsSinceEpoch) const
{
// Available in ICU C++ api, and draft C api in v50
// TODO When v51 released see if api is stable
#if U_ICU_VERSION_MAJOR_NUM == 50
#if U_ICU_VERSION_MAJOR_NUM >= 50
return ucalTimeZoneTransition(m_ucal, UCAL_TZ_TRANSITION_NEXT, afterMSecsSinceEpoch);
#else
Q_UNUSED(afterMSecsSinceEpoch);
return invalidData();
#endif // U_ICU_VERSION_MAJOR_NUM == 50
#endif
}
QTimeZonePrivate::Data QIcuTimeZonePrivate::previousTransition(qint64 beforeMSecsSinceEpoch) const
{
// Available in ICU C++ api, and draft C api in v50
// TODO When v51 released see if api is stable
#if U_ICU_VERSION_MAJOR_NUM == 50
#if U_ICU_VERSION_MAJOR_NUM >= 50
return ucalTimeZoneTransition(m_ucal, UCAL_TZ_TRANSITION_PREVIOUS, beforeMSecsSinceEpoch);
#else
Q_UNUSED(beforeMSecsSinceEpoch);
return invalidData();
#endif // U_ICU_VERSION_MAJOR_NUM == 50
#endif
}
QByteArray QIcuTimeZonePrivate::systemTimeZoneId() const