KI18n

ktimezone.cpp
1 /*
2  SPDX-FileCopyrightText: 2021 Volker Krause <[email protected]>
3 
4  SPDX-License-Identifier: LGPL-2.0-or-later
5 */
6 
7 #include "ktimezone.h"
8 #include "data/timezone_country_map.cpp"
9 #include "data/timezone_name_table.cpp"
10 #include "kcountry.h"
11 #include "spatial_index_p.h"
12 
13 #include <cstring>
14 
15 const char *KTimeZone::fromLocation(float latitude, float longitude)
16 {
17  const auto entry = SpatialIndex::lookup(latitude, longitude);
18  return timezone_name_table + entry.m_tz;
19 }
20 
21 KCountry KTimeZone::country(const char *ianaId)
22 {
23  if (!ianaId) {
24  return {};
25  }
26 
27  const auto it = std::lower_bound(std::begin(timezone_country_map), std::end(timezone_country_map), ianaId, [](auto lhs, auto rhs) {
28  return std::strcmp(timezone_name_table + lhs.key, rhs) < 0;
29  });
30  if (it != std::end(timezone_country_map) && std::strcmp(timezone_name_table + (*it).key, ianaId) == 0) {
31  KCountry c;
32  c.d = (*it).value;
33  return c;
34  }
35  return {};
36 }
KI18NLOCALEDATA_EXPORT KCountry country(const char *)
Returns the country a timezone is in.
float latitude() const
float longitude() const
const KI18NLOCALEDATA_EXPORT char * fromLocation(float latitude, float longitude)
Returns the timezone at the given geo coordinate.
This file is part of the KDE documentation.
Documentation copyright © 1996-2022 The KDE developers.
Generated on Mon Aug 15 2022 04:07:44 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.