diff --git a/tz.h b/tz.h index 1c10b7b..406d622 100644 --- a/tz.h +++ b/tz.h @@ -1056,6 +1056,8 @@ public: template using utc_time = std::chrono::time_point; +using utc_seconds = utc_time; + inline utc_clock::time_point utc_clock::now() NOEXCEPT @@ -1090,12 +1092,9 @@ utc_clock::utc_to_sys(utc_time t) return tp; } -template - using utc_time = std::chrono::time_point; - template inline -sys_time +sys_time::type> to_sys_time(utc_time ut) { return utc_clock::utc_to_sys(ut); @@ -1103,7 +1102,7 @@ to_sys_time(utc_time ut) template inline -utc_time +utc_time::type> to_utc_time(sys_time st) { return utc_clock::sys_to_utc(st); @@ -1289,7 +1288,7 @@ parse(std::istream& is, const std::string& format, double s; is >> s; if (!is.fail()) - subseconds = duration_cast(duration{s}); + subseconds = round(duration{s}); else err |= ios_base::failbit; } @@ -1330,17 +1329,14 @@ parse(std::istream& is, const std::string& format, } break; case 'Z': - if (abbrev != nullptr) + f.get(is, 0, is, err, &tm, b, i); + ++i; + b = i+1; + if ((err & ios_base::failbit) == 0) { - f.get(is, 0, is, err, &tm, b, i); - ++i; - b = i+1; - if ((err & ios_base::failbit) == 0) - { - is >> temp_abbrev; - if (is.fail()) - err |= ios_base::failbit; - } + is >> temp_abbrev; + if (is.fail()) + err |= ios_base::failbit; } break; } @@ -1357,10 +1353,11 @@ parse(std::istream& is, const std::string& format, #else auto tt = _mkgmtime(&tm); #endif - tp = floor(system_clock::from_time_t(tt) + - subseconds - offset); + tp = floor(system_clock::from_time_t(tt) + subseconds); if (abbrev != nullptr) *abbrev = std::move(temp_abbrev); + else + tp -= offset; } } is.setstate(err); @@ -1389,6 +1386,18 @@ parse(std::istream& is, const std::string& format, local_time& tp, tp = local_time{st.time_since_epoch()}; } +template +inline +void +parse(std::istream& is, const std::string& format, local_time& tp) +{ + sys_time st; + std::string abbrev; + detail::parse(is, format, st, &abbrev); + if (!is.fail()) + tp = local_time{st.time_since_epoch()}; +} + } // namespace date #endif // TZ_H