File indexing completed on 2024-03-24 03:57:18
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_name_table.cpp" 0009 #include "kcountry.h" 0010 #include "spatial_index_p.h" 0011 0012 #include <QTimeZone> 0013 0014 #include <cstring> 0015 0016 const char *KTimeZone::fromLocation(float latitude, float longitude) 0017 { 0018 const auto entry = SpatialIndex::lookup(latitude, longitude); 0019 return timezone_name_table + entry.m_tz; 0020 } 0021 0022 KCountry KTimeZone::country(const char *ianaId) 0023 { 0024 // Asia/Bangkok is special as it's the only "regular" IANA tz that covers more than one country 0025 // (northern Vietnam and Thailand in this case), QTimeZone however reports it as Thailand. 0026 if (!ianaId || std::strcmp(ianaId, "") == 0 || std::strcmp(ianaId, "Asia/Bangkok") == 0) { 0027 return {}; 0028 } 0029 0030 return KCountry::fromQLocale(QTimeZone(ianaId).territory()); 0031 }