forked from HowardHinnant/date
Polish formatting, parsing and utc_time.
This commit is contained in:
45
tz.h
45
tz.h
@@ -1056,6 +1056,8 @@ public:
|
|||||||
template <class Duration>
|
template <class Duration>
|
||||||
using utc_time = std::chrono::time_point<utc_clock, Duration>;
|
using utc_time = std::chrono::time_point<utc_clock, Duration>;
|
||||||
|
|
||||||
|
using utc_seconds = utc_time<std::chrono::seconds>;
|
||||||
|
|
||||||
inline
|
inline
|
||||||
utc_clock::time_point
|
utc_clock::time_point
|
||||||
utc_clock::now() NOEXCEPT
|
utc_clock::now() NOEXCEPT
|
||||||
@@ -1090,12 +1092,9 @@ utc_clock::utc_to_sys(utc_time<Duration> t)
|
|||||||
return tp;
|
return tp;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <class Duration>
|
|
||||||
using utc_time = std::chrono::time_point<utc_clock, Duration>;
|
|
||||||
|
|
||||||
template <class Duration>
|
template <class Duration>
|
||||||
inline
|
inline
|
||||||
sys_time<Duration>
|
sys_time<typename std::common_type<Duration, std::chrono::seconds>::type>
|
||||||
to_sys_time(utc_time<Duration> ut)
|
to_sys_time(utc_time<Duration> ut)
|
||||||
{
|
{
|
||||||
return utc_clock::utc_to_sys(ut);
|
return utc_clock::utc_to_sys(ut);
|
||||||
@@ -1103,7 +1102,7 @@ to_sys_time(utc_time<Duration> ut)
|
|||||||
|
|
||||||
template <class Duration>
|
template <class Duration>
|
||||||
inline
|
inline
|
||||||
utc_time<Duration>
|
utc_time<typename std::common_type<Duration, std::chrono::seconds>::type>
|
||||||
to_utc_time(sys_time<Duration> st)
|
to_utc_time(sys_time<Duration> st)
|
||||||
{
|
{
|
||||||
return utc_clock::sys_to_utc(st);
|
return utc_clock::sys_to_utc(st);
|
||||||
@@ -1289,7 +1288,7 @@ parse(std::istream& is, const std::string& format,
|
|||||||
double s;
|
double s;
|
||||||
is >> s;
|
is >> s;
|
||||||
if (!is.fail())
|
if (!is.fail())
|
||||||
subseconds = duration_cast<Duration>(duration<double>{s});
|
subseconds = round<Duration>(duration<double>{s});
|
||||||
else
|
else
|
||||||
err |= ios_base::failbit;
|
err |= ios_base::failbit;
|
||||||
}
|
}
|
||||||
@@ -1330,17 +1329,14 @@ parse(std::istream& is, const std::string& format,
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 'Z':
|
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);
|
is >> temp_abbrev;
|
||||||
++i;
|
if (is.fail())
|
||||||
b = i+1;
|
err |= ios_base::failbit;
|
||||||
if ((err & ios_base::failbit) == 0)
|
|
||||||
{
|
|
||||||
is >> temp_abbrev;
|
|
||||||
if (is.fail())
|
|
||||||
err |= ios_base::failbit;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -1357,10 +1353,11 @@ parse(std::istream& is, const std::string& format,
|
|||||||
#else
|
#else
|
||||||
auto tt = _mkgmtime(&tm);
|
auto tt = _mkgmtime(&tm);
|
||||||
#endif
|
#endif
|
||||||
tp = floor<Duration>(system_clock::from_time_t(tt) +
|
tp = floor<Duration>(system_clock::from_time_t(tt) + subseconds);
|
||||||
subseconds - offset);
|
|
||||||
if (abbrev != nullptr)
|
if (abbrev != nullptr)
|
||||||
*abbrev = std::move(temp_abbrev);
|
*abbrev = std::move(temp_abbrev);
|
||||||
|
else
|
||||||
|
tp -= offset;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
is.setstate(err);
|
is.setstate(err);
|
||||||
@@ -1389,6 +1386,18 @@ parse(std::istream& is, const std::string& format, local_time<Duration>& tp,
|
|||||||
tp = local_time<Duration>{st.time_since_epoch()};
|
tp = local_time<Duration>{st.time_since_epoch()};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template <class Duration>
|
||||||
|
inline
|
||||||
|
void
|
||||||
|
parse(std::istream& is, const std::string& format, local_time<Duration>& tp)
|
||||||
|
{
|
||||||
|
sys_time<Duration> st;
|
||||||
|
std::string abbrev;
|
||||||
|
detail::parse(is, format, st, &abbrev);
|
||||||
|
if (!is.fail())
|
||||||
|
tp = local_time<Duration>{st.time_since_epoch()};
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace date
|
} // namespace date
|
||||||
|
|
||||||
#endif // TZ_H
|
#endif // TZ_H
|
||||||
|
Reference in New Issue
Block a user