1 | /* |
---|---|
2 | SPDX-FileCopyrightText: 2021 Volker Krause <vkrause@kde.org> |
3 | |
4 | SPDX-License-Identifier: LGPL-2.0-or-later |
5 | */ |
6 | |
7 | #include "ktimezone.h" |
8 | #include "data/timezone_name_table.cpp" |
9 | #include "kcountry.h" |
10 | #include "spatial_index_p.h" |
11 | |
12 | #include <QTimeZone> |
13 | |
14 | #include <cstring> |
15 | |
16 | const char *KTimeZone::fromLocation(float latitude, float longitude) |
17 | { |
18 | const auto entry = SpatialIndex::lookup(lat: latitude, lon: longitude); |
19 | return timezone_name_table + entry.m_tz; |
20 | } |
21 | |
22 | KCountry KTimeZone::country(const char *ianaId) |
23 | { |
24 | // Asia/Bangkok is special as it's the only "regular" IANA tz that covers more than one country |
25 | // (northern Vietnam and Thailand in this case), QTimeZone however reports it as Thailand. |
26 | if (!ianaId || std::strcmp(s1: ianaId, s2: "") == 0 || std::strcmp(s1: ianaId, s2: "Asia/Bangkok") == 0) { |
27 | return {}; |
28 | } |
29 | |
30 | return KCountry::fromQLocale(country: QTimeZone(ianaId).territory()); |
31 | } |
32 |