From 42f2d187f807f515ca57a4ee1bff739a1eb59862 Mon Sep 17 00:00:00 2001 From: John Ralls Date: Thu, 23 Jul 2015 17:31:49 -0700 Subject: [PATCH] Windows: Get default timezone if there's no default key. Windows XP doesn't provide a default key, just the TZI returned by GetDefaultTimeZone(), so use that instead of throwing if there's no default key in the registry. If GetDefaultTimeZone() files, throw: We can't safely read the database without a timezone. --- src/libqof/qof/gnc-timezone.cpp | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/src/libqof/qof/gnc-timezone.cpp b/src/libqof/qof/gnc-timezone.cpp index a6804eb..850dd5a 100644 --- a/src/libqof/qof/gnc-timezone.cpp +++ b/src/libqof/qof/gnc-timezone.cpp @@ -226,6 +226,19 @@ TimeZoneProvider::load_windows_classic_tz (HKEY key, time_zone_names names) RegCloseKey (key); } +void +TimeZoneProvider::load_windows_default_tz() +{ + TIME_ZONE_INFORMATION tzi {}; + if (GetTimeZoneInformation (&tzi) == TIME_ZONE_INVALID) + throw std::system_error("No default time zone."); + RegTZI regtzi { tzi.Bias, tzi.StandardBias, tzi.DaylightBias, + tzi.StandardDate, tzi.DaylightDate }; + time_zone_names names (tiz.StandardName, tzi.StandardName, + tzi.DaylightName, tzi.DaylightName); + zone_vector.push_back(std::make_pair(0, zone_from_regtzi(regtzi, names))); +} + TimeZoneProvider::TimeZoneProvider (const std::string& identifier) : zone_vector () { @@ -237,8 +250,10 @@ TimeZoneProvider::TimeZoneProvider (const std::string& identifier) : identifier); if (key_name.empty()) - throw std::invalid_argument ("No identifier or default tzname."); - + { + load_windows_default_tz(); + return; + } std::string subkey = reg_key + key_name; if (RegOpenKeyExA (HKEY_LOCAL_MACHINE, subkey.c_str(), 0, KEY_QUERY_VALUE, &key) != ERROR_SUCCESS) -- 2.3.2 (Apple Git-55)