diff --git a/src/libqof/qof/gnc-timezone.cpp b/src/libqof/qof/gnc-timezone.cpp index 9ca8c3a4f9..b419604813 100644 --- a/src/libqof/qof/gnc-timezone.cpp +++ b/src/libqof/qof/gnc-timezone.cpp @@ -28,7 +28,8 @@ #include #include #if PLATFORM(WINDOWS) -#include +//We'd prefer to use std::codecvt, but it's not supported by gcc until 5.0. +#include #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 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,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(tzi.StandardName, + tzi.StandardName + sizeof(tzi.StandardName)); + auto dlt_name = utf_to_utf(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 9988b87cdf..efbfc650f8 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 };