Commit 3da35611 authored by Volker Krause's avatar Volker Krause
Browse files

Try to find an equivalent timezone in the right country

This improves the situation for locations close to the boarder, where the
coordinate-based lookup gives us the equivalent timezone in the wrong
country, and where the right country has more than one timezone. This
particularly helps with CA <-> US and MX <-> US cases, and thus improves
test results for the airport location database.
parent 8ed24d9d
......@@ -106,6 +106,36 @@ KnowledgeDb::Tz KnowledgeDb::timezoneForLocation(float lat, float lon, CountryId
const auto countryTz = timezoneForCountry(country);
const auto countryFromCoord = countryForTimezone(coordTz);
// if we determine a different country than was provided, search for an equivalent timezone
// in the requested country
// example: Tijuana airport ending up in America/Los Angeles, and America/Tijuna being the only MX timezone equivalent to that
if (coordTz != Tz::Undefined && countryFromCoord.isValid() && countryFromCoord != country) {
bool nonUnique = false;
Tz foundTz = Tz::Undefined;
const auto coordZone = toQTimeZone(coordTz);
constexpr const int timezone_count = sizeof(timezone_country_map) / sizeof(timezone_country_map[0]);
for (int i = 1; i < timezone_count; ++i) {
if (timezone_country_map[i] != country) {
const auto t = static_cast<Tz>(i);
if (!isEquivalentTimezone(toQTimeZone(t), coordZone)) {
if (foundTz != Tz::Undefined) {
nonUnique = true;
foundTz = t;
if (!nonUnique && foundTz != Tz::Undefined) {
return foundTz;
// only one method found a result, let's use that one
if (coordTz == Tz::Undefined || coordTz == countryTz) {
return countryTz;
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