forked from HowardHinnant/date
TZ stuff fixed for VS2013
This commit is contained in:
@@ -273,12 +273,14 @@ static void get_windows_timezone_info(std::vector<timezone_info>& tz_list)
|
||||
|
||||
// Open the parent time zone key that has the list of timezones in.
|
||||
reg_key zones_key;
|
||||
static const wchar_t zones_key_name[] = { L"SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Time Zones" };
|
||||
static const wchar_t zones_key_name[] =
|
||||
{ L"SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Time Zones" };
|
||||
result = zones_key.open(zones_key_name);
|
||||
// TODO! Review if this should happen here or be signalled later.
|
||||
// We don't want the process to fail on startup because of this.
|
||||
if (result != ERROR_SUCCESS)
|
||||
throw std::runtime_error("Time Zone registry key could not be opened: " + get_win32_message(result));
|
||||
throw std::runtime_error("Time Zone registry key could not be opened: "
|
||||
+ get_win32_message(result));
|
||||
|
||||
DWORD size;
|
||||
wchar_t zone_key_name[256];
|
||||
@@ -295,7 +297,8 @@ static void get_windows_timezone_info(std::vector<timezone_info>& tz_list)
|
||||
auto status = RegEnumKeyExW(zones_key.handle(), zone_index, zone_key_name, &size,
|
||||
nullptr, nullptr, nullptr, nullptr);
|
||||
if (status != ERROR_SUCCESS && status != ERROR_NO_MORE_ITEMS)
|
||||
throw std::runtime_error("Can't enumerate time zone registry key" + get_win32_message(status));
|
||||
throw std::runtime_error("Can't enumerate time zone registry key"
|
||||
+ get_win32_message(status));
|
||||
if (status == ERROR_NO_MORE_ITEMS)
|
||||
break;
|
||||
zone_key_name[size] = L'\0';
|
||||
@@ -389,25 +392,32 @@ load_timezone_mappings_from_csv_file(const std::string& input_path)
|
||||
std::string copyright;
|
||||
for (int i = 0; i < 4; ++i)
|
||||
getline(is, copyright);
|
||||
|
||||
for (;;)
|
||||
{
|
||||
timezone_mapping zm{};
|
||||
is >> std::quoted(zm.other);
|
||||
char ch;
|
||||
|
||||
is.read(&ch, 1);
|
||||
if (is.eof())
|
||||
break;
|
||||
|
||||
std::getline(is, zm.other, '\"');
|
||||
read_field_delim();
|
||||
is >> std::quoted(zm.territory);
|
||||
read_field_delim();
|
||||
is >> std::quoted(zm.type);
|
||||
|
||||
char record_delim;
|
||||
is.read(&record_delim, 1);
|
||||
if (is.gcount() != 1 || record_delim != '\n')
|
||||
is.read(&ch, 1);
|
||||
std::getline(is, zm.territory, '\"');
|
||||
read_field_delim();
|
||||
|
||||
is.read(&ch, 1);
|
||||
std::getline(is, zm.type, '\"');
|
||||
|
||||
is.read(&ch, 1);
|
||||
if (is.gcount() != 1 || ch != '\n')
|
||||
error("record delimiter LF expected");
|
||||
|
||||
if (is.fail() || is.eof())
|
||||
error("unexpected end of file, file read error or formatting error.");
|
||||
|
||||
++line;
|
||||
mappings.push_back(std::move(zm));
|
||||
}
|
||||
@@ -416,7 +426,8 @@ load_timezone_mappings_from_csv_file(const std::string& input_path)
|
||||
}
|
||||
|
||||
static bool
|
||||
native_to_standard_timezone_name(const std::string& native_tz_name, std::string& standard_tz_name)
|
||||
native_to_standard_timezone_name(const std::string& native_tz_name,
|
||||
std::string& standard_tz_name)
|
||||
{
|
||||
// TOOD! Need be a case insensitive compare?
|
||||
if (native_tz_name == "UTC")
|
||||
@@ -757,7 +768,11 @@ operator>>(std::istream& is, MonthDayTime& x)
|
||||
throw std::runtime_error(std::string("bad operator: ") + c + c2
|
||||
+ std::to_string(d));
|
||||
x.type_ = c == '<' ? MonthDayTime::lteq : MonthDayTime::gteq;
|
||||
x.u = {date::month(m)/d, weekday(dow)};
|
||||
#if !defined(_MSC_VER) || (_MSC_VER >= 1900)
|
||||
x.u = {date::month(m)/d, date::weekday(dow)};
|
||||
#else
|
||||
x.u = MonthDayTime::U(date::month(m)/d, date::weekday(dow));
|
||||
#endif
|
||||
}
|
||||
else
|
||||
throw std::runtime_error(std::string("bad operator: ") + c);
|
||||
@@ -1005,7 +1020,7 @@ operator<<(std::ostream& os, const Rule& r)
|
||||
{
|
||||
using namespace date;
|
||||
using namespace std::chrono;
|
||||
save_stream _(os);
|
||||
detail::save_stream _(os);
|
||||
os.fill(' ');
|
||||
os.flags(std::ios::dec | std::ios::left);
|
||||
os.width(15);
|
||||
@@ -1194,17 +1209,21 @@ Rule::split_overlaps(std::vector<Rule>& rules)
|
||||
|
||||
Zone::zonelet::~zonelet()
|
||||
{
|
||||
#if !defined(_MSC_VER) || (_MSC_VER >= 1900)
|
||||
using minutes = std::chrono::minutes;
|
||||
using string = std::string;
|
||||
if (tag_ == has_save)
|
||||
u.save_.~minutes();
|
||||
else
|
||||
u.rule_.~string();
|
||||
#endif
|
||||
}
|
||||
|
||||
Zone::zonelet::zonelet()
|
||||
{
|
||||
#if !defined(_MSC_VER) || (_MSC_VER >= 1900)
|
||||
::new(&u.rule_) std::string();
|
||||
#endif
|
||||
}
|
||||
|
||||
Zone::zonelet::zonelet(const zonelet& i)
|
||||
@@ -1221,10 +1240,17 @@ Zone::zonelet::zonelet(const zonelet& i)
|
||||
, first_rule_(i.first_rule_)
|
||||
, last_rule_(i.last_rule_)
|
||||
{
|
||||
#if !defined(_MSC_VER) || (_MSC_VER >= 1900)
|
||||
if (tag_ == has_save)
|
||||
::new(&u.save_) std::chrono::minutes(i.u.save_);
|
||||
else
|
||||
::new(&u.rule_) std::string(i.u.rule_);
|
||||
#else
|
||||
if (tag_ == has_save)
|
||||
u.save_ = i.u.save_;
|
||||
else
|
||||
u.rule_ = i.u.rule_;
|
||||
#endif
|
||||
}
|
||||
|
||||
Zone::Zone(const std::string& s)
|
||||
@@ -1344,7 +1370,8 @@ find_previous_rule(const Rule* r, date::year y)
|
||||
// [first, last) all have the same name
|
||||
static
|
||||
std::pair<const Rule*, date::year>
|
||||
find_next_rule(const Rule* first_rule, const Rule* last_rule, const Rule* r, date::year y)
|
||||
find_next_rule(const Rule* first_rule, const Rule* last_rule, const Rule* r,
|
||||
date::year y)
|
||||
{
|
||||
using namespace date;
|
||||
if (y == r->ending_year())
|
||||
@@ -1564,9 +1591,15 @@ Zone::adjust_infos(const std::vector<Rule>& rules)
|
||||
std::istringstream in(z.u.rule_);
|
||||
in.exceptions(std::ios::failbit | std::ios::badbit);
|
||||
auto tmp = duration_cast<minutes>(parse_signed_time(in));
|
||||
#if !defined(_MSC_VER) || (_MSC_VER >= 1900)
|
||||
z.u.rule_.~string();
|
||||
z.tag_ = zonelet::has_save;
|
||||
::new(&z.u.save_) minutes(tmp);
|
||||
#else
|
||||
z.u.rule_.clear();
|
||||
z.tag_ = zonelet::has_save;
|
||||
z.u.save_ = tmp;
|
||||
#endif
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
@@ -1773,7 +1806,7 @@ operator<<(std::ostream& os, const Zone& z)
|
||||
{
|
||||
using namespace date;
|
||||
using namespace std::chrono;
|
||||
save_stream _(os);
|
||||
detail::save_stream _(os);
|
||||
os.fill(' ');
|
||||
os.flags(std::ios::dec | std::ios::left);
|
||||
os.width(35);
|
||||
@@ -1832,7 +1865,7 @@ std::ostream&
|
||||
operator<<(std::ostream& os, const Link& x)
|
||||
{
|
||||
using namespace date;
|
||||
save_stream _(os);
|
||||
detail::save_stream _(os);
|
||||
os.fill(' ');
|
||||
os.flags(std::ios::dec | std::ios::left);
|
||||
os.width(35);
|
||||
@@ -2099,7 +2132,8 @@ current_zone()
|
||||
if (tz_result == TIME_ZONE_ID_INVALID)
|
||||
{
|
||||
auto error_code = ::GetLastError(); // Store this quick before it gets overwritten.
|
||||
throw std::runtime_error("GetTimeZoneInformation failed: " + get_win32_message(error_code));
|
||||
throw std::runtime_error("GetTimeZoneInformation failed: "
|
||||
+ get_win32_message(error_code));
|
||||
}
|
||||
std::wstring_convert<std::codecvt_utf8_utf16<wchar_t>> converter;
|
||||
std::string standard_name(converter.to_bytes(tzi.StandardName));
|
||||
|
||||
Reference in New Issue
Block a user