Have QDTP match longest form it can for local zone name
Previously, three candidates were tried (there shall soon be more) and
the length of the first to match was returned. This could go wrong if
tzname[] = { "GMT", "GMT+1" } and our text starts with the latter; we
would have only matched it to the former.
Change-Id: I8e7b9e6a382bdd527bb98be7c86ea67b11cdc13a
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
bb10
parent
bd5c6fab40
commit
4756062828
|
|
@ -1180,17 +1180,20 @@ static QTime actualTime(QDateTimeParser::Sections known,
|
|||
*/
|
||||
static int startsWithLocalTimeZone(QStringView name, const QDateTime &when)
|
||||
{
|
||||
// Pick longest match that we might get.
|
||||
qsizetype longest = 0;
|
||||
// On MS-Win, at least when system zone is UTC, the tzname[]s may be empty.
|
||||
for (int i = 0; i < 2; ++i) {
|
||||
const QString zone(qTzName(i));
|
||||
if (!zone.isEmpty() && name.startsWith(zone))
|
||||
return zone.size();
|
||||
if (zone.size() > longest && name.startsWith(zone))
|
||||
longest = zone.size();
|
||||
}
|
||||
// Mimic what QLocale::toString() would have used, to ensure round-trips work:
|
||||
const QString local = QDateTime(when.date(), when.time()).timeZoneAbbreviation();
|
||||
if (name.startsWith(local))
|
||||
return local.size();
|
||||
return 0;
|
||||
if (local.size() > longest && name.startsWith(local))
|
||||
longest = local.size();
|
||||
Q_ASSERT(longest <= INT_MAX); // Timezone names are not that long.
|
||||
return int(longest);
|
||||
}
|
||||
|
||||
/*!
|
||||
|
|
|
|||
Loading…
Reference in New Issue