File indexing completed on 2024-04-28 11:40:13
0001 /* 0002 SPDX-FileCopyrightText: 2021 Volker Krause <vkrause@kde.org> 0003 0004 SPDX-License-Identifier: LGPL-2.0-or-later 0005 */ 0006 0007 #include "ktimezone.h" 0008 #include "data/timezone_country_map.cpp" 0009 #include "data/timezone_name_table.cpp" 0010 #include "kcountry.h" 0011 #include "spatial_index_p.h" 0012 0013 #include <cstring> 0014 0015 const char *KTimeZone::fromLocation(float latitude, float longitude) 0016 { 0017 const auto entry = SpatialIndex::lookup(latitude, longitude); 0018 return timezone_name_table + entry.m_tz; 0019 } 0020 0021 KCountry KTimeZone::country(const char *ianaId) 0022 { 0023 if (!ianaId) { 0024 return {}; 0025 } 0026 0027 const auto it = std::lower_bound(std::begin(timezone_country_map), std::end(timezone_country_map), ianaId, [](auto lhs, auto rhs) { 0028 return std::strcmp(timezone_name_table + lhs.key, rhs) < 0; 0029 }); 0030 if (it != std::end(timezone_country_map) && std::strcmp(timezone_name_table + (*it).key, ianaId) == 0) { 0031 KCountry c; 0032 c.d = (*it).value; 0033 return c; 0034 } 0035 return {}; 0036 }