gnucash master: Multiple changes pushed
John Ralls
jralls at code.gnucash.org
Sat Jul 25 14:23:35 EDT 2015
Updated via https://github.com/Gnucash/gnucash/commit/b78f1029 (commit)
via https://github.com/Gnucash/gnucash/commit/5cc99806 (commit)
from https://github.com/Gnucash/gnucash/commit/54c9e836 (commit)
commit b78f10292919958830057907ebcdadfe6df8adfc
Author: John Ralls <jralls at ceridwen.us>
Date: Sat Jul 25 11:23:06 2015 -0700
Fix timezone exceptions on Windows XP.
diff --git a/src/libqof/qof/gnc-timezone.cpp b/src/libqof/qof/gnc-timezone.cpp
index 9ca8c3a..b419604 100644
--- a/src/libqof/qof/gnc-timezone.cpp
+++ b/src/libqof/qof/gnc-timezone.cpp
@@ -28,7 +28,8 @@
#include <algorithm>
#include <boost/date_time/gregorian/gregorian.hpp>
#if PLATFORM(WINDOWS)
-#include <codecvt>
+//We'd prefer to use std::codecvt, but it's not supported by gcc until 5.0.
+#include <boost/locale/encoding_utf.hpp>
#endif
using namespace gnc::date;
@@ -38,6 +39,9 @@ using time_zone = boost::local_time::custom_time_zone;
using dst_offsets = boost::local_time::dst_adjustment_offsets;
using calc_rule_ptr = boost::local_time::dst_calc_rule_ptr;
+const unsigned int TimeZoneProvider::min_year = 1400;
+const unsigned int TimeZoneProvider::max_year = 9999;
+
template<typename T>
T*
endian_swap(T* t)
@@ -193,7 +197,7 @@ TimeZoneProvider::load_windows_dynamic_tz (HKEY key, time_zone_names names)
zone_vector.push_back (std::make_pair(0, tz));
zone_vector.push_back (std::make_pair(year, tz));
}
- zone_vector.push_back (std::make_pair(9999, tz));
+ zone_vector.push_back (std::make_pair(max_year, tz));
}
catch (std::invalid_argument)
{
@@ -234,15 +238,16 @@ void
TimeZoneProvider::load_windows_default_tz()
{
TIME_ZONE_INFORMATION tzi {};
- if (GetTimeZoneInformation (&tzi) == TIME_ZONE_INVALID)
- throw std::system_error("No default time zone.");
+ GetTimeZoneInformation (&tzi);
RegTZI regtzi { tzi.Bias, tzi.StandardBias, tzi.DaylightBias,
tzi.StandardDate, tzi.DaylightDate };
- std::wstring_convert<std::codecvt_utf8_utf16<char16_t>,char16_t> conversion;
- auto std_name = conversion.to_bytes(tzi.StandardName);
- auto dlt_name = conversion.to_bytes(tzi.DaylightName);
+ using boost::locale::conv::utf_to_utf;
+ auto std_name = utf_to_utf<char>(tzi.StandardName,
+ tzi.StandardName + sizeof(tzi.StandardName));
+ auto dlt_name = utf_to_utf<char>(tzi.DaylightName,
+ tzi.DaylightName + sizeof(tzi.DaylightName));
time_zone_names names (std_name, std_name, dlt_name, dlt_name);
- zone_vector.push_back(std::make_pair(0, zone_from_regtzi(regtzi, names)));
+ zone_vector.push_back(std::make_pair(max_year, zone_from_regtzi(regtzi, names)));
}
TimeZoneProvider::TimeZoneProvider (const std::string& identifier) :
@@ -635,9 +640,9 @@ TimeZoneProvider::TimeZoneProvider(const std::string& tzname) : zone_vector {}
if (last_time.is_not_a_date_time() ||
last_time.date().year() < parser.last_year)
- zone_vector.push_back(zone_no_dst(9999, last_info));
+ zone_vector.push_back(zone_no_dst(max_year, last_info));
else //Last DST rule forever after.
- zone_vector.push_back(zone_from_rule(9999, last_rule));
+ zone_vector.push_back(zone_from_rule(max_year, last_rule));
}
#endif
diff --git a/src/libqof/qof/gnc-timezone.hpp b/src/libqof/qof/gnc-timezone.hpp
index 9988b87..efbfc65 100644
--- a/src/libqof/qof/gnc-timezone.hpp
+++ b/src/libqof/qof/gnc-timezone.hpp
@@ -55,11 +55,14 @@ public:
TimeZoneProvider operator=(const TimeZoneProvider&) = delete;
TimeZoneProvider operator=(const TimeZoneProvider&&) = delete;
TZ_Ptr get (int year) const noexcept;
+ static const unsigned int min_year; //1400
+ static const unsigned int max_year; //9999
private:
TZ_Vector zone_vector;
#if PLATFORM(WINDOWS)
void load_windows_dynamic_tz(HKEY, time_zone_names);
void load_windows_classic_tz(HKEY, time_zone_names);
+ void load_windows_default_tz(void);
#endif
};
commit 5cc99806d8886f948c05e097e215d7f923a1f621
Author: John Ralls <jralls at ceridwen.us>
Date: Thu Jul 23 17:31:49 2015 -0700
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.
diff --git a/src/libqof/qof/gnc-timezone.cpp b/src/libqof/qof/gnc-timezone.cpp
index a6804eb..9ca8c3a 100644
--- a/src/libqof/qof/gnc-timezone.cpp
+++ b/src/libqof/qof/gnc-timezone.cpp
@@ -27,6 +27,10 @@
#include <istream>
#include <algorithm>
#include <boost/date_time/gregorian/gregorian.hpp>
+#if PLATFORM(WINDOWS)
+#include <codecvt>
+#endif
+
using namespace gnc::date;
using duration = boost::posix_time::time_duration;
@@ -226,6 +230,21 @@ 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 };
+ std::wstring_convert<std::codecvt_utf8_utf16<char16_t>,char16_t> conversion;
+ auto std_name = conversion.to_bytes(tzi.StandardName);
+ auto dlt_name = conversion.to_bytes(tzi.DaylightName);
+ time_zone_names names (std_name, std_name, dlt_name, dlt_name);
+ zone_vector.push_back(std::make_pair(0, zone_from_regtzi(regtzi, names)));
+}
+
TimeZoneProvider::TimeZoneProvider (const std::string& identifier) :
zone_vector ()
{
@@ -237,8 +256,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)
Summary of changes:
src/libqof/qof/gnc-timezone.cpp | 36 +++++++++++++++++++++++++++++++-----
src/libqof/qof/gnc-timezone.hpp | 3 +++
2 files changed, 34 insertions(+), 5 deletions(-)
More information about the gnucash-changes
mailing list