mirror of
				https://github.com/ciphervance/supercell-wx.git
				synced 2025-10-31 10:20:04 +00:00 
			
		
		
		
	Load time zone into radar site
This commit is contained in:
		
							parent
							
								
									547c68f1a3
								
							
						
					
					
						commit
						f719fcbc06
					
				
					 3 changed files with 51 additions and 18 deletions
				
			
		|  | @ -4,11 +4,16 @@ | |||
| #include <scwx/common/sites.hpp> | ||||
| #include <scwx/util/logger.hpp> | ||||
| 
 | ||||
| #include <chrono> | ||||
| #include <shared_mutex> | ||||
| #include <unordered_map> | ||||
| 
 | ||||
| #include <boost/json.hpp> | ||||
| 
 | ||||
| #if !defined(_MSC_VER) | ||||
| #   include <date/date.h> | ||||
| #endif | ||||
| 
 | ||||
| namespace scwx | ||||
| { | ||||
| namespace qt | ||||
|  | @ -35,26 +40,19 @@ static bool ValidateJsonEntry(const boost::json::object& o); | |||
| class RadarSiteImpl | ||||
| { | ||||
| public: | ||||
|    explicit RadarSiteImpl() : | ||||
|        type_ {}, | ||||
|        id_ {}, | ||||
|        latitude_ {0.0}, | ||||
|        longitude_ {0.0}, | ||||
|        country_ {}, | ||||
|        state_ {}, | ||||
|        place_ {} | ||||
|    { | ||||
|    } | ||||
| 
 | ||||
|    explicit RadarSiteImpl() {} | ||||
|    ~RadarSiteImpl() {} | ||||
| 
 | ||||
|    std::string type_; | ||||
|    std::string id_; | ||||
|    double      latitude_; | ||||
|    double      longitude_; | ||||
|    std::string country_; | ||||
|    std::string state_; | ||||
|    std::string place_; | ||||
|    std::string type_ {}; | ||||
|    std::string id_ {}; | ||||
|    double      latitude_ {0.0}; | ||||
|    double      longitude_ {0.0}; | ||||
|    std::string country_ {}; | ||||
|    std::string state_ {}; | ||||
|    std::string place_ {}; | ||||
|    std::string tzName_ {}; | ||||
| 
 | ||||
|    const scwx::util::time_zone* timeZone_ {nullptr}; | ||||
| }; | ||||
| 
 | ||||
| RadarSite::RadarSite() : p(std::make_unique<RadarSiteImpl>()) {} | ||||
|  | @ -134,6 +132,16 @@ std::string RadarSite::location_name() const | |||
|    return locationName; | ||||
| } | ||||
| 
 | ||||
| std::string RadarSite::tz_name() const | ||||
| { | ||||
|    return p->tzName_; | ||||
| } | ||||
| 
 | ||||
| const scwx::util::time_zone* RadarSite::time_zone() const | ||||
| { | ||||
|    return p->timeZone_; | ||||
| } | ||||
| 
 | ||||
| std::shared_ptr<RadarSite> RadarSite::Get(const std::string& id) | ||||
| { | ||||
|    std::shared_lock           lock(siteMutex_); | ||||
|  | @ -259,6 +267,23 @@ size_t RadarSite::ReadConfig(const std::string& path) | |||
|                boost::json::value_to<std::string>(o.at("country")); | ||||
|             site->p->state_ = boost::json::value_to<std::string>(o.at("state")); | ||||
|             site->p->place_ = boost::json::value_to<std::string>(o.at("place")); | ||||
|             site->p->tzName_ = boost::json::value_to<std::string>(o.at("tz")); | ||||
| 
 | ||||
|             try | ||||
|             { | ||||
| #if defined(_MSC_VER) | ||||
|                using namespace std::chrono; | ||||
| #else | ||||
|                using namespace date; | ||||
| #endif | ||||
| 
 | ||||
|                site->p->timeZone_ = get_tzdb().locate_zone(site->p->tzName_); | ||||
|             } | ||||
|             catch (const std::runtime_error&) | ||||
|             { | ||||
|                logger_->warn( | ||||
|                   "{} unknown time zone: {}", site->p->id_, site->p->tzName_); | ||||
|             } | ||||
| 
 | ||||
|             if (!radarSiteMap_.contains(site->p->id_)) | ||||
|             { | ||||
|  |  | |||
|  | @ -1,5 +1,7 @@ | |||
| #pragma once | ||||
| 
 | ||||
| #include <scwx/util/time.hpp> | ||||
| 
 | ||||
| #include <memory> | ||||
| #include <optional> | ||||
| #include <string> | ||||
|  | @ -35,6 +37,9 @@ public: | |||
|    std::string state() const; | ||||
|    std::string place() const; | ||||
|    std::string location_name() const; | ||||
|    std::string tz_name() const; | ||||
| 
 | ||||
|    const scwx::util::time_zone* time_zone() const; | ||||
| 
 | ||||
|    static std::shared_ptr<RadarSite>              Get(const std::string& id); | ||||
|    static std::vector<std::shared_ptr<RadarSite>> GetAll(); | ||||
|  |  | |||
|  | @ -38,6 +38,9 @@ TEST_F(RadarSiteTest, DefaultConfig) | |||
|    EXPECT_EQ(radarSite->country(), "USA"); | ||||
|    EXPECT_EQ(radarSite->state(), "MO"); | ||||
|    EXPECT_EQ(radarSite->place(), "St. Louis"); | ||||
|    EXPECT_EQ(radarSite->tz_name(), "America/Chicago"); | ||||
|    ASSERT_NE(radarSite->time_zone(), nullptr); | ||||
|    EXPECT_EQ(radarSite->time_zone()->name(), "America/Chicago"); | ||||
|    EXPECT_DOUBLE_EQ(radarSite->latitude(), 38.6986863); | ||||
|    EXPECT_DOUBLE_EQ(radarSite->longitude(), -90.682877); | ||||
| } | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Dan Paulat
						Dan Paulat