minor fixes in format and parse

This commit is contained in:
Howard Hinnant
2016-05-09 10:45:35 -04:00
parent f5f0f80778
commit 8fc76f618e

11
tz.h
View File

@@ -1151,7 +1151,7 @@ format(const std::locale& loc, std::string format,
throw std::runtime_error("Can not format local_time with %z"); throw std::runtime_error("Can not format local_time with %z");
else else
{ {
auto info = zone->get_info(tp); auto info = zone->get_info(tp).first;
auto offset = duration_cast<minutes>(info.offset); auto offset = duration_cast<minutes>(info.offset);
ostringstream os; ostringstream os;
if (offset >= minutes{0}) if (offset >= minutes{0})
@@ -1168,7 +1168,7 @@ format(const std::locale& loc, std::string format,
throw std::runtime_error("Can not format local_time with %z"); throw std::runtime_error("Can not format local_time with %z");
else else
{ {
auto info = zone->get_info(tp); auto info = zone->get_info(tp).first;
format.replace(i, 2, info.abbrev); format.replace(i, 2, info.abbrev);
i += info.abbrev.size() - 1; i += info.abbrev.size() - 1;
} }
@@ -1380,10 +1380,13 @@ parse(std::istream& is, const std::string& format, sys_time<Duration>& tp)
template <class Duration> template <class Duration>
inline inline
void void
parse(std::istream& is, const std::string& format, sys_time<Duration>& tp, parse(std::istream& is, const std::string& format, local_time<Duration>& tp,
std::string& abbrev) std::string& abbrev)
{ {
detail::parse(is, format, tp, &abbrev); sys_time<Duration> st;
detail::parse(is, format, st, &abbrev);
if (!is.fail())
tp = local_time<Duration>{st.time_since_epoch()};
} }
} // namespace date } // namespace date