From ab69e7c83a35e729a356139ca34210847765c26d Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Thu, 6 Aug 2020 01:52:50 +0200 Subject: [PATCH] [libcalamares] Add API for geographical lookup - find a zone given lat, lon -- with a failing test and a bogus implementation. --- src/libcalamares/locale/Tests.cpp | 10 ++++++++++ src/libcalamares/locale/TimeZone.cpp | 6 ++++++ src/libcalamares/locale/TimeZone.h | 6 ++++++ 3 files changed, 22 insertions(+) diff --git a/src/libcalamares/locale/Tests.cpp b/src/libcalamares/locale/Tests.cpp index dde199a7f..081d0ced5 100644 --- a/src/libcalamares/locale/Tests.cpp +++ b/src/libcalamares/locale/Tests.cpp @@ -52,6 +52,7 @@ private Q_SLOTS: void testComplexZones(); void testTZLookup(); void testTZIterator(); + void testLocationLookup(); }; LocaleTests::LocaleTests() {} @@ -389,6 +390,15 @@ LocaleTests::testTZIterator() QCOMPARE( ( *zones.begin() )->zone(), QStringLiteral( "Abidjan" ) ); } +void +LocaleTests::testLocationLookup() +{ + const CalamaresUtils::Locale::ZonesModel zones; + + QVERIFY( zones.find( 50.0, 0.0 ) ); + QCOMPARE( zones.find( 50.0, 0.0 )->zone(), QStringLiteral( "London" ) ); +} + QTEST_GUILESS_MAIN( LocaleTests ) diff --git a/src/libcalamares/locale/TimeZone.cpp b/src/libcalamares/locale/TimeZone.cpp index 974b73bfb..eaf7698ea 100644 --- a/src/libcalamares/locale/TimeZone.cpp +++ b/src/libcalamares/locale/TimeZone.cpp @@ -316,6 +316,12 @@ ZonesModel::find( const QString& region, const QString& zone ) const return nullptr; } +const TimeZoneData* +ZonesModel::find( double latitude, double longitude ) const +{ + return nullptr; +} + ZonesModel::Iterator::operator bool() const { return 0 <= m_index && m_index < m_p->m_zones.count(); diff --git a/src/libcalamares/locale/TimeZone.h b/src/libcalamares/locale/TimeZone.h index 9b8569b21..55fdda60a 100644 --- a/src/libcalamares/locale/TimeZone.h +++ b/src/libcalamares/locale/TimeZone.h @@ -128,6 +128,12 @@ public: */ const TimeZoneData* find( const QString& region, const QString& zone ) const; + /** @brief Look up TZ data based on the location. + * + * Returns the nearest zone to the given lat and lon. + */ + const TimeZoneData* find( double latitude, double longitude ) const; + /** @brief Iterator for testing purposes * * This is primarily for testing, but who knows, it might be useful