KI18n

ktimezone.cpp
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
16const char *KTimeZone::fromLocation(float latitude, float longitude)
17{
18 const auto entry = SpatialIndex::lookup(latitude, longitude);
19 return timezone_name_table + entry.m_tz;
20}
21
22KCountry 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(ianaId, "") == 0 || std::strcmp(ianaId, "Asia/Bangkok") == 0) {
27 return {};
28 }
29
30 return KCountry::fromQLocale(QTimeZone(ianaId).territory());
31}
Information about an ISO 3166-1 country.
Definition kcountry.h:40
static KCountry fromQLocale(QLocale::Country country)
Returns a KCountry instance matching the given QLocale::Country code.
Definition kcountry.cpp:270
KI18NLOCALEDATA_EXPORT const char * fromLocation(float latitude, float longitude)
Returns the timezone at the given geo coordinate.
Definition ktimezone.cpp:16
KI18NLOCALEDATA_EXPORT KCountry country(const char *)
Returns the country a timezone is in.
Definition ktimezone.cpp:22
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Tue Mar 26 2024 11:21:06 by doxygen 1.10.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.