Eschew using directives in headers, even at function scope.

* There is still an impact on user code, though I'm not sure
  if by specification or compiler bug.
* Prefer using declarations instead.
This commit is contained in:
Howard Hinnant
2019-05-19 21:53:29 -04:00
parent ed0368fc75
commit 44215f6781
5 changed files with 181 additions and 162 deletions

View File

@ -1106,7 +1106,7 @@ typename std::enable_if
>::type >::type
trunc(T t) NOEXCEPT trunc(T t) NOEXCEPT
{ {
using namespace std; using std::numeric_limits;
using I = typename choose_trunc_type<T>::type; using I = typename choose_trunc_type<T>::type;
CONSTDATA auto digits = numeric_limits<T>::digits; CONSTDATA auto digits = numeric_limits<T>::digits;
static_assert(digits < numeric_limits<I>::digits, ""); static_assert(digits < numeric_limits<I>::digits, "");
@ -1197,7 +1197,8 @@ typename std::enable_if
>::type >::type
trunc(const std::chrono::duration<Rep, Period>& d) trunc(const std::chrono::duration<Rep, Period>& d)
{ {
using namespace std::chrono; using std::chrono::duration_cast;
using std::chrono::duration;
using rep = typename std::common_type<Rep, typename To::rep>::type; using rep = typename std::common_type<Rep, typename To::rep>::type;
return To{detail::trunc(duration_cast<To>(duration_cast<duration<rep>>(d)).count())}; return To{detail::trunc(duration_cast<To>(duration_cast<duration<rep>>(d)).count())};
} }
@ -1243,9 +1244,8 @@ typename std::enable_if
>::type >::type
floor(const std::chrono::duration<Rep, Period>& d) floor(const std::chrono::duration<Rep, Period>& d)
{ {
using namespace std::chrono;
using rep = typename std::common_type<Rep, typename To::rep>::type; using rep = typename std::common_type<Rep, typename To::rep>::type;
return floor<To>(floor<duration<rep>>(d)); return floor<To>(floor<std::chrono::duration<rep>>(d));
} }
// round to nearest, to even on tie // round to nearest, to even on tie
@ -3746,8 +3746,7 @@ public:
CONSTCD11 bool in_conventional_range() const NOEXCEPT CONSTCD11 bool in_conventional_range() const NOEXCEPT
{ {
using namespace std::chrono; return sub_s_ < std::chrono::seconds{1} && s_ < std::chrono::minutes{1};
return sub_s_ < std::chrono::seconds{1} && s_ < minutes{1};
} }
template <class CharT, class Traits> template <class CharT, class Traits>
@ -3861,8 +3860,7 @@ public:
CONSTCD11 bool in_conventional_range() const NOEXCEPT CONSTCD11 bool in_conventional_range() const NOEXCEPT
{ {
using namespace std; return !neg_ && h_ < days{1} && m_ < std::chrono::hours{1} &&
return !neg_ && h_ < days{1} && m_ < chrono::hours{1} &&
s_.in_conventional_range(); s_.in_conventional_range();
} }
@ -3873,14 +3871,12 @@ private:
std::basic_ostream<charT, traits>& std::basic_ostream<charT, traits>&
operator<<(std::basic_ostream<charT, traits>& os, hh_mm_ss const& tod) operator<<(std::basic_ostream<charT, traits>& os, hh_mm_ss const& tod)
{ {
using namespace detail;
using namespace std;
if (tod.is_negative()) if (tod.is_negative())
os << '-'; os << '-';
if (tod.h_ < chrono::hours{10}) if (tod.h_ < std::chrono::hours{10})
os << '0'; os << '0';
os << tod.h_.count() << ':'; os << tod.h_.count() << ':';
if (tod.m_ < chrono::minutes{10}) if (tod.m_ < std::chrono::minutes{10})
os << '0'; os << '0';
os << tod.m_.count() << ':' << tod.s_; os << tod.m_.count() << ':' << tod.s_;
return os; return os;
@ -3906,7 +3902,7 @@ CONSTCD14
bool bool
is_am(std::chrono::hours const& h) NOEXCEPT is_am(std::chrono::hours const& h) NOEXCEPT
{ {
using namespace std::chrono; using std::chrono::hours;
return hours{0} <= h && h < hours{12}; return hours{0} <= h && h < hours{12};
} }
@ -3915,7 +3911,7 @@ CONSTCD14
bool bool
is_pm(std::chrono::hours const& h) NOEXCEPT is_pm(std::chrono::hours const& h) NOEXCEPT
{ {
using namespace std::chrono; using std::chrono::hours;
return hours{12} <= h && h < hours{24}; return hours{12} <= h && h < hours{24};
} }
@ -3924,7 +3920,7 @@ CONSTCD14
std::chrono::hours std::chrono::hours
make12(std::chrono::hours h) NOEXCEPT make12(std::chrono::hours h) NOEXCEPT
{ {
using namespace std::chrono; using std::chrono::hours;
if (h < hours{12}) if (h < hours{12})
{ {
if (h == hours{0}) if (h == hours{0})
@ -3943,7 +3939,7 @@ CONSTCD14
std::chrono::hours std::chrono::hours
make24(std::chrono::hours h, bool is_pm) NOEXCEPT make24(std::chrono::hours h, bool is_pm) NOEXCEPT
{ {
using namespace std::chrono; using std::chrono::hours;
if (is_pm) if (is_pm)
{ {
if (h != hours{12}) if (h != hours{12})
@ -4697,19 +4693,18 @@ template <class CharT, class Traits, class FwdIter>
FwdIter FwdIter
scan_keyword(std::basic_istream<CharT, Traits>& is, FwdIter kb, FwdIter ke) scan_keyword(std::basic_istream<CharT, Traits>& is, FwdIter kb, FwdIter ke)
{ {
using namespace std;
size_t nkw = static_cast<size_t>(std::distance(kb, ke)); size_t nkw = static_cast<size_t>(std::distance(kb, ke));
const unsigned char doesnt_match = '\0'; const unsigned char doesnt_match = '\0';
const unsigned char might_match = '\1'; const unsigned char might_match = '\1';
const unsigned char does_match = '\2'; const unsigned char does_match = '\2';
unsigned char statbuf[100]; unsigned char statbuf[100];
unsigned char* status = statbuf; unsigned char* status = statbuf;
unique_ptr<unsigned char, void(*)(void*)> stat_hold(0, free); std::unique_ptr<unsigned char, void(*)(void*)> stat_hold(0, free);
if (nkw > sizeof(statbuf)) if (nkw > sizeof(statbuf))
{ {
status = (unsigned char*)malloc(nkw); status = (unsigned char*)std::malloc(nkw);
if (status == nullptr) if (status == nullptr)
throw bad_alloc(); throw std::bad_alloc();
stat_hold.reset(status); stat_hold.reset(status);
} }
size_t n_might_match = nkw; // At this point, any keyword might match size_t n_might_match = nkw; // At this point, any keyword might match
@ -4734,7 +4729,7 @@ scan_keyword(std::basic_istream<CharT, Traits>& is, FwdIter kb, FwdIter ke)
auto ic = is.peek(); auto ic = is.peek();
if (ic == EOF) if (ic == EOF)
{ {
is.setstate(ios::eofbit); is.setstate(std::ios::eofbit);
break; break;
} }
auto c = static_cast<char>(toupper(ic)); auto c = static_cast<char>(toupper(ic));
@ -4794,7 +4789,7 @@ scan_keyword(std::basic_istream<CharT, Traits>& is, FwdIter kb, FwdIter ke)
if (*st == does_match) if (*st == does_match)
break; break;
if (kb == ke) if (kb == ke)
is.setstate(ios_base::failbit); is.setstate(std::ios::failbit);
return kb; return kb;
} }
@ -4808,9 +4803,20 @@ to_stream(std::basic_ostream<CharT, Traits>& os, const CharT* fmt,
const fields<Duration>& fds, const std::string* abbrev, const fields<Duration>& fds, const std::string* abbrev,
const std::chrono::seconds* offset_sec) const std::chrono::seconds* offset_sec)
{ {
using namespace std; #if ONLY_C_LOCALE
using namespace std::chrono; using detail::weekday_names;
using namespace detail; using detail::month_names;
using detail::ampm_names;
#endif
using detail::save_ostream;
using detail::get_units;
using detail::extract_weekday;
using detail::extract_month;
using std::ios;
using std::chrono::duration_cast;
using std::chrono::seconds;
using std::chrono::minutes;
using std::chrono::hours;
date::detail::save_ostream<CharT, Traits> ss(os); date::detail::save_ostream<CharT, Traits> ss(os);
os.fill(' '); os.fill(' ');
os.flags(std::ios::skipws | std::ios::dec); os.flags(std::ios::skipws | std::ios::dec);
@ -4818,7 +4824,7 @@ to_stream(std::basic_ostream<CharT, Traits>& os, const CharT* fmt,
tm tm{}; tm tm{};
bool insert_negative = fds.has_tod && fds.tod.to_duration() < Duration::zero(); bool insert_negative = fds.has_tod && fds.tod.to_duration() < Duration::zero();
#if !ONLY_C_LOCALE #if !ONLY_C_LOCALE
auto& facet = use_facet<time_put<CharT>>(os.getloc()); auto& facet = std::use_facet<std::time_put<CharT>>(os.getloc());
#endif #endif
const CharT* command = nullptr; const CharT* command = nullptr;
CharT modified = CharT{}; CharT modified = CharT{};
@ -4837,7 +4843,7 @@ to_stream(std::basic_ostream<CharT, Traits>& os, const CharT* fmt,
return os; return os;
#if !ONLY_C_LOCALE #if !ONLY_C_LOCALE
const CharT f[] = {'%', *fmt}; const CharT f[] = {'%', *fmt};
facet.put(os, os, os.fill(), &tm, begin(f), end(f)); facet.put(os, os, os.fill(), &tm, std::begin(f), std::end(f));
#else // ONLY_C_LOCALE #else // ONLY_C_LOCALE
os << weekday_names().first[tm.tm_wday+7*(*fmt == 'a')]; os << weekday_names().first[tm.tm_wday+7*(*fmt == 'a')];
#endif // ONLY_C_LOCALE #endif // ONLY_C_LOCALE
@ -4862,7 +4868,7 @@ to_stream(std::basic_ostream<CharT, Traits>& os, const CharT* fmt,
tm.tm_mon = static_cast<int>(extract_month(os, fds)) - 1; tm.tm_mon = static_cast<int>(extract_month(os, fds)) - 1;
#if !ONLY_C_LOCALE #if !ONLY_C_LOCALE
const CharT f[] = {'%', *fmt}; const CharT f[] = {'%', *fmt};
facet.put(os, os, os.fill(), &tm, begin(f), end(f)); facet.put(os, os, os.fill(), &tm, std::begin(f), std::end(f));
#else // ONLY_C_LOCALE #else // ONLY_C_LOCALE
os << month_names().first[tm.tm_mon+12*(*fmt != 'B')]; os << month_names().first[tm.tm_mon+12*(*fmt != 'B')];
#endif // ONLY_C_LOCALE #endif // ONLY_C_LOCALE
@ -4907,11 +4913,11 @@ to_stream(std::basic_ostream<CharT, Traits>& os, const CharT* fmt,
return os; return os;
tm.tm_yday = static_cast<int>((ld - local_days(ymd.year()/1/1)).count()); tm.tm_yday = static_cast<int>((ld - local_days(ymd.year()/1/1)).count());
CharT f[3] = {'%'}; CharT f[3] = {'%'};
auto fe = begin(f) + 1; auto fe = std::begin(f) + 1;
if (modified == CharT{'E'}) if (modified == CharT{'E'})
*fe++ = modified; *fe++ = modified;
*fe++ = *fmt; *fe++ = *fmt;
facet.put(os, os, os.fill(), &tm, begin(f), fe); facet.put(os, os, os.fill(), &tm, std::begin(f), fe);
#else // ONLY_C_LOCALE #else // ONLY_C_LOCALE
if (*fmt == 'c') if (*fmt == 'c')
{ {
@ -4982,7 +4988,7 @@ to_stream(std::basic_ostream<CharT, Traits>& os, const CharT* fmt,
{ {
tm.tm_year = y - 1900; tm.tm_year = y - 1900;
CharT f[3] = {'%', 'E', 'C'}; CharT f[3] = {'%', 'E', 'C'};
facet.put(os, os, os.fill(), &tm, begin(f), end(f)); facet.put(os, os, os.fill(), &tm, std::begin(f), std::end(f));
} }
#endif #endif
} }
@ -5021,7 +5027,7 @@ to_stream(std::basic_ostream<CharT, Traits>& os, const CharT* fmt,
{ {
tm.tm_mday = d; tm.tm_mday = d;
CharT f[3] = {'%', 'O', *fmt}; CharT f[3] = {'%', 'O', *fmt};
facet.put(os, os, os.fill(), &tm, begin(f), end(f)); facet.put(os, os, os.fill(), &tm, std::begin(f), std::end(f));
} }
#endif #endif
} }
@ -5152,7 +5158,7 @@ to_stream(std::basic_ostream<CharT, Traits>& os, const CharT* fmt,
{ {
const CharT f[] = {'%', modified, *fmt}; const CharT f[] = {'%', modified, *fmt};
tm.tm_hour = static_cast<int>(hms.hours().count()); tm.tm_hour = static_cast<int>(hms.hours().count());
facet.put(os, os, os.fill(), &tm, begin(f), end(f)); facet.put(os, os, os.fill(), &tm, std::begin(f), std::end(f));
} }
#endif #endif
} }
@ -5224,7 +5230,7 @@ to_stream(std::basic_ostream<CharT, Traits>& os, const CharT* fmt,
{ {
const CharT f[] = {'%', modified, *fmt}; const CharT f[] = {'%', modified, *fmt};
tm.tm_mon = static_cast<int>(m-1); tm.tm_mon = static_cast<int>(m-1);
facet.put(os, os, os.fill(), &tm, begin(f), end(f)); facet.put(os, os, os.fill(), &tm, std::begin(f), std::end(f));
} }
#endif #endif
} }
@ -5261,7 +5267,7 @@ to_stream(std::basic_ostream<CharT, Traits>& os, const CharT* fmt,
{ {
const CharT f[] = {'%', modified, *fmt}; const CharT f[] = {'%', modified, *fmt};
tm.tm_min = static_cast<int>(fds.tod.minutes().count()); tm.tm_min = static_cast<int>(fds.tod.minutes().count());
facet.put(os, os, os.fill(), &tm, begin(f), end(f)); facet.put(os, os, os.fill(), &tm, std::begin(f), std::end(f));
} }
#endif #endif
} }
@ -5296,7 +5302,7 @@ to_stream(std::basic_ostream<CharT, Traits>& os, const CharT* fmt,
#if !ONLY_C_LOCALE #if !ONLY_C_LOCALE
const CharT f[] = {'%', *fmt}; const CharT f[] = {'%', *fmt};
tm.tm_hour = static_cast<int>(fds.tod.hours().count()); tm.tm_hour = static_cast<int>(fds.tod.hours().count());
facet.put(os, os, os.fill(), &tm, begin(f), end(f)); facet.put(os, os, os.fill(), &tm, std::begin(f), std::end(f));
#else #else
if (is_am(fds.tod.hours())) if (is_am(fds.tod.hours()))
os << ampm_names().first[0]; os << ampm_names().first[0];
@ -5350,7 +5356,7 @@ to_stream(std::basic_ostream<CharT, Traits>& os, const CharT* fmt,
tm.tm_hour = static_cast<int>(fds.tod.hours().count()); tm.tm_hour = static_cast<int>(fds.tod.hours().count());
tm.tm_min = static_cast<int>(fds.tod.minutes().count()); tm.tm_min = static_cast<int>(fds.tod.minutes().count());
tm.tm_sec = static_cast<int>(fds.tod.seconds().count()); tm.tm_sec = static_cast<int>(fds.tod.seconds().count());
facet.put(os, os, os.fill(), &tm, begin(f), end(f)); facet.put(os, os, os.fill(), &tm, std::begin(f), std::end(f));
#else #else
hh_mm_ss<seconds> tod(duration_cast<seconds>(fds.tod.to_duration())); hh_mm_ss<seconds> tod(duration_cast<seconds>(fds.tod.to_duration()));
save_ostream<CharT, Traits> _(os); save_ostream<CharT, Traits> _(os);
@ -5426,7 +5432,7 @@ to_stream(std::basic_ostream<CharT, Traits>& os, const CharT* fmt,
{ {
const CharT f[] = {'%', modified, *fmt}; const CharT f[] = {'%', modified, *fmt};
tm.tm_sec = static_cast<int>(fds.tod.s_.seconds().count()); tm.tm_sec = static_cast<int>(fds.tod.s_.seconds().count());
facet.put(os, os, os.fill(), &tm, begin(f), end(f)); facet.put(os, os, os.fill(), &tm, std::begin(f), std::end(f));
} }
#endif #endif
} }
@ -5489,7 +5495,7 @@ to_stream(std::basic_ostream<CharT, Traits>& os, const CharT* fmt,
{ {
const CharT f[] = {'%', modified, *fmt}; const CharT f[] = {'%', modified, *fmt};
tm.tm_wday = static_cast<int>(wd); tm.tm_wday = static_cast<int>(wd);
facet.put(os, os, os.fill(), &tm, begin(f), end(f)); facet.put(os, os, os.fill(), &tm, std::begin(f), std::end(f));
} }
#endif #endif
} }
@ -5534,7 +5540,7 @@ to_stream(std::basic_ostream<CharT, Traits>& os, const CharT* fmt,
if (os.fail()) if (os.fail())
return os; return os;
tm.tm_yday = static_cast<int>((ld - local_days(ymd.year()/1/1)).count()); tm.tm_yday = static_cast<int>((ld - local_days(ymd.year()/1/1)).count());
facet.put(os, os, os.fill(), &tm, begin(f), end(f)); facet.put(os, os, os.fill(), &tm, std::begin(f), std::end(f));
} }
#endif #endif
} }
@ -5582,7 +5588,7 @@ to_stream(std::basic_ostream<CharT, Traits>& os, const CharT* fmt,
if (os.fail()) if (os.fail())
return os; return os;
tm.tm_yday = static_cast<int>((ld - local_days(ymd.year()/1/1)).count()); tm.tm_yday = static_cast<int>((ld - local_days(ymd.year()/1/1)).count());
facet.put(os, os, os.fill(), &tm, begin(f), end(f)); facet.put(os, os, os.fill(), &tm, std::begin(f), std::end(f));
} }
#endif #endif
} }
@ -5611,7 +5617,7 @@ to_stream(std::basic_ostream<CharT, Traits>& os, const CharT* fmt,
{ {
const CharT f[] = {'%', modified, *fmt}; const CharT f[] = {'%', modified, *fmt};
tm.tm_wday = static_cast<int>(wd); tm.tm_wday = static_cast<int>(wd);
facet.put(os, os, os.fill(), &tm, begin(f), end(f)); facet.put(os, os, os.fill(), &tm, std::begin(f), std::end(f));
} }
#endif #endif
else else
@ -5659,7 +5665,7 @@ to_stream(std::basic_ostream<CharT, Traits>& os, const CharT* fmt,
if (os.fail()) if (os.fail())
return os; return os;
tm.tm_yday = static_cast<int>((ld - local_days(ymd.year()/1/1)).count()); tm.tm_yday = static_cast<int>((ld - local_days(ymd.year()/1/1)).count());
facet.put(os, os, os.fill(), &tm, begin(f), end(f)); facet.put(os, os, os.fill(), &tm, std::begin(f), std::end(f));
} }
#endif #endif
} }
@ -5684,11 +5690,11 @@ to_stream(std::basic_ostream<CharT, Traits>& os, const CharT* fmt,
tm.tm_min = static_cast<int>(fds.tod.minutes().count()); tm.tm_min = static_cast<int>(fds.tod.minutes().count());
tm.tm_hour = static_cast<int>(fds.tod.hours().count()); tm.tm_hour = static_cast<int>(fds.tod.hours().count());
CharT f[3] = {'%'}; CharT f[3] = {'%'};
auto fe = begin(f) + 1; auto fe = std::begin(f) + 1;
if (modified == CharT{'E'}) if (modified == CharT{'E'})
*fe++ = modified; *fe++ = modified;
*fe++ = *fmt; *fe++ = *fmt;
facet.put(os, os, os.fill(), &tm, begin(f), fe); facet.put(os, os, os.fill(), &tm, std::begin(f), fe);
#else #else
os << fds.tod; os << fds.tod;
#endif #endif
@ -5719,7 +5725,7 @@ to_stream(std::basic_ostream<CharT, Traits>& os, const CharT* fmt,
{ {
const CharT f[] = {'%', modified, *fmt}; const CharT f[] = {'%', modified, *fmt};
tm.tm_year = y - 1900; tm.tm_year = y - 1900;
facet.put(os, os, os.fill(), &tm, begin(f), end(f)); facet.put(os, os, os.fill(), &tm, std::begin(f), std::end(f));
} }
#endif #endif
modified = CharT{}; modified = CharT{};
@ -5749,7 +5755,7 @@ to_stream(std::basic_ostream<CharT, Traits>& os, const CharT* fmt,
{ {
const CharT f[] = {'%', modified, *fmt}; const CharT f[] = {'%', modified, *fmt};
tm.tm_year = static_cast<int>(y) - 1900; tm.tm_year = static_cast<int>(y) - 1900;
facet.put(os, os, os.fill(), &tm, begin(f), end(f)); facet.put(os, os, os.fill(), &tm, std::begin(f), std::end(f));
} }
#endif #endif
} }
@ -5973,7 +5979,7 @@ std::basic_ostream<CharT, Traits>&
to_stream(std::basic_ostream<CharT, Traits>& os, const CharT* fmt, to_stream(std::basic_ostream<CharT, Traits>& os, const CharT* fmt,
const sys_time<Duration>& tp) const sys_time<Duration>& tp)
{ {
using namespace std::chrono; using std::chrono::seconds;
using CT = typename std::common_type<Duration, seconds>::type; using CT = typename std::common_type<Duration, seconds>::type;
const std::string abbrev("UTC"); const std::string abbrev("UTC");
CONSTDATA seconds offset{0}; CONSTDATA seconds offset{0};
@ -6110,10 +6116,9 @@ template <class CharT, class Traits>
long double long double
read_long_double(std::basic_istream<CharT, Traits>& is, unsigned m = 1, unsigned M = 10) read_long_double(std::basic_istream<CharT, Traits>& is, unsigned m = 1, unsigned M = 10)
{ {
using namespace std;
unsigned count = 0; unsigned count = 0;
auto decimal_point = Traits::to_int_type( auto decimal_point = Traits::to_int_type(
use_facet<numpunct<CharT>>(is.getloc()).decimal_point()); std::use_facet<std::numpunct<CharT>>(is.getloc()).decimal_point());
std::string buf; std::string buf;
while (true) while (true)
{ {
@ -6292,9 +6297,14 @@ from_stream(std::basic_istream<CharT, Traits>& is, const CharT* fmt,
fields<Duration>& fds, std::basic_string<CharT, Traits, Alloc>* abbrev, fields<Duration>& fds, std::basic_string<CharT, Traits, Alloc>* abbrev,
std::chrono::minutes* offset) std::chrono::minutes* offset)
{ {
using namespace std; using std::numeric_limits;
using namespace std::chrono; using std::ios;
typename basic_istream<CharT, Traits>::sentry ok{is, true}; using std::chrono::duration;
using std::chrono::duration_cast;
using std::chrono::seconds;
using std::chrono::minutes;
using std::chrono::hours;
typename std::basic_istream<CharT, Traits>::sentry ok{is, true};
if (ok) if (ok)
{ {
date::detail::save_istream<CharT, Traits> ss(is); date::detail::save_istream<CharT, Traits> ss(is);
@ -6302,7 +6312,7 @@ from_stream(std::basic_istream<CharT, Traits>& is, const CharT* fmt,
is.flags(std::ios::skipws | std::ios::dec); is.flags(std::ios::skipws | std::ios::dec);
is.width(0); is.width(0);
#if !ONLY_C_LOCALE #if !ONLY_C_LOCALE
auto& f = use_facet<time_get<CharT>>(is.getloc()); auto& f = std::use_facet<std::time_get<CharT>>(is.getloc());
std::tm tm{}; std::tm tm{};
#endif #endif
const CharT* command = nullptr; const CharT* command = nullptr;
@ -6365,7 +6375,7 @@ from_stream(std::basic_istream<CharT, Traits>& is, const CharT* fmt,
if (modified == CharT{}) if (modified == CharT{})
{ {
#if !ONLY_C_LOCALE #if !ONLY_C_LOCALE
ios_base::iostate err = ios_base::goodbit; ios::iostate err = ios::goodbit;
f.get(is, nullptr, is, err, &tm, command, fmt+1); f.get(is, nullptr, is, err, &tm, command, fmt+1);
is.setstate(err); is.setstate(err);
if (!is.fail()) if (!is.fail())
@ -6397,7 +6407,7 @@ from_stream(std::basic_istream<CharT, Traits>& is, const CharT* fmt,
if (!(1 <= trial_wd && trial_wd <= 7)) if (!(1 <= trial_wd && trial_wd <= 7))
{ {
trial_wd = not_a_weekday; trial_wd = not_a_weekday;
is.setstate(ios_base::failbit); is.setstate(ios::failbit);
} }
else if (trial_wd == 7) else if (trial_wd == 7)
trial_wd = 0; trial_wd = 0;
@ -6407,7 +6417,7 @@ from_stream(std::basic_istream<CharT, Traits>& is, const CharT* fmt,
if (!(0 <= trial_wd && trial_wd <= 6)) if (!(0 <= trial_wd && trial_wd <= 6))
{ {
trial_wd = not_a_weekday; trial_wd = not_a_weekday;
is.setstate(ios_base::failbit); is.setstate(ios::failbit);
} }
} }
} }
@ -6415,7 +6425,7 @@ from_stream(std::basic_istream<CharT, Traits>& is, const CharT* fmt,
#if !ONLY_C_LOCALE #if !ONLY_C_LOCALE
else if (modified == CharT{'O'}) else if (modified == CharT{'O'})
{ {
ios_base::iostate err = ios_base::goodbit; ios::iostate err = ios::goodbit;
f.get(is, nullptr, is, err, &tm, command, fmt+1); f.get(is, nullptr, is, err, &tm, command, fmt+1);
is.setstate(err); is.setstate(err);
if (!is.fail()) if (!is.fail())
@ -6443,7 +6453,7 @@ from_stream(std::basic_istream<CharT, Traits>& is, const CharT* fmt,
{ {
int ttm = not_a_month; int ttm = not_a_month;
#if !ONLY_C_LOCALE #if !ONLY_C_LOCALE
ios_base::iostate err = ios_base::goodbit; ios::iostate err = ios::goodbit;
f.get(is, nullptr, is, err, &tm, command, fmt+1); f.get(is, nullptr, is, err, &tm, command, fmt+1);
if ((err & ios::failbit) == 0) if ((err & ios::failbit) == 0)
ttm = tm.tm_mon + 1; ttm = tm.tm_mon + 1;
@ -6471,7 +6481,7 @@ from_stream(std::basic_istream<CharT, Traits>& is, const CharT* fmt,
if (modified != CharT{'O'}) if (modified != CharT{'O'})
{ {
#if !ONLY_C_LOCALE #if !ONLY_C_LOCALE
ios_base::iostate err = ios_base::goodbit; ios::iostate err = ios::goodbit;
f.get(is, nullptr, is, err, &tm, command, fmt+1); f.get(is, nullptr, is, err, &tm, command, fmt+1);
if ((err & ios::failbit) == 0) if ((err & ios::failbit) == 0)
{ {
@ -6530,7 +6540,7 @@ from_stream(std::basic_istream<CharT, Traits>& is, const CharT* fmt,
if (modified != CharT{'O'}) if (modified != CharT{'O'})
{ {
#if !ONLY_C_LOCALE #if !ONLY_C_LOCALE
ios_base::iostate err = ios_base::goodbit; ios::iostate err = ios::goodbit;
f.get(is, nullptr, is, err, &tm, command, fmt+1); f.get(is, nullptr, is, err, &tm, command, fmt+1);
if ((err & ios::failbit) == 0) if ((err & ios::failbit) == 0)
{ {
@ -6566,7 +6576,7 @@ from_stream(std::basic_istream<CharT, Traits>& is, const CharT* fmt,
if (modified != CharT{'O'}) if (modified != CharT{'O'})
{ {
#if !ONLY_C_LOCALE #if !ONLY_C_LOCALE
ios_base::iostate err = ios_base::goodbit; ios::iostate err = ios::goodbit;
f.get(is, nullptr, is, err, &tm, command, fmt+1); f.get(is, nullptr, is, err, &tm, command, fmt+1);
if ((err & ios::failbit) == 0) if ((err & ios::failbit) == 0)
{ {
@ -6613,7 +6623,7 @@ from_stream(std::basic_istream<CharT, Traits>& is, const CharT* fmt,
} }
else else
{ {
ios_base::iostate err = ios_base::goodbit; ios::iostate err = ios::goodbit;
f.get(is, nullptr, is, err, &tm, command, fmt+1); f.get(is, nullptr, is, err, &tm, command, fmt+1);
if ((err & ios::failbit) == 0) if ((err & ios::failbit) == 0)
{ {
@ -6695,7 +6705,7 @@ from_stream(std::basic_istream<CharT, Traits>& is, const CharT* fmt,
#if !ONLY_C_LOCALE #if !ONLY_C_LOCALE
else if (modified == CharT{'O'}) else if (modified == CharT{'O'})
{ {
ios_base::iostate err = ios_base::goodbit; ios::iostate err = ios::goodbit;
f.get(is, nullptr, is, err, &tm, command, fmt+1); f.get(is, nullptr, is, err, &tm, command, fmt+1);
command = nullptr; command = nullptr;
width = -1; width = -1;
@ -6730,7 +6740,7 @@ from_stream(std::basic_istream<CharT, Traits>& is, const CharT* fmt,
#if !ONLY_C_LOCALE #if !ONLY_C_LOCALE
else if (modified == CharT{'O'}) else if (modified == CharT{'O'})
{ {
ios_base::iostate err = ios_base::goodbit; ios::iostate err = ios::goodbit;
f.get(is, nullptr, is, err, &tm, command, fmt+1); f.get(is, nullptr, is, err, &tm, command, fmt+1);
if ((err & ios::failbit) == 0) if ((err & ios::failbit) == 0)
checked_set(H, tm.tm_hour, not_a_hour, is); checked_set(H, tm.tm_hour, not_a_hour, is);
@ -6801,7 +6811,7 @@ from_stream(std::basic_istream<CharT, Traits>& is, const CharT* fmt,
#if !ONLY_C_LOCALE #if !ONLY_C_LOCALE
else if (modified == CharT{'O'}) else if (modified == CharT{'O'})
{ {
ios_base::iostate err = ios_base::goodbit; ios::iostate err = ios::goodbit;
f.get(is, nullptr, is, err, &tm, command, fmt+1); f.get(is, nullptr, is, err, &tm, command, fmt+1);
if ((err & ios::failbit) == 0) if ((err & ios::failbit) == 0)
checked_set(M, tm.tm_min, not_a_minute, is); checked_set(M, tm.tm_min, not_a_minute, is);
@ -6833,7 +6843,7 @@ from_stream(std::basic_istream<CharT, Traits>& is, const CharT* fmt,
#if !ONLY_C_LOCALE #if !ONLY_C_LOCALE
else if (modified == CharT{'O'}) else if (modified == CharT{'O'})
{ {
ios_base::iostate err = ios_base::goodbit; ios::iostate err = ios::goodbit;
f.get(is, nullptr, is, err, &tm, command, fmt+1); f.get(is, nullptr, is, err, &tm, command, fmt+1);
if ((err & ios::failbit) == 0) if ((err & ios::failbit) == 0)
checked_set(m, tm.tm_mon + 1, not_a_month, is); checked_set(m, tm.tm_mon + 1, not_a_month, is);
@ -6860,9 +6870,9 @@ from_stream(std::basic_istream<CharT, Traits>& is, const CharT* fmt,
auto ic = is.peek(); auto ic = is.peek();
if (Traits::eq_int_type(ic, Traits::eof())) if (Traits::eq_int_type(ic, Traits::eof()))
{ {
ios_base::iostate err = ios_base::eofbit; ios::iostate err = ios::eofbit;
if (*fmt == 'n') if (*fmt == 'n')
err |= ios_base::failbit; err |= ios::failbit;
is.setstate(err); is.setstate(err);
break; break;
} }
@ -6871,7 +6881,7 @@ from_stream(std::basic_istream<CharT, Traits>& is, const CharT* fmt,
(void)is.get(); (void)is.get();
} }
else if (*fmt == 'n') else if (*fmt == 'n')
is.setstate(ios_base::failbit); is.setstate(ios::failbit);
} }
else else
read(is, CharT{'%'}, width, modified, *fmt); read(is, CharT{'%'}, width, modified, *fmt);
@ -6891,7 +6901,7 @@ from_stream(std::basic_istream<CharT, Traits>& is, const CharT* fmt,
#if !ONLY_C_LOCALE #if !ONLY_C_LOCALE
tm = std::tm{}; tm = std::tm{};
tm.tm_hour = 1; tm.tm_hour = 1;
ios_base::iostate err = ios_base::goodbit; ios::iostate err = ios::goodbit;
f.get(is, nullptr, is, err, &tm, command, fmt+1); f.get(is, nullptr, is, err, &tm, command, fmt+1);
is.setstate(err); is.setstate(err);
if (tm.tm_hour == 1) if (tm.tm_hour == 1)
@ -6923,7 +6933,7 @@ from_stream(std::basic_istream<CharT, Traits>& is, const CharT* fmt,
if (modified == CharT{}) if (modified == CharT{})
{ {
#if !ONLY_C_LOCALE #if !ONLY_C_LOCALE
ios_base::iostate err = ios_base::goodbit; ios::iostate err = ios::goodbit;
f.get(is, nullptr, is, err, &tm, command, fmt+1); f.get(is, nullptr, is, err, &tm, command, fmt+1);
if ((err & ios::failbit) == 0) if ((err & ios::failbit) == 0)
{ {
@ -7001,7 +7011,7 @@ from_stream(std::basic_istream<CharT, Traits>& is, const CharT* fmt,
#if !ONLY_C_LOCALE #if !ONLY_C_LOCALE
else if (modified == CharT{'O'}) else if (modified == CharT{'O'})
{ {
ios_base::iostate err = ios_base::goodbit; ios::iostate err = ios::goodbit;
f.get(is, nullptr, is, err, &tm, command, fmt+1); f.get(is, nullptr, is, err, &tm, command, fmt+1);
if ((err & ios::failbit) == 0) if ((err & ios::failbit) == 0)
checked_set(s, duration_cast<Duration>(seconds{tm.tm_sec}), checked_set(s, duration_cast<Duration>(seconds{tm.tm_sec}),
@ -7060,7 +7070,7 @@ from_stream(std::basic_istream<CharT, Traits>& is, const CharT* fmt,
#if !ONLY_C_LOCALE #if !ONLY_C_LOCALE
else if (modified == CharT{'E'}) else if (modified == CharT{'E'})
{ {
ios_base::iostate err = ios_base::goodbit; ios::iostate err = ios::goodbit;
f.get(is, nullptr, is, err, &tm, command, fmt+1); f.get(is, nullptr, is, err, &tm, command, fmt+1);
if ((err & ios::failbit) == 0) if ((err & ios::failbit) == 0)
checked_set(Y, tm.tm_year + 1900, not_a_year, is); checked_set(Y, tm.tm_year + 1900, not_a_year, is);
@ -7090,7 +7100,7 @@ from_stream(std::basic_istream<CharT, Traits>& is, const CharT* fmt,
#if !ONLY_C_LOCALE #if !ONLY_C_LOCALE
else else
{ {
ios_base::iostate err = ios_base::goodbit; ios::iostate err = ios::goodbit;
f.get(is, nullptr, is, err, &tm, command, fmt+1); f.get(is, nullptr, is, err, &tm, command, fmt+1);
if ((err & ios::failbit) == 0) if ((err & ios::failbit) == 0)
checked_set(Y, tm.tm_year + 1900, not_a_year, is); checked_set(Y, tm.tm_year + 1900, not_a_year, is);
@ -7610,7 +7620,7 @@ from_stream(std::basic_istream<CharT, Traits>& is, const CharT* fmt,
return is; return is;
} }
broken: broken:
is.setstate(ios_base::failbit); is.setstate(ios::failbit);
return is; return is;
} }
@ -7620,13 +7630,11 @@ from_stream(std::basic_istream<CharT, Traits>& is, const CharT* fmt, year& y,
std::basic_string<CharT, Traits, Alloc>* abbrev = nullptr, std::basic_string<CharT, Traits, Alloc>* abbrev = nullptr,
std::chrono::minutes* offset = nullptr) std::chrono::minutes* offset = nullptr)
{ {
using namespace std; using CT = std::chrono::seconds;
using namespace std::chrono;
using CT = seconds;
fields<CT> fds{}; fields<CT> fds{};
from_stream(is, fmt, fds, abbrev, offset); from_stream(is, fmt, fds, abbrev, offset);
if (!fds.ymd.year().ok()) if (!fds.ymd.year().ok())
is.setstate(ios::failbit); is.setstate(std::ios::failbit);
if (!is.fail()) if (!is.fail())
y = fds.ymd.year(); y = fds.ymd.year();
return is; return is;
@ -7638,13 +7646,11 @@ from_stream(std::basic_istream<CharT, Traits>& is, const CharT* fmt, month& m,
std::basic_string<CharT, Traits, Alloc>* abbrev = nullptr, std::basic_string<CharT, Traits, Alloc>* abbrev = nullptr,
std::chrono::minutes* offset = nullptr) std::chrono::minutes* offset = nullptr)
{ {
using namespace std; using CT = std::chrono::seconds;
using namespace std::chrono;
using CT = seconds;
fields<CT> fds{}; fields<CT> fds{};
from_stream(is, fmt, fds, abbrev, offset); from_stream(is, fmt, fds, abbrev, offset);
if (!fds.ymd.month().ok()) if (!fds.ymd.month().ok())
is.setstate(ios::failbit); is.setstate(std::ios::failbit);
if (!is.fail()) if (!is.fail())
m = fds.ymd.month(); m = fds.ymd.month();
return is; return is;
@ -7656,13 +7662,11 @@ from_stream(std::basic_istream<CharT, Traits>& is, const CharT* fmt, day& d,
std::basic_string<CharT, Traits, Alloc>* abbrev = nullptr, std::basic_string<CharT, Traits, Alloc>* abbrev = nullptr,
std::chrono::minutes* offset = nullptr) std::chrono::minutes* offset = nullptr)
{ {
using namespace std; using CT = std::chrono::seconds;
using namespace std::chrono;
using CT = seconds;
fields<CT> fds{}; fields<CT> fds{};
from_stream(is, fmt, fds, abbrev, offset); from_stream(is, fmt, fds, abbrev, offset);
if (!fds.ymd.day().ok()) if (!fds.ymd.day().ok())
is.setstate(ios::failbit); is.setstate(std::ios::failbit);
if (!is.fail()) if (!is.fail())
d = fds.ymd.day(); d = fds.ymd.day();
return is; return is;
@ -7674,13 +7678,11 @@ from_stream(std::basic_istream<CharT, Traits>& is, const CharT* fmt, weekday& wd
std::basic_string<CharT, Traits, Alloc>* abbrev = nullptr, std::basic_string<CharT, Traits, Alloc>* abbrev = nullptr,
std::chrono::minutes* offset = nullptr) std::chrono::minutes* offset = nullptr)
{ {
using namespace std; using CT = std::chrono::seconds;
using namespace std::chrono;
using CT = seconds;
fields<CT> fds{}; fields<CT> fds{};
from_stream(is, fmt, fds, abbrev, offset); from_stream(is, fmt, fds, abbrev, offset);
if (!fds.wd.ok()) if (!fds.wd.ok())
is.setstate(ios::failbit); is.setstate(std::ios::failbit);
if (!is.fail()) if (!is.fail())
wd = fds.wd; wd = fds.wd;
return is; return is;
@ -7692,13 +7694,11 @@ from_stream(std::basic_istream<CharT, Traits>& is, const CharT* fmt, year_month&
std::basic_string<CharT, Traits, Alloc>* abbrev = nullptr, std::basic_string<CharT, Traits, Alloc>* abbrev = nullptr,
std::chrono::minutes* offset = nullptr) std::chrono::minutes* offset = nullptr)
{ {
using namespace std; using CT = std::chrono::seconds;
using namespace std::chrono;
using CT = seconds;
fields<CT> fds{}; fields<CT> fds{};
from_stream(is, fmt, fds, abbrev, offset); from_stream(is, fmt, fds, abbrev, offset);
if (!fds.ymd.month().ok()) if (!fds.ymd.month().ok())
is.setstate(ios::failbit); is.setstate(std::ios::failbit);
if (!is.fail()) if (!is.fail())
ym = fds.ymd.year()/fds.ymd.month(); ym = fds.ymd.year()/fds.ymd.month();
return is; return is;
@ -7710,13 +7710,11 @@ from_stream(std::basic_istream<CharT, Traits>& is, const CharT* fmt, month_day&
std::basic_string<CharT, Traits, Alloc>* abbrev = nullptr, std::basic_string<CharT, Traits, Alloc>* abbrev = nullptr,
std::chrono::minutes* offset = nullptr) std::chrono::minutes* offset = nullptr)
{ {
using namespace std; using CT = std::chrono::seconds;
using namespace std::chrono;
using CT = seconds;
fields<CT> fds{}; fields<CT> fds{};
from_stream(is, fmt, fds, abbrev, offset); from_stream(is, fmt, fds, abbrev, offset);
if (!fds.ymd.month().ok() || !fds.ymd.day().ok()) if (!fds.ymd.month().ok() || !fds.ymd.day().ok())
is.setstate(ios::failbit); is.setstate(std::ios::failbit);
if (!is.fail()) if (!is.fail())
md = fds.ymd.month()/fds.ymd.day(); md = fds.ymd.month()/fds.ymd.day();
return is; return is;
@ -7728,13 +7726,11 @@ from_stream(std::basic_istream<CharT, Traits>& is, const CharT* fmt,
year_month_day& ymd, std::basic_string<CharT, Traits, Alloc>* abbrev = nullptr, year_month_day& ymd, std::basic_string<CharT, Traits, Alloc>* abbrev = nullptr,
std::chrono::minutes* offset = nullptr) std::chrono::minutes* offset = nullptr)
{ {
using namespace std; using CT = std::chrono::seconds;
using namespace std::chrono;
using CT = seconds;
fields<CT> fds{}; fields<CT> fds{};
from_stream(is, fmt, fds, abbrev, offset); from_stream(is, fmt, fds, abbrev, offset);
if (!fds.ymd.ok()) if (!fds.ymd.ok())
is.setstate(ios::failbit); is.setstate(std::ios::failbit);
if (!is.fail()) if (!is.fail())
ymd = fds.ymd; ymd = fds.ymd;
return is; return is;
@ -7746,16 +7742,14 @@ from_stream(std::basic_istream<CharT, Traits>& is, const CharT* fmt,
sys_time<Duration>& tp, std::basic_string<CharT, Traits, Alloc>* abbrev = nullptr, sys_time<Duration>& tp, std::basic_string<CharT, Traits, Alloc>* abbrev = nullptr,
std::chrono::minutes* offset = nullptr) std::chrono::minutes* offset = nullptr)
{ {
using namespace std; using CT = typename std::common_type<Duration, std::chrono::seconds>::type;
using namespace std::chrono; std::chrono::minutes offset_local{};
using CT = typename common_type<Duration, seconds>::type;
minutes offset_local{};
auto offptr = offset ? offset : &offset_local; auto offptr = offset ? offset : &offset_local;
fields<CT> fds{}; fields<CT> fds{};
fds.has_tod = true; fds.has_tod = true;
from_stream(is, fmt, fds, abbrev, offptr); from_stream(is, fmt, fds, abbrev, offptr);
if (!fds.ymd.ok() || !fds.tod.in_conventional_range()) if (!fds.ymd.ok() || !fds.tod.in_conventional_range())
is.setstate(ios::failbit); is.setstate(std::ios::failbit);
if (!is.fail()) if (!is.fail())
tp = round<Duration>(sys_days(fds.ymd) - *offptr + fds.tod.to_duration()); tp = round<Duration>(sys_days(fds.ymd) - *offptr + fds.tod.to_duration());
return is; return is;
@ -7767,14 +7761,12 @@ from_stream(std::basic_istream<CharT, Traits>& is, const CharT* fmt,
local_time<Duration>& tp, std::basic_string<CharT, Traits, Alloc>* abbrev = nullptr, local_time<Duration>& tp, std::basic_string<CharT, Traits, Alloc>* abbrev = nullptr,
std::chrono::minutes* offset = nullptr) std::chrono::minutes* offset = nullptr)
{ {
using namespace std; using CT = typename std::common_type<Duration, std::chrono::seconds>::type;
using namespace std::chrono;
using CT = typename common_type<Duration, seconds>::type;
fields<CT> fds{}; fields<CT> fds{};
fds.has_tod = true; fds.has_tod = true;
from_stream(is, fmt, fds, abbrev, offset); from_stream(is, fmt, fds, abbrev, offset);
if (!fds.ymd.ok() || !fds.tod.in_conventional_range()) if (!fds.ymd.ok() || !fds.tod.in_conventional_range())
is.setstate(ios::failbit); is.setstate(std::ios::failbit);
if (!is.fail()) if (!is.fail())
tp = round<Duration>(local_seconds{local_days(fds.ymd)} + fds.tod.to_duration()); tp = round<Duration>(local_seconds{local_days(fds.ymd)} + fds.tod.to_duration());
return is; return is;
@ -7787,16 +7779,14 @@ from_stream(std::basic_istream<CharT, Traits>& is, const CharT* fmt,
std::basic_string<CharT, Traits, Alloc>* abbrev = nullptr, std::basic_string<CharT, Traits, Alloc>* abbrev = nullptr,
std::chrono::minutes* offset = nullptr) std::chrono::minutes* offset = nullptr)
{ {
using namespace std;
using namespace std::chrono;
using Duration = std::chrono::duration<Rep, Period>; using Duration = std::chrono::duration<Rep, Period>;
using CT = typename common_type<Duration, seconds>::type; using CT = typename std::common_type<Duration, std::chrono::seconds>::type;
fields<CT> fds{}; fields<CT> fds{};
from_stream(is, fmt, fds, abbrev, offset); from_stream(is, fmt, fds, abbrev, offset);
if (!fds.has_tod) if (!fds.has_tod)
is.setstate(ios::failbit); is.setstate(std::ios::failbit);
if (!is.fail()) if (!is.fail())
d = duration_cast<Duration>(fds.tod.to_duration()); d = std::chrono::duration_cast<Duration>(fds.tod.to_duration());
return is; return is;
} }
@ -7932,9 +7922,8 @@ std::basic_ostream<CharT, Traits>&
operator<<(std::basic_ostream<CharT, Traits>& os, operator<<(std::basic_ostream<CharT, Traits>& os,
const std::chrono::duration<Rep, Period>& d) const std::chrono::duration<Rep, Period>& d)
{ {
using namespace detail; return os << detail::make_string<CharT, Traits>::from(d.count()) +
return os << make_string<CharT, Traits>::from(d.count()) + detail::get_units<CharT>(typename Period::type{});
get_units<CharT>(typename Period::type{});
} }
} // namespace date } // namespace date

View File

@ -451,7 +451,7 @@ weekday::weekday(unsigned wd) NOEXCEPT
CONSTCD11 CONSTCD11
inline inline
weekday::weekday(date::weekday wd) NOEXCEPT weekday::weekday(date::weekday wd) NOEXCEPT
: wd_((wd-date::Monday).count() + 1) : wd_(wd.iso_encoding())
{} {}
CONSTCD11 CONSTCD11
@ -607,7 +607,10 @@ inline
year year
year::min() NOEXCEPT year::min() NOEXCEPT
{ {
using namespace std::chrono; using std::chrono::seconds;
using std::chrono::minutes;
using std::chrono::hours;
using std::chrono::duration_cast;
static_assert(sizeof(seconds)*CHAR_BIT >= 41, "seconds may overflow"); static_assert(sizeof(seconds)*CHAR_BIT >= 41, "seconds may overflow");
static_assert(sizeof(hours)*CHAR_BIT >= 30, "hours may overflow"); static_assert(sizeof(hours)*CHAR_BIT >= 30, "hours may overflow");
return sizeof(minutes)*CHAR_BIT < 34 ? return sizeof(minutes)*CHAR_BIT < 34 ?
@ -620,7 +623,10 @@ inline
year year
year::max() NOEXCEPT year::max() NOEXCEPT
{ {
using namespace std::chrono; using std::chrono::seconds;
using std::chrono::minutes;
using std::chrono::hours;
using std::chrono::duration_cast;
static_assert(sizeof(seconds)*CHAR_BIT >= 41, "seconds may overflow"); static_assert(sizeof(seconds)*CHAR_BIT >= 41, "seconds may overflow");
static_assert(sizeof(hours)*CHAR_BIT >= 30, "hours may overflow"); static_assert(sizeof(hours)*CHAR_BIT >= 30, "hours may overflow");
return sizeof(minutes)*CHAR_BIT < 34 ? return sizeof(minutes)*CHAR_BIT < 34 ?

View File

@ -96,7 +96,10 @@ inline
date::local_seconds date::local_seconds
rule::operator()(date::year y) const rule::operator()(date::year y) const
{ {
using namespace date; using date::local_days;
using date::January;
using date::days;
using date::last;
using sec = std::chrono::seconds; using sec = std::chrono::seconds;
date::local_seconds t; date::local_seconds t;
switch (mode_) switch (mode_)
@ -180,7 +183,9 @@ public:
inline inline
time_zone::time_zone(const detail::string_t& s) time_zone::time_zone(const detail::string_t& s)
{ {
using namespace detail; using detail::read_name;
using detail::read_signed_time;
using detail::throw_invalid;
auto i = read_name(s, 0, std_abbrev_); auto i = read_name(s, 0, std_abbrev_);
i = read_signed_time(s, i, offset_); i = read_signed_time(s, i, offset_);
offset_ = -offset_; offset_ = -offset_;
@ -212,8 +217,19 @@ template <class Duration>
date::sys_info date::sys_info
time_zone::get_info(date::sys_time<Duration> st) const time_zone::get_info(date::sys_time<Duration> st) const
{ {
using namespace date; using date::sys_info;
using namespace std::chrono; using date::year_month_day;
using date::sys_seconds;
using date::sys_days;
using date::floor;
using date::ceil;
using date::days;
using date::years;
using date::year;
using date::January;
using date::December;
using date::last;
using std::chrono::minutes;
sys_info r{}; sys_info r{};
r.offset = offset_; r.offset = offset_;
if (start_rule_.ok()) if (start_rule_.ok())
@ -256,9 +272,21 @@ template <class Duration>
date::local_info date::local_info
time_zone::get_info(date::local_time<Duration> tp) const time_zone::get_info(date::local_time<Duration> tp) const
{ {
using namespace date; using date::local_info;
using namespace std::chrono; using date::year_month_day;
using date::days;
using date::sys_days;
using date::sys_seconds;
using date::years;
using date::year;
using date::ceil;
using date::January;
using date::December;
using date::last;
using std::chrono::seconds;
using std::chrono::minutes;
local_info r{}; local_info r{};
using date::floor;
if (start_rule_.ok()) if (start_rule_.ok())
{ {
auto y = year_month_day{floor<days>(tp)}.year(); auto y = year_month_day{floor<days>(tp)}.year();
@ -335,7 +363,9 @@ template <class Duration>
date::sys_time<typename std::common_type<Duration, std::chrono::seconds>::type> date::sys_time<typename std::common_type<Duration, std::chrono::seconds>::type>
time_zone::to_sys(date::local_time<Duration> tp) const time_zone::to_sys(date::local_time<Duration> tp) const
{ {
using namespace date; using date::local_info;
using date::sys_time;
using date::ambiguous_local_time;
auto i = get_info(tp); auto i = get_info(tp);
if (i.result == local_info::nonexistent) if (i.result == local_info::nonexistent)
throw nonexistent_local_time(tp, i); throw nonexistent_local_time(tp, i);
@ -348,7 +378,9 @@ template <class Duration>
date::sys_time<typename std::common_type<Duration, std::chrono::seconds>::type> date::sys_time<typename std::common_type<Duration, std::chrono::seconds>::type>
time_zone::to_sys(date::local_time<Duration> tp, date::choose z) const time_zone::to_sys(date::local_time<Duration> tp, date::choose z) const
{ {
using namespace date; using date::local_info;
using date::sys_time;
using date::choose;
auto i = get_info(tp); auto i = get_info(tp);
if (i.result == local_info::nonexistent) if (i.result == local_info::nonexistent)
{ {
@ -366,8 +398,8 @@ template <class Duration>
date::local_time<typename std::common_type<Duration, std::chrono::seconds>::type> date::local_time<typename std::common_type<Duration, std::chrono::seconds>::type>
time_zone::to_local(date::sys_time<Duration> tp) const time_zone::to_local(date::sys_time<Duration> tp) const
{ {
using namespace date; using date::local_time;
using namespace std::chrono; using std::chrono::seconds;
using LT = local_time<typename std::common_type<Duration, seconds>::type>; using LT = local_time<typename std::common_type<Duration, seconds>::type>;
auto i = get_info(tp); auto i = get_info(tp);
return LT{(tp + i.offset).time_since_epoch()}; return LT{(tp + i.offset).time_since_epoch()};
@ -404,7 +436,8 @@ inline
unsigned unsigned
read_date(const string_t& s, unsigned i, rule& r) read_date(const string_t& s, unsigned i, rule& r)
{ {
using namespace date; using date::month;
using date::weekday;
if (i == s.size()) if (i == s.size())
throw_invalid(s, i, "Expected rule but found end of string"); throw_invalid(s, i, "Expected rule but found end of string");
if (s[i] == 'J') if (s[i] == 'J')
@ -513,7 +546,9 @@ inline
unsigned unsigned
read_unsigned_time(const string_t& s, unsigned i, std::chrono::seconds& t) read_unsigned_time(const string_t& s, unsigned i, std::chrono::seconds& t)
{ {
using namespace std::chrono; using std::chrono::seconds;
using std::chrono::minutes;
using std::chrono::hours;
if (i == s.size()) if (i == s.size())
throw_invalid(s, i, "Expected to read unsigned time, but found end of string"); throw_invalid(s, i, "Expected to read unsigned time, but found end of string");
unsigned x; unsigned x;

View File

@ -891,8 +891,7 @@ inline
sys_info sys_info
time_zone::get_info(sys_time<Duration> st) const time_zone::get_info(sys_time<Duration> st) const
{ {
using namespace std::chrono; return get_info_impl(date::floor<std::chrono::seconds>(st));
return get_info_impl(date::floor<seconds>(st));
} }
template <class Duration> template <class Duration>
@ -900,8 +899,7 @@ inline
local_info local_info
time_zone::get_info(local_time<Duration> tp) const time_zone::get_info(local_time<Duration> tp) const
{ {
using namespace std::chrono; return get_info_impl(date::floor<std::chrono::seconds>(tp));
return get_info_impl(date::floor<seconds>(tp));
} }
template <class Duration> template <class Duration>
@ -942,8 +940,6 @@ template <class Duration>
sys_time<typename std::common_type<Duration, std::chrono::seconds>::type> sys_time<typename std::common_type<Duration, std::chrono::seconds>::type>
time_zone::to_sys_impl(local_time<Duration> tp, choose z, std::false_type) const time_zone::to_sys_impl(local_time<Duration> tp, choose z, std::false_type) const
{ {
using namespace date;
using namespace std::chrono;
auto i = get_info(tp); auto i = get_info(tp);
if (i.result == local_info::nonexistent) if (i.result == local_info::nonexistent)
{ {
@ -961,8 +957,6 @@ template <class Duration>
sys_time<typename std::common_type<Duration, std::chrono::seconds>::type> sys_time<typename std::common_type<Duration, std::chrono::seconds>::type>
time_zone::to_sys_impl(local_time<Duration> tp, choose, std::true_type) const time_zone::to_sys_impl(local_time<Duration> tp, choose, std::true_type) const
{ {
using namespace date;
using namespace std::chrono;
auto i = get_info(tp); auto i = get_info(tp);
if (i.result == local_info::nonexistent) if (i.result == local_info::nonexistent)
throw nonexistent_local_time(tp, i); throw nonexistent_local_time(tp, i);
@ -1886,7 +1880,7 @@ template <class Duration>
utc_time<typename std::common_type<Duration, std::chrono::seconds>::type> utc_time<typename std::common_type<Duration, std::chrono::seconds>::type>
utc_clock::from_sys(const sys_time<Duration>& st) utc_clock::from_sys(const sys_time<Duration>& st)
{ {
using namespace std::chrono; using std::chrono::seconds;
using CD = typename std::common_type<Duration, seconds>::type; using CD = typename std::common_type<Duration, seconds>::type;
auto const& leaps = get_tzdb().leaps; auto const& leaps = get_tzdb().leaps;
auto const lt = std::upper_bound(leaps.begin(), leaps.end(), st); auto const lt = std::upper_bound(leaps.begin(), leaps.end(), st);
@ -1900,8 +1894,7 @@ template <class Duration>
std::pair<bool, std::chrono::seconds> std::pair<bool, std::chrono::seconds>
is_leap_second(date::utc_time<Duration> const& ut) is_leap_second(date::utc_time<Duration> const& ut)
{ {
using namespace date; using std::chrono::seconds;
using namespace std::chrono;
using duration = typename std::common_type<Duration, seconds>::type; using duration = typename std::common_type<Duration, seconds>::type;
auto const& leaps = get_tzdb().leaps; auto const& leaps = get_tzdb().leaps;
auto tp = sys_time<duration>{ut.time_since_epoch()}; auto tp = sys_time<duration>{ut.time_since_epoch()};
@ -1940,7 +1933,7 @@ template <class Duration>
sys_time<typename std::common_type<Duration, std::chrono::seconds>::type> sys_time<typename std::common_type<Duration, std::chrono::seconds>::type>
utc_clock::to_sys(const utc_time<Duration>& ut) utc_clock::to_sys(const utc_time<Duration>& ut)
{ {
using namespace std::chrono; using std::chrono::seconds;
using CD = typename std::common_type<Duration, seconds>::type; using CD = typename std::common_type<Duration, seconds>::type;
auto ls = is_leap_second(ut); auto ls = is_leap_second(ut);
auto tp = sys_time<CD>{ut.time_since_epoch() - ls.second}; auto tp = sys_time<CD>{ut.time_since_epoch() - ls.second};
@ -1953,8 +1946,7 @@ inline
utc_clock::time_point utc_clock::time_point
utc_clock::now() utc_clock::now()
{ {
using namespace std::chrono; return from_sys(std::chrono::system_clock::now());
return from_sys(system_clock::now());
} }
template <class Duration> template <class Duration>
@ -1977,7 +1969,7 @@ std::basic_ostream<CharT, Traits>&
to_stream(std::basic_ostream<CharT, Traits>& os, const CharT* fmt, to_stream(std::basic_ostream<CharT, Traits>& os, const CharT* fmt,
const utc_time<Duration>& t) const utc_time<Duration>& t)
{ {
using namespace std::chrono; using std::chrono::seconds;
using CT = typename std::common_type<Duration, seconds>::type; using CT = typename std::common_type<Duration, seconds>::type;
const std::string abbrev("UTC"); const std::string abbrev("UTC");
CONSTDATA seconds offset{0}; CONSTDATA seconds offset{0};
@ -2005,7 +1997,8 @@ from_stream(std::basic_istream<CharT, Traits>& is, const CharT* fmt,
utc_time<Duration>& tp, std::basic_string<CharT, Traits, Alloc>* abbrev = nullptr, utc_time<Duration>& tp, std::basic_string<CharT, Traits, Alloc>* abbrev = nullptr,
std::chrono::minutes* offset = nullptr) std::chrono::minutes* offset = nullptr)
{ {
using namespace std::chrono; using std::chrono::seconds;
using std::chrono::minutes;
using CT = typename std::common_type<Duration, seconds>::type; using CT = typename std::common_type<Duration, seconds>::type;
minutes offset_local{}; minutes offset_local{};
auto offptr = offset ? offset : &offset_local; auto offptr = offset ? offset : &offset_local;
@ -2027,7 +2020,7 @@ from_stream(std::basic_istream<CharT, Traits>& is, const CharT* fmt,
is.setstate(std::ios::failbit); is.setstate(std::ios::failbit);
return is; return is;
} }
tp = time_point_cast<Duration>(tmp); tp = std::chrono::time_point_cast<Duration>(tmp);
} }
return is; return is;
} }
@ -2076,7 +2069,7 @@ inline
utc_time<typename std::common_type<Duration, std::chrono::seconds>::type> utc_time<typename std::common_type<Duration, std::chrono::seconds>::type>
tai_clock::to_utc(const tai_time<Duration>& t) NOEXCEPT tai_clock::to_utc(const tai_time<Duration>& t) NOEXCEPT
{ {
using namespace std::chrono; using std::chrono::seconds;
using CD = typename std::common_type<Duration, seconds>::type; using CD = typename std::common_type<Duration, seconds>::type;
return utc_time<CD>{t.time_since_epoch()} - return utc_time<CD>{t.time_since_epoch()} -
(sys_days(year{1970}/January/1) - sys_days(year{1958}/January/1) + seconds{10}); (sys_days(year{1970}/January/1) - sys_days(year{1958}/January/1) + seconds{10});
@ -2087,7 +2080,7 @@ inline
tai_time<typename std::common_type<Duration, std::chrono::seconds>::type> tai_time<typename std::common_type<Duration, std::chrono::seconds>::type>
tai_clock::from_utc(const utc_time<Duration>& t) NOEXCEPT tai_clock::from_utc(const utc_time<Duration>& t) NOEXCEPT
{ {
using namespace std::chrono; using std::chrono::seconds;
using CD = typename std::common_type<Duration, seconds>::type; using CD = typename std::common_type<Duration, seconds>::type;
return tai_time<CD>{t.time_since_epoch()} + return tai_time<CD>{t.time_since_epoch()} +
(sys_days(year{1970}/January/1) - sys_days(year{1958}/January/1) + seconds{10}); (sys_days(year{1970}/January/1) - sys_days(year{1958}/January/1) + seconds{10});
@ -2097,7 +2090,6 @@ inline
tai_clock::time_point tai_clock::time_point
tai_clock::now() tai_clock::now()
{ {
using namespace std::chrono;
return from_utc(utc_clock::now()); return from_utc(utc_clock::now());
} }
@ -2197,7 +2189,7 @@ inline
utc_time<typename std::common_type<Duration, std::chrono::seconds>::type> utc_time<typename std::common_type<Duration, std::chrono::seconds>::type>
gps_clock::to_utc(const gps_time<Duration>& t) NOEXCEPT gps_clock::to_utc(const gps_time<Duration>& t) NOEXCEPT
{ {
using namespace std::chrono; using std::chrono::seconds;
using CD = typename std::common_type<Duration, seconds>::type; using CD = typename std::common_type<Duration, seconds>::type;
return utc_time<CD>{t.time_since_epoch()} + return utc_time<CD>{t.time_since_epoch()} +
(sys_days(year{1980}/January/Sunday[1]) - sys_days(year{1970}/January/1) + (sys_days(year{1980}/January/Sunday[1]) - sys_days(year{1970}/January/1) +
@ -2209,7 +2201,7 @@ inline
gps_time<typename std::common_type<Duration, std::chrono::seconds>::type> gps_time<typename std::common_type<Duration, std::chrono::seconds>::type>
gps_clock::from_utc(const utc_time<Duration>& t) NOEXCEPT gps_clock::from_utc(const utc_time<Duration>& t) NOEXCEPT
{ {
using namespace std::chrono; using std::chrono::seconds;
using CD = typename std::common_type<Duration, seconds>::type; using CD = typename std::common_type<Duration, seconds>::type;
return gps_time<CD>{t.time_since_epoch()} - return gps_time<CD>{t.time_since_epoch()} -
(sys_days(year{1980}/January/Sunday[1]) - sys_days(year{1970}/January/1) + (sys_days(year{1980}/January/Sunday[1]) - sys_days(year{1970}/January/1) +
@ -2220,7 +2212,6 @@ inline
gps_clock::time_point gps_clock::time_point
gps_clock::now() gps_clock::now()
{ {
using namespace std::chrono;
return from_utc(utc_clock::now()); return from_utc(utc_clock::now());
} }

View File

@ -289,11 +289,9 @@ struct transition
std::ostream& std::ostream&
operator<<(std::ostream& os, const transition& t) operator<<(std::ostream& os, const transition& t)
{ {
using namespace date;
using namespace std::chrono;
using date::operator<<; using date::operator<<;
os << t.timepoint << "Z "; os << t.timepoint << "Z ";
if (t.info->offset >= seconds{0}) if (t.info->offset >= std::chrono::seconds{0})
os << '+'; os << '+';
os << make_time(t.info->offset); os << make_time(t.info->offset);
if (t.info->is_dst > 0) if (t.info->is_dst > 0)