mirror of
https://github.com/Xahau/xahaud.git
synced 2025-12-06 17:27:52 +00:00
Remove unused chrono::time_point stream conversions
This commit is contained in:
committed by
Nik Bougalis
parent
8aa4a027bb
commit
5cde522d5e
@@ -32,8 +32,6 @@
|
||||
#include <beast/utility/noexcept.h>
|
||||
#include <ctime>
|
||||
#include <locale>
|
||||
|
||||
#define BEAST_CHRONO_NO_TIMEPOINT_IO 1
|
||||
|
||||
/*
|
||||
|
||||
@@ -798,292 +796,8 @@ time_fmt(timezone f)
|
||||
return __time_man(f);
|
||||
}
|
||||
|
||||
#if ! BEAST_CHRONO_NO_TIMEPOINT_IO
|
||||
} // chrono
|
||||
|
||||
template <class _CharT, class _Traits, class _Duration>
|
||||
basic_istream<_CharT, _Traits>&
|
||||
operator>>(basic_istream<_CharT, _Traits>& __is,
|
||||
time_point<steady_clock, _Duration>& __tp)
|
||||
{
|
||||
_Duration __d;
|
||||
__is >> __d;
|
||||
if (__is.good())
|
||||
{
|
||||
const _CharT __u[] = {' ', 's', 'i', 'n', 'c', 'e', ' ', 'b', 'o', 'o', 't'};
|
||||
const basic_string<_CharT> __units(__u, __u + sizeof(__u)/sizeof(__u[0]));
|
||||
ios_base::iostate __err = ios_base::goodbit;
|
||||
typedef istreambuf_iterator<_CharT, _Traits> _I;
|
||||
_I __i(__is);
|
||||
_I __e;
|
||||
ptrdiff_t __k = __scan_keyword(__i, __e,
|
||||
&__units, &__units + 1,
|
||||
use_facet<ctype<_CharT> >(__is.getloc()),
|
||||
__err) - &__units;
|
||||
if (__k == 1)
|
||||
{
|
||||
// failed to read epoch string
|
||||
__is.setstate(__err);
|
||||
return __is;
|
||||
}
|
||||
__tp = time_point<steady_clock, _Duration>(__d);
|
||||
}
|
||||
else
|
||||
__is.setstate(__is.failbit);
|
||||
return __is;
|
||||
}
|
||||
|
||||
template <class _CharT, class _Traits, class _Duration>
|
||||
basic_ostream<_CharT, _Traits>&
|
||||
operator<<(basic_ostream<_CharT, _Traits>& __os,
|
||||
const time_point<system_clock, _Duration>& __tp)
|
||||
{
|
||||
typename basic_ostream<_CharT, _Traits>::sentry ok(__os);
|
||||
if (ok)
|
||||
{
|
||||
bool failed = false;
|
||||
try
|
||||
{
|
||||
const _CharT* pb = nullptr;
|
||||
const _CharT* pe = pb;
|
||||
timezone tz = utc;
|
||||
typedef timepunct<_CharT> F;
|
||||
locale loc = __os.getloc();
|
||||
if (has_facet<F>(loc))
|
||||
{
|
||||
const F& f = use_facet<F>(loc);
|
||||
pb = f.fmt().data();
|
||||
pe = pb + f.fmt().size();
|
||||
tz = f.get_timezone();
|
||||
}
|
||||
time_t __t = system_clock::to_time_t(__tp);
|
||||
tm* __tm;
|
||||
if (tz == local)
|
||||
{
|
||||
if (! (__tm = localtime(&__t)))
|
||||
failed = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (! (__tm = gmtime(&__t)))
|
||||
failed = true;
|
||||
}
|
||||
if (!failed)
|
||||
{
|
||||
const time_put<_CharT>& tp = use_facet<time_put<_CharT> >(loc);
|
||||
if (pb == pe)
|
||||
{
|
||||
_CharT pattern[] = {'%', 'F', 'T', '%', 'H', ':', '%', 'M', ':'};
|
||||
pb = pattern;
|
||||
pe = pb + sizeof(pattern) / sizeof(_CharT);
|
||||
failed = tp.put(__os, __os, __os.fill(), __tm, pb, pe).failed();
|
||||
if (!failed)
|
||||
{
|
||||
duration<double> __d = __tp - system_clock::from_time_t(__t) +
|
||||
seconds(__tm->tm_sec);
|
||||
if (__d.count() < 10)
|
||||
__os << _CharT('0');
|
||||
ios::fmtflags __flgs = __os.flags();
|
||||
__os.setf(ios::fixed, ios::floatfield);
|
||||
__os << __d.count();
|
||||
__os.flags(__flgs);
|
||||
if (tz == local)
|
||||
{
|
||||
_CharT sub_pattern[] = {' ', '%', 'z'};
|
||||
pb = sub_pattern;
|
||||
pe = pb + + sizeof(sub_pattern) / sizeof(_CharT);
|
||||
failed = tp.put(__os, __os, __os.fill(), __tm, pb, pe).failed();
|
||||
}
|
||||
else
|
||||
{
|
||||
_CharT sub_pattern[] = {' ', '+', '0', '0', '0', '0', 0};
|
||||
__os << sub_pattern;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
failed = tp.put(__os, __os, __os.fill(), __tm, pb, pe).failed();
|
||||
}
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
failed = true;
|
||||
}
|
||||
if (failed)
|
||||
__os.setstate(ios_base::failbit | ios_base::badbit);
|
||||
}
|
||||
return __os;
|
||||
}
|
||||
|
||||
template <class _CharT, class _InputIterator>
|
||||
minutes
|
||||
__extract_z(_InputIterator& __b, _InputIterator __e,
|
||||
ios_base::iostate& __err, const ctype<_CharT>& __ct)
|
||||
{
|
||||
int __minn = 0;
|
||||
if (__b != __e)
|
||||
{
|
||||
char __cn = __ct.narrow(*__b, 0);
|
||||
if (__cn != '+' && __cn != '-')
|
||||
{
|
||||
__err |= ios_base::failbit;
|
||||
return minutes(0);
|
||||
}
|
||||
int __sn = __cn == '-' ? -1 : 1;
|
||||
int __hr = 0;
|
||||
for (int i = 0; i < 2; ++i)
|
||||
{
|
||||
if (++__b == __e)
|
||||
{
|
||||
__err |= ios_base::eofbit | ios_base::failbit;
|
||||
return minutes(0);
|
||||
}
|
||||
__cn = __ct.narrow(*__b, 0);
|
||||
if (!('0' <= __cn && __cn <= '9'))
|
||||
{
|
||||
__err |= ios_base::failbit;
|
||||
return minutes(0);
|
||||
}
|
||||
__hr = __hr * 10 + __cn - '0';
|
||||
}
|
||||
for (int i = 0; i < 2; ++i)
|
||||
{
|
||||
if (++__b == __e)
|
||||
{
|
||||
__err |= ios_base::eofbit | ios_base::failbit;
|
||||
return minutes(0);
|
||||
}
|
||||
__cn = __ct.narrow(*__b, 0);
|
||||
if (!('0' <= __cn && __cn <= '9'))
|
||||
{
|
||||
__err |= ios_base::failbit;
|
||||
return minutes(0);
|
||||
}
|
||||
__minn = __minn * 10 + __cn - '0';
|
||||
}
|
||||
if (++__b == __e)
|
||||
__err |= ios_base::eofbit;
|
||||
__minn += __hr * 60;
|
||||
__minn *= __sn;
|
||||
}
|
||||
else
|
||||
__err |= ios_base::eofbit | ios_base::failbit;
|
||||
return minutes(__minn);
|
||||
}
|
||||
|
||||
template <class _CharT, class _Traits, class _Duration>
|
||||
basic_istream<_CharT, _Traits>&
|
||||
operator>>(basic_istream<_CharT, _Traits>& __is,
|
||||
time_point<system_clock, _Duration>& __tp)
|
||||
{
|
||||
typename basic_istream<_CharT,_Traits>::sentry ok(__is);
|
||||
if (ok)
|
||||
{
|
||||
ios_base::iostate err = ios_base::goodbit;
|
||||
try
|
||||
{
|
||||
const _CharT* pb = nullptr;
|
||||
const _CharT* pe = pb;
|
||||
typedef timepunct<_CharT> F;
|
||||
locale loc = __is.getloc();
|
||||
timezone tz = utc;
|
||||
if (has_facet<F>(loc))
|
||||
{
|
||||
const F& f = use_facet<F>(loc);
|
||||
pb = f.fmt().data();
|
||||
pe = pb + f.fmt().size();
|
||||
tz = f.get_timezone();
|
||||
}
|
||||
const time_get<_CharT>& tg = use_facet<time_get<_CharT> >(loc);
|
||||
const ctype<_CharT>& __ct = use_facet<ctype<_CharT> >(loc);
|
||||
tm __tm = {0};
|
||||
typedef istreambuf_iterator<_CharT, _Traits> _I;
|
||||
if (pb == pe)
|
||||
{
|
||||
_CharT pattern[] = {'%', 'Y', '-', '%', 'm', '-', '%', 'd',
|
||||
'T', '%', 'H', ':', '%', 'M', ':'};
|
||||
pb = pattern;
|
||||
pe = pb + sizeof(pattern) / sizeof(_CharT);
|
||||
tg.get(__is, 0, __is, err, &__tm, pb, pe);
|
||||
if (err & ios_base::failbit)
|
||||
goto __exit;
|
||||
double __sec;
|
||||
_CharT __c = _CharT();
|
||||
__is >> __sec;
|
||||
if (__is.fail())
|
||||
{
|
||||
err |= ios_base::failbit;
|
||||
goto __exit;
|
||||
}
|
||||
_I __i(__is);
|
||||
_I __eof;
|
||||
__c = *__i;
|
||||
if (++__i == __eof || __c != ' ')
|
||||
{
|
||||
err |= ios_base::failbit;
|
||||
goto __exit;
|
||||
}
|
||||
minutes __minn = __extract_z(__i, __eof, err, __ct);
|
||||
if (err & ios_base::failbit)
|
||||
goto __exit;
|
||||
time_t __t;
|
||||
__t = timegm(&__tm);
|
||||
__tp = system_clock::from_time_t(__t) - __minn
|
||||
+ round<microseconds>(duration<double>(__sec));
|
||||
}
|
||||
else
|
||||
{
|
||||
const _CharT __z[2] = {'%', 'z'};
|
||||
const _CharT* __fz = std::search(pb, pe, __z, __z+2);
|
||||
tg.get(__is, 0, __is, err, &__tm, pb, __fz);
|
||||
minutes __minn(0);
|
||||
if (__fz != pe)
|
||||
{
|
||||
if (err != ios_base::goodbit)
|
||||
{
|
||||
err |= ios_base::failbit;
|
||||
goto __exit;
|
||||
}
|
||||
_I __i(__is);
|
||||
_I __eof;
|
||||
__minn = __extract_z(__i, __eof, err, __ct);
|
||||
if (err & ios_base::failbit)
|
||||
goto __exit;
|
||||
if (__fz+2 != pe)
|
||||
{
|
||||
if (err != ios_base::goodbit)
|
||||
{
|
||||
err |= ios_base::failbit;
|
||||
goto __exit;
|
||||
}
|
||||
tg.get(__is, 0, __is, err, &__tm, __fz+2, pe);
|
||||
if (err & ios_base::failbit)
|
||||
goto __exit;
|
||||
}
|
||||
}
|
||||
__tm.tm_isdst = -1;
|
||||
time_t __t;
|
||||
if (tz == utc || __fz != pe)
|
||||
__t = timegm(&__tm);
|
||||
else
|
||||
__t = mktime(&__tm);
|
||||
__tp = system_clock::from_time_t(__t) - __minn;
|
||||
}
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
err |= ios_base::badbit | ios_base::failbit;
|
||||
}
|
||||
__exit:
|
||||
__is.setstate(err);
|
||||
}
|
||||
return __is;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
} // chrono
|
||||
|
||||
//_LIBCPP_END_NAMESPACE_STD
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user