Catch out-of-range exception at beginning and end of TZFile on Fedora.

This commit is contained in:
John Ralls 2015-05-04 15:53:23 -07:00
parent 0b55c746c8
commit 577aa3fe02

View File

@ -562,33 +562,40 @@ TimeZoneProvider::TimeZoneProvider(const std::string& tzname) : zone_vector {}
auto this_time = ptime(date(1970, 1, 1), auto this_time = ptime(date(1970, 1, 1),
time_duration(txi->timestamp / 3600, 0, time_duration(txi->timestamp / 3600, 0,
txi->timestamp % 3600)); txi->timestamp % 3600));
auto this_year = this_time.date().year(); try
//Initial case
if (last_time.is_not_a_date_time())
zone_vector.push_back(zone_no_dst(this_year - 1, last_info));
//gap in transitions > 1 year, non-dst zone
//change. In the last case the exact date of the change will be
//wrong because boost::local_date::timezone isn't able to
//represent it. For GnuCash's purposes this isn't likely to be
//important as the last time this sort of transition happened
//was 1946, but we have to handle the case in order to parse
//the tz file.
else if (this_year - last_time.date().year() > 1 ||
last_info->info.isdst == this_info->info.isdst)
{ {
zone_vector.push_back(zone_no_dst(this_year, last_info)); auto this_year = this_time.date().year();
} //Initial case
if (last_time.is_not_a_date_time())
else zone_vector.push_back(zone_no_dst(this_year - 1, last_info));
{ //gap in transitions > 1 year, non-dst zone
DSTRule::DSTRule new_rule(last_info, this_info, //change. In the last case the exact date of the change will be
last_time, this_time); //wrong because boost::local_date::timezone isn't able to
if (new_rule != last_rule) //represent it. For GnuCash's purposes this isn't likely to be
//important as the last time this sort of transition happened
//was 1946, but we have to handle the case in order to parse
//the tz file.
else if (this_year - last_time.date().year() > 1 ||
last_info->info.isdst == this_info->info.isdst)
{ {
last_rule = new_rule; zone_vector.push_back(zone_no_dst(this_year, last_info));
zone_vector.push_back(zone_from_rule (this_time.date().year(),
new_rule));
} }
else
{
DSTRule::DSTRule new_rule(last_info, this_info,
last_time, this_time);
if (new_rule != last_rule)
{
last_rule = new_rule;
zone_vector.push_back(zone_from_rule (this_time.date().year(),
new_rule));
}
}
}
catch(boost::gregorian::bad_year err)
{
continue;
} }
last_time = this_time; last_time = this_time;
last_info = this_info; last_info = this_info;