Commit c0b485c7 authored by Volker Krause's avatar Volker Krause
Browse files

Deal with two special cases of timezones not mapping to exactly one country

That's Asia/Bangkok which is also used in northern Vietnam since the 2019
timezone shapefile release, and Europe/Simferopol which is a disputed area.
parent 86f897f1
......@@ -228,10 +228,11 @@ private Q_SLOTS:
{
using namespace KnowledgeDb;
qDebug() << countryForTimezone(Tz::Europe_Busingen).toString();
QCOMPARE(countryForTimezone(Tz::Europe_Busingen), CountryId{"DE"});
QCOMPARE(countryForTimezone(Tz::America_Los_Angeles), CountryId{"US"});
QCOMPARE(countryForTimezone(Tz::Asia_Kuching), CountryId{"MY"});
QCOMPARE(countryForTimezone(Tz::Asia_Bangkok), CountryId{});
QCOMPARE(countryForTimezone(Tz::Asia_Ho_Chi_Minh), CountryId{"VN"});
}
void testUICCountryCodeLookup()
......
......@@ -124,10 +124,15 @@ Timezones::Timezones()
/* Manual overrides for countries that de-facto only have a single timezone,
* even if the IANA database doesn't reflect that.
*/
m_countryZones[QStringLiteral("AR")] = { "America/Argentina/Buenos_Aires" };
m_countryZones[QStringLiteral("CN")] = { "Asia/Shanghai" };
m_countryZones[QStringLiteral("CY")] = { "Asia/Nicosia" };
m_countryZones[QStringLiteral("DE")] = { "Europe/Berlin" };
m_countryZones[QStringLiteral("MY")] = { "Asia/Kuala_Lumpur" };
/* Manual overrides for timezones that do not belong to a unique country, contrary what zonetab claims. */
setCountryForZone("Asia/Bangkok", {}); // also used in northern Vietnam
setCountryForZone("Europe/Simferopol", {}); // disputed area
}
Timezones::~Timezones() = default;
......@@ -210,3 +215,12 @@ QPoint Timezones::coordinateToPixel(KnowledgeDb::Coordinate coord) const
p.setY(qRound((coord.latitude - m_topLeftMapUnitY) / m_yMapUnitsPerPixel));
return p;
}
void Timezones::setCountryForZone(const QByteArray &tz, const QString &country)
{
auto it = m_countryForZone.find(tz);
if (it == m_countryForZone.end()) {
return;
}
(*it).second = country;
}
......@@ -47,6 +47,8 @@ private:
QPoint coordinateToPixel(KnowledgeDb::Coordinate coord) const;
QByteArray timezoneForPixel(int x, int y) const;
void setCountryForZone(const QByteArray &tz, const QString &country);
mutable QImage m_map;
QHash<QRgb, QByteArray> m_colorMap;
double m_xMapUnitsPerPixel;
......
......@@ -1318,7 +1318,7 @@ static constexpr const CountryId timezone_country_map[] = {
CountryId{"IQ"}, // Asia/Baghdad
CountryId{"BH"}, // Asia/Bahrain
CountryId{"AZ"}, // Asia/Baku
CountryId{"TH"}, // Asia/Bangkok
CountryId{}, // Asia/Bangkok
CountryId{"RU"}, // Asia/Barnaul
CountryId{"CN"}, // Asia/Beijing
CountryId{"LB"}, // Asia/Beirut
......@@ -1456,7 +1456,7 @@ static constexpr const CountryId timezone_country_map[] = {
CountryId{"SM"}, // Europe/San_Marino
CountryId{"BA"}, // Europe/Sarajevo
CountryId{"RU"}, // Europe/Saratov
CountryId{"UA"}, // Europe/Simferopol
CountryId{}, // Europe/Simferopol
CountryId{"MK"}, // Europe/Skopje
CountryId{"BG"}, // Europe/Sofia
CountryId{"SE"}, // Europe/Stockholm
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment