Update time_of_day to be more consistent ...

the needs of formatting.
This commit is contained in:
Howard Hinnant 2019-02-02 14:06:12 -05:00
parent f1326968af
commit 9cb0013aef
11 changed files with 184 additions and 689 deletions

View File

@ -3652,11 +3652,11 @@ from_stream(std::basic_istream<CharT, Traits>& is, const CharT* fmt,
// time_of_day
enum {am = 1, pm};
namespace detail
{
struct undocumented {explicit undocumented() = default;};
// width<n>::value is the number of fractional decimal digits in 1/n
// width<0>::value and width<1>::value are defined to be 0
// If 1/n takes more than 18 fractional decimal digits,
@ -3709,16 +3709,16 @@ struct make_precision<Rep, w, false>
static CONSTDATA unsigned width = 6;
};
template <class Duration,
unsigned w = width<std::common_type<
Duration,
std::chrono::seconds>::type::period::den>::value>
template <class Duration>
class decimal_format_seconds
{
using CT = typename std::common_type<Duration, std::chrono::seconds>::type;
using rep = typename CT::rep;
public:
using rep = typename std::common_type<Duration, std::chrono::seconds>::type::rep;
using precision = typename make_precision<rep, w>::type;
static auto CONSTDATA width = make_precision<rep, w>::width;
static unsigned constexpr width = detail::width<CT::period::den>::value < 19 ?
detail::width<CT::period::den>::value : 6u;
using precision = std::chrono::duration<rep,
std::ratio<1, static_pow10<width>::value>>;
private:
std::chrono::seconds s_;
@ -3759,25 +3759,27 @@ public:
os.fill('0');
os.flags(std::ios::dec | std::ios::right);
os.width(2);
os << x.s_.count() <<
std::use_facet<std::numpunct<char>>(os.getloc()).decimal_point();
os.width(width);
os << static_cast<std::int64_t>(x.sub_s_.count());
os << x.s_.count();
if (width > 0)
{
os << std::use_facet<std::numpunct<CharT>>(os.getloc()).decimal_point();
os.width(width);
os << static_cast<std::int64_t>(x.sub_s_.count());
}
return os;
}
};
template <class Duration>
class decimal_format_seconds<Duration, 0>
template <class Rep>
class decimal_format_seconds<std::chrono::duration<Rep>>
{
static CONSTDATA unsigned w = 0;
public:
using rep = typename std::common_type<Duration, std::chrono::seconds>::type::rep;
using precision = std::chrono::duration<rep>;
static auto CONSTDATA width = make_precision<rep, w>::width;
static unsigned constexpr width = 0u;
using precision = std::chrono::duration<Rep>;
private:
std::chrono::seconds s_;
precision s_;
public:
CONSTCD11 decimal_format_seconds() : s_() {}
@ -3800,39 +3802,13 @@ public:
std::basic_ostream<CharT, Traits>&
operator<<(std::basic_ostream<CharT, Traits>& os, const decimal_format_seconds& x)
{
date::detail::save_ostream<CharT, Traits> _(os);
os.fill('0');
os.flags(std::ios::dec | std::ios::right);
os.width(2);
if (x.s_ < std::chrono::seconds{10})
os << '0';
os << x.s_.count();
return os;
}
};
enum class classify
{
not_valid,
hour,
minute,
second,
subsecond
};
template <class Duration>
struct classify_duration
{
static CONSTDATA classify value =
std::is_convertible<Duration, std::chrono::hours>::value
? classify::hour :
std::is_convertible<Duration, std::chrono::minutes>::value
? classify::minute :
std::is_convertible<Duration, std::chrono::seconds>::value
? classify::second :
std::chrono::treat_as_floating_point<typename Duration::rep>::value
? classify::not_valid :
classify::subsecond;
};
template <class Rep, class Period>
inline
CONSTCD11
@ -3859,490 +3835,160 @@ abs(std::chrono::duration<Rep, Period> d)
return d;
}
class time_of_day_base
{
protected:
std::chrono::hours h_;
unsigned char mode_;
bool neg_;
enum {is24hr};
CONSTCD11 time_of_day_base() NOEXCEPT
: h_(0)
, mode_(static_cast<decltype(mode_)>(is24hr))
, neg_(false)
{}
CONSTCD11 time_of_day_base(std::chrono::hours h, bool neg, unsigned m) NOEXCEPT
: h_(detail::abs(h))
, mode_(static_cast<decltype(mode_)>(m))
, neg_(neg)
{}
CONSTCD14 void make24() NOEXCEPT;
CONSTCD14 void make12() NOEXCEPT;
CONSTCD14 std::chrono::hours to24hr() const;
CONSTCD11 bool in_conventional_range() const NOEXCEPT
{
return !neg_ && h_ < days{1};
}
};
CONSTCD14
inline
std::chrono::hours
time_of_day_base::to24hr() const
{
auto h = h_;
if (mode_ == am || mode_ == pm)
{
CONSTDATA auto h12 = std::chrono::hours(12);
if (mode_ == pm)
{
if (h != h12)
h = h + h12;
}
else if (h == h12)
h = std::chrono::hours(0);
}
return h;
}
CONSTCD14
inline
void
time_of_day_base::make24() NOEXCEPT
{
h_ = to24hr();
mode_ = is24hr;
}
CONSTCD14
inline
void
time_of_day_base::make12() NOEXCEPT
{
if (mode_ == is24hr)
{
CONSTDATA auto h12 = std::chrono::hours(12);
if (h_ >= h12)
{
if (h_ > h12)
h_ = h_ - h12;
mode_ = pm;
}
else
{
if (h_ == std::chrono::hours(0))
h_ = h12;
mode_ = am;
}
}
}
template <class Duration, detail::classify = detail::classify_duration<Duration>::value>
class time_of_day_storage;
template <class Rep, class Period>
class time_of_day_storage<std::chrono::duration<Rep, Period>, detail::classify::hour>
: private detail::time_of_day_base
{
using base = detail::time_of_day_base;
public:
using precision = std::chrono::hours;
#if !defined(_MSC_VER) || _MSC_VER >= 1900
CONSTCD11 time_of_day_storage() NOEXCEPT = default;
#else
CONSTCD11 time_of_day_storage() = default;
#endif /* !defined(_MSC_VER) || _MSC_VER >= 1900 */
CONSTCD11 explicit time_of_day_storage(std::chrono::hours since_midnight) NOEXCEPT
: base(since_midnight, since_midnight < std::chrono::hours{0}, is24hr)
{}
CONSTCD11 explicit time_of_day_storage(std::chrono::hours h, unsigned md) NOEXCEPT
: base(h, h < std::chrono::hours{0}, md)
{}
CONSTCD11 std::chrono::hours hours() const NOEXCEPT {return h_;}
CONSTCD11 unsigned mode() const NOEXCEPT {return mode_;}
CONSTCD14 explicit operator precision() const NOEXCEPT
{
auto p = to24hr();
if (neg_)
p = -p;
return p;
}
CONSTCD14 precision to_duration() const NOEXCEPT
{
return static_cast<precision>(*this);
}
CONSTCD14 time_of_day_storage& make24() NOEXCEPT {base::make24(); return *this;}
CONSTCD14 time_of_day_storage& make12() NOEXCEPT {base::make12(); return *this;}
CONSTCD11 bool in_conventional_range() const NOEXCEPT
{
return base::in_conventional_range();
}
template<class CharT, class Traits>
friend
std::basic_ostream<CharT, Traits>&
operator<<(std::basic_ostream<CharT, Traits>& os, const time_of_day_storage& t)
{
using namespace std;
detail::save_ostream<CharT, Traits> _(os);
if (t.neg_)
os << '-';
os.fill('0');
os.flags(std::ios::dec | std::ios::right);
if (t.mode_ != am && t.mode_ != pm)
os.width(2);
os << t.h_.count();
switch (t.mode_)
{
case time_of_day_storage::is24hr:
os << "00";
break;
case am:
os << "am";
break;
case pm:
os << "pm";
break;
}
return os;
}
};
template <class Rep, class Period>
class time_of_day_storage<std::chrono::duration<Rep, Period>, detail::classify::minute>
: private detail::time_of_day_base
{
using base = detail::time_of_day_base;
std::chrono::minutes m_;
public:
using precision = std::chrono::minutes;
CONSTCD11 time_of_day_storage() NOEXCEPT
: base()
, m_(0)
{}
CONSTCD11 explicit time_of_day_storage(std::chrono::minutes since_midnight) NOEXCEPT
: base(std::chrono::duration_cast<std::chrono::hours>(since_midnight),
since_midnight < std::chrono::minutes{0}, is24hr)
, m_(detail::abs(since_midnight) - h_)
{}
CONSTCD11 explicit time_of_day_storage(std::chrono::hours h, std::chrono::minutes m,
unsigned md) NOEXCEPT
: base(h, false, md)
, m_(m)
{}
CONSTCD11 std::chrono::hours hours() const NOEXCEPT {return h_;}
CONSTCD11 std::chrono::minutes minutes() const NOEXCEPT {return m_;}
CONSTCD11 unsigned mode() const NOEXCEPT {return mode_;}
CONSTCD14 explicit operator precision() const NOEXCEPT
{
auto p = to24hr() + m_;
if (neg_)
p = -p;
return p;
}
CONSTCD14 precision to_duration() const NOEXCEPT
{
return static_cast<precision>(*this);
}
CONSTCD14 time_of_day_storage& make24() NOEXCEPT {base::make24(); return *this;}
CONSTCD14 time_of_day_storage& make12() NOEXCEPT {base::make12(); return *this;}
CONSTCD11 bool in_conventional_range() const NOEXCEPT
{
return base::in_conventional_range() && m_ < std::chrono::hours{1};
}
template<class CharT, class Traits>
friend
std::basic_ostream<CharT, Traits>&
operator<<(std::basic_ostream<CharT, Traits>& os, const time_of_day_storage& t)
{
using namespace std;
detail::save_ostream<CharT, Traits> _(os);
if (t.neg_)
os << '-';
os.fill('0');
os.flags(std::ios::dec | std::ios::right);
if (t.mode_ != am && t.mode_ != pm)
os.width(2);
os << t.h_.count() << ':';
os.width(2);
os << t.m_.count();
switch (t.mode_)
{
case am:
os << "am";
break;
case pm:
os << "pm";
break;
}
return os;
}
};
template <class Rep, class Period>
class time_of_day_storage<std::chrono::duration<Rep, Period>, detail::classify::second>
: private detail::time_of_day_base
{
using base = detail::time_of_day_base;
using dfs = decimal_format_seconds<std::chrono::seconds>;
std::chrono::minutes m_;
dfs s_;
public:
using precision = std::chrono::seconds;
CONSTCD11 time_of_day_storage() NOEXCEPT
: base()
, m_(0)
, s_()
{}
CONSTCD11 explicit time_of_day_storage(std::chrono::seconds since_midnight) NOEXCEPT
: base(std::chrono::duration_cast<std::chrono::hours>(since_midnight),
since_midnight < std::chrono::seconds{0}, is24hr)
, m_(std::chrono::duration_cast<std::chrono::minutes>(detail::abs(since_midnight) - h_))
, s_(detail::abs(since_midnight) - h_ - m_)
{}
CONSTCD11 explicit time_of_day_storage(std::chrono::hours h, std::chrono::minutes m,
std::chrono::seconds s, unsigned md) NOEXCEPT
: base(h, false, md)
, m_(m)
, s_(s)
{}
CONSTCD11 std::chrono::hours hours() const NOEXCEPT {return h_;}
CONSTCD11 std::chrono::minutes minutes() const NOEXCEPT {return m_;}
CONSTCD14 std::chrono::seconds& seconds() NOEXCEPT {return s_.seconds();}
CONSTCD11 std::chrono::seconds seconds() const NOEXCEPT {return s_.seconds();}
CONSTCD11 unsigned mode() const NOEXCEPT {return mode_;}
CONSTCD14 explicit operator precision() const NOEXCEPT
{
auto p = to24hr() + s_.to_duration() + m_;
if (neg_)
p = -p;
return p;
}
CONSTCD14 precision to_duration() const NOEXCEPT
{
return static_cast<precision>(*this);
}
CONSTCD14 time_of_day_storage& make24() NOEXCEPT {base::make24(); return *this;}
CONSTCD14 time_of_day_storage& make12() NOEXCEPT {base::make12(); return *this;}
CONSTCD11 bool in_conventional_range() const NOEXCEPT
{
return base::in_conventional_range() && m_ < std::chrono::hours{1} &&
s_.in_conventional_range();
}
template<class CharT, class Traits>
friend
std::basic_ostream<CharT, Traits>&
operator<<(std::basic_ostream<CharT, Traits>& os, const time_of_day_storage& t)
{
using namespace std;
detail::save_ostream<CharT, Traits> _(os);
if (t.neg_)
os << '-';
os.fill('0');
os.flags(std::ios::dec | std::ios::right);
if (t.mode_ != am && t.mode_ != pm)
os.width(2);
os << t.h_.count() << ':';
os.width(2);
os << t.m_.count() << ':' << t.s_;
switch (t.mode_)
{
case am:
os << "am";
break;
case pm:
os << "pm";
break;
}
return os;
}
template <class CharT, class Traits, class Duration>
friend
std::basic_ostream<CharT, Traits>&
date::to_stream(std::basic_ostream<CharT, Traits>& os, const CharT* fmt,
const fields<Duration>& fds, const std::string* abbrev,
const std::chrono::seconds* offset_sec);
template <class CharT, class Traits, class Duration, class Alloc>
friend
std::basic_istream<CharT, Traits>&
date::from_stream(std::basic_istream<CharT, Traits>& is, const CharT* fmt,
fields<Duration>& fds,
std::basic_string<CharT, Traits, Alloc>* abbrev, std::chrono::minutes* offset);
};
template <class Rep, class Period>
class time_of_day_storage<std::chrono::duration<Rep, Period>, detail::classify::subsecond>
: private detail::time_of_day_base
{
public:
using Duration = std::chrono::duration<Rep, Period>;
using dfs = decimal_format_seconds<typename std::common_type<Duration,
std::chrono::seconds>::type>;
using precision = typename dfs::precision;
private:
using base = detail::time_of_day_base;
std::chrono::minutes m_;
dfs s_;
public:
CONSTCD11 time_of_day_storage() NOEXCEPT
: base()
, m_(0)
, s_()
{}
CONSTCD11 explicit time_of_day_storage(Duration since_midnight) NOEXCEPT
: base(date::trunc<std::chrono::hours>(since_midnight),
since_midnight < Duration{0}, is24hr)
, m_(date::trunc<std::chrono::minutes>(detail::abs(since_midnight) - h_))
, s_(detail::abs(since_midnight) - h_ - m_)
{}
CONSTCD11 explicit time_of_day_storage(std::chrono::hours h, std::chrono::minutes m,
std::chrono::seconds s, precision sub_s,
unsigned md) NOEXCEPT
: base(h, false, md)
, m_(m)
, s_(s + sub_s)
{}
CONSTCD11 std::chrono::hours hours() const NOEXCEPT {return h_;}
CONSTCD11 std::chrono::minutes minutes() const NOEXCEPT {return m_;}
CONSTCD14 std::chrono::seconds& seconds() NOEXCEPT {return s_.seconds();}
CONSTCD11 std::chrono::seconds seconds() const NOEXCEPT {return s_.seconds();}
CONSTCD11 precision subseconds() const NOEXCEPT {return s_.subseconds();}
CONSTCD11 unsigned mode() const NOEXCEPT {return mode_;}
CONSTCD14 explicit operator precision() const NOEXCEPT
{
auto p = to24hr() + s_.to_duration() + m_;
if (neg_)
p = -p;
return p;
}
CONSTCD14 precision to_duration() const NOEXCEPT
{
return static_cast<precision>(*this);
}
CONSTCD14 time_of_day_storage& make24() NOEXCEPT {base::make24(); return *this;}
CONSTCD14 time_of_day_storage& make12() NOEXCEPT {base::make12(); return *this;}
CONSTCD11 bool in_conventional_range() const NOEXCEPT
{
return base::in_conventional_range() && m_ < std::chrono::hours{1} &&
s_.in_conventional_range();
}
template<class CharT, class Traits>
friend
std::basic_ostream<CharT, Traits>&
operator<<(std::basic_ostream<CharT, Traits>& os, const time_of_day_storage& t)
{
using namespace std;
detail::save_ostream<CharT, Traits> _(os);
if (t.neg_)
os << '-';
os.fill('0');
os.flags(std::ios::dec | std::ios::right);
if (t.mode_ != am && t.mode_ != pm)
os.width(2);
os << t.h_.count() << ':';
os.width(2);
os << t.m_.count() << ':' << t.s_;
switch (t.mode_)
{
case am:
os << "am";
break;
case pm:
os << "pm";
break;
}
return os;
}
template <class CharT, class Traits, class Duration>
friend
std::basic_ostream<CharT, Traits>&
date::to_stream(std::basic_ostream<CharT, Traits>& os, const CharT* fmt,
const fields<Duration>& fds, const std::string* abbrev,
const std::chrono::seconds* offset_sec);
template <class CharT, class Traits, class Duration, class Alloc>
friend
std::basic_istream<CharT, Traits>&
date::from_stream(std::basic_istream<CharT, Traits>& is, const CharT* fmt,
fields<Duration>& fds,
std::basic_string<CharT, Traits, Alloc>* abbrev, std::chrono::minutes* offset);
};
} // namespace detail
template <class Duration>
class time_of_day
: public detail::time_of_day_storage<Duration>
{
using base = detail::time_of_day_storage<Duration>;
using dfs = detail::decimal_format_seconds<typename std::common_type<Duration,
std::chrono::seconds>::type>;
enum state {is_24, am, pm};
std::chrono::hours h_;
std::chrono::minutes m_;
dfs s_;
bool neg_;
state mode_ = is_24;
public:
#if !defined(_MSC_VER) || _MSC_VER >= 1900
CONSTCD11 time_of_day() NOEXCEPT = default;
#else
using precision = typename dfs::precision;
CONSTCD11 time_of_day() = default;
#endif /* !defined(_MSC_VER) || _MSC_VER >= 1900 */
CONSTCD11 explicit time_of_day(Duration since_midnight) NOEXCEPT
: base(since_midnight)
CONSTCD11 explicit time_of_day(Duration d) NOEXCEPT
: h_(std::chrono::duration_cast<std::chrono::hours>(detail::abs(d)))
, m_(std::chrono::duration_cast<std::chrono::minutes>(detail::abs(d)) - h_)
, s_(detail::abs(d) - h_ - m_)
, neg_(d < precision{})
{}
template <class Arg0, class Arg1, class ...Args>
CONSTCD11
explicit time_of_day(Arg0&& arg0, Arg1&& arg1, Args&& ...args) NOEXCEPT
: base(std::forward<Arg0>(arg0), std::forward<Arg1>(arg1), std::forward<Args>(args)...)
{}
CONSTCD11 std::chrono::hours hours() const NOEXCEPT {return h_;}
CONSTCD11 std::chrono::minutes minutes() const NOEXCEPT {return m_;}
CONSTCD11 std::chrono::seconds seconds() const NOEXCEPT {return s_.seconds();}
CONSTCD11 std::chrono::seconds&
seconds(detail::undocumented) NOEXCEPT {return s_.seconds();}
CONSTCD11 precision subseconds() const NOEXCEPT {return s_.subseconds();}
CONSTCD11 explicit operator precision() const NOEXCEPT {return to_duration();}
CONSTCD11 precision to_duration() const NOEXCEPT
{return (make_24(mode_, h_) + m_ + s_.to_duration()) * (1-2*neg_);}
CONSTCD14 void make24() NOEXCEPT
{
h_ = make_24(mode_, h_);
mode_ = is_24;
}
CONSTCD14 void make12() NOEXCEPT {make_12(mode_, h_);}
CONSTCD11 bool in_conventional_range() const NOEXCEPT
{
using namespace std;
return !neg_ && h_ < days{1} && m_ < chrono::hours{1} &&
s_.in_conventional_range();
}
private:
CONSTCD14
static
std::chrono::hours
make_24(state mode, std::chrono::hours h) NOEXCEPT
{
using namespace std;
if (mode != is_24)
{
if (mode == am)
{
if (h == chrono::hours{12})
h = chrono::hours{0};
}
else
{
if (h != chrono::hours{12})
h += chrono::hours{12};
}
}
return h;
}
CONSTCD14
static
void
make_12(state& mode, std::chrono::hours& h) NOEXCEPT
{
using namespace std;
if (mode == is_24)
{
if (h < chrono::hours{12})
{
if (h == chrono::hours{0})
h = chrono::hours{12};
mode = am;
}
else
{
if (h != chrono::hours{12})
h -= chrono::hours{12};
mode = pm;
}
}
}
template <class charT, class traits>
friend
std::basic_ostream<charT, traits>&
operator<<(std::basic_ostream<charT, traits>& os, time_of_day const& tod)
{
using namespace detail;
using namespace std;
if (tod.neg_)
os << '-';
if (tod.mode_ == is_24)
{
if (tod.h_ < chrono::hours{10})
os << '0';
os << tod.h_.count() << ':';
if (tod.m_ < chrono::minutes{10})
os << '0';
os << tod.m_.count() << ':' << tod.s_;
}
else
{
os << tod.h_.count() << ':';
if (tod.m_ < chrono::minutes{10})
os << '0';
os << tod.m_.count() << ':' << tod.s_;
#if !ONLY_C_LOCALE
std::tm tm{};
tm.tm_hour = tod.make_24(tod.mode_, tod.h_).count();
auto& facet = use_facet<time_put<charT>>(os.getloc());
const charT f[] = {'%', 'p'};
facet.put(os, os, os.fill(), &tm, f, f+2);
#else
if (tod.mode_ == am)
os << 'A';
else
os << 'P';
os << 'M';
#endif
}
return os;
}
template <class CharT, class Traits, class Duration2>
friend
std::basic_ostream<CharT, Traits>&
date::to_stream(std::basic_ostream<CharT, Traits>& os, const CharT* fmt,
const fields<Duration2>& fds, const std::string* abbrev,
const std::chrono::seconds* offset_sec);
template <class CharT, class Traits, class Duration2, class Alloc>
friend
std::basic_istream<CharT, Traits>&
date::from_stream(std::basic_istream<CharT, Traits>& is, const CharT* fmt,
fields<Duration2>& fds,
std::basic_string<CharT, Traits, Alloc>* abbrev, std::chrono::minutes* offset);
};
template <class Rep, class Period,
@ -4356,45 +4002,6 @@ make_time(const std::chrono::duration<Rep, Period>& d)
return time_of_day<std::chrono::duration<Rep, Period>>(d);
}
CONSTCD11
inline
time_of_day<std::chrono::hours>
make_time(const std::chrono::hours& h, unsigned md)
{
return time_of_day<std::chrono::hours>(h, md);
}
CONSTCD11
inline
time_of_day<std::chrono::minutes>
make_time(const std::chrono::hours& h, const std::chrono::minutes& m,
unsigned md)
{
return time_of_day<std::chrono::minutes>(h, m, md);
}
CONSTCD11
inline
time_of_day<std::chrono::seconds>
make_time(const std::chrono::hours& h, const std::chrono::minutes& m,
const std::chrono::seconds& s, unsigned md)
{
return time_of_day<std::chrono::seconds>(h, m, s, md);
}
template <class Rep, class Period,
class = typename std::enable_if<std::ratio_less<Period,
std::ratio<1>>::value>::type>
CONSTCD11
inline
time_of_day<std::chrono::duration<Rep, Period>>
make_time(const std::chrono::hours& h, const std::chrono::minutes& m,
const std::chrono::seconds& s, const std::chrono::duration<Rep, Period>& sub_s,
unsigned md)
{
return time_of_day<std::chrono::duration<Rep, Period>>(h, m, s, sub_s, md);
}
template <class CharT, class Traits, class Duration>
inline
typename std::enable_if

View File

@ -1972,7 +1972,7 @@ to_stream(std::basic_ostream<CharT, Traits>& os, const CharT* fmt,
auto const sd = floor<days>(tp);
year_month_day ymd = sd;
auto time = make_time(tp - sys_seconds{sd});
time.seconds() += seconds{ls.first};
time.seconds(detail::undocumented{}) += seconds{ls.first};
fields<CT> fds{ymd, time};
return to_stream(os, fmt, fds, &abbrev, &offset);
}
@ -2004,7 +2004,7 @@ from_stream(std::basic_istream<CharT, Traits>& is, const CharT* fmt,
{
bool is_60_sec = fds.tod.seconds() == seconds{60};
if (is_60_sec)
fds.tod.seconds() -= seconds{1};
fds.tod.seconds(detail::undocumented{}) -= seconds{1};
auto tmp = utc_clock::from_sys(sys_days(fds.ymd) - *offptr + fds.tod.to_duration());
if (is_60_sec)
tmp += seconds{1};

View File

@ -393,11 +393,6 @@ get_tz_dir()
// | End Configuration |
// +-------------------+
namespace detail
{
struct undocumented {explicit undocumented() = default;};
}
#ifndef _MSC_VER
static_assert(min_year <= max_year, "Configuration error");
#endif

View File

@ -94,7 +94,6 @@ main()
{
using D = decimal_format_seconds<milliseconds>;
static_assert(D::width == 3, "");
static_assert(is_same<D::precision, make_precision<D::rep, D::width>::type>{}, "");
D dfs{seconds{3}};
assert(dfs.seconds() == seconds{3});
assert(dfs.to_duration() == seconds{3});
@ -106,7 +105,6 @@ main()
{
using D = decimal_format_seconds<milliseconds>;
static_assert(D::width == 3, "");
static_assert(is_same<D::precision, make_precision<D::rep, D::width>::type>{}, "");
D dfs{milliseconds{3}};
assert(dfs.seconds() == seconds{0});
assert(dfs.to_duration() == milliseconds{3});
@ -118,9 +116,8 @@ main()
{
using D = decimal_format_seconds<microfortnights>;
static_assert(D::width == 4, "");
using S = make_precision<D::rep, D::width>::type;
static_assert(is_same<D::precision, S>{}, "");
D dfs{microfortnights{3}};
using S = D::precision;
assert(dfs.seconds() == seconds{3});
assert(dfs.to_duration() == S{36288});
assert(dfs.subseconds() == S{6288});
@ -132,9 +129,8 @@ main()
using CT = common_type<seconds, microfortnights>::type;
using D = decimal_format_seconds<CT>;
static_assert(D::width == 4, "");
using S = make_precision<D::rep, D::width>::type;
static_assert(is_same<D::precision, S>{}, "");
D dfs{microfortnights{3}};
using S = D::precision;
assert(dfs.seconds() == seconds{3});
assert(dfs.to_duration() == S{36288});
assert(dfs.subseconds() == S{6288});

View File

@ -27,27 +27,6 @@
// time_of_day<std::chrono::duration<Rep, Period>>
// make_time(std::chrono::duration<Rep, Period> d) noexcept;
// constexpr
// time_of_day<std::chrono::hours>
// make_time(std::chrono::hours h, unsigned md) noexcept;
// constexpr
// time_of_day<std::chrono::minutes>
// make_time(std::chrono::hours h, std::chrono::minutes m, unsigned md) noexcept;
// constexpr
// time_of_day<std::chrono::seconds>
// make_time(std::chrono::hours h, std::chrono::minutes m, std::chrono::seconds s,
// unsigned md) noexcept;
// template <class Rep, class Period,
// class = typename std::enable_if<std::ratio_less<Period,
// std::ratio<1>>::value>::type>
// constexpr
// time_of_day<std::chrono::duration<Rep, Period>>
// make_time(std::chrono::hours h, std::chrono::minutes m, std::chrono::seconds s,
// std::chrono::duration<Rep, Period> sub_s, unsigned md) noexcept;
#include "date.h"
#include <cassert>
@ -68,7 +47,6 @@ main()
assert(tod.minutes() == minutes{7});
assert(tod.seconds() == seconds{9});
assert(tod.subseconds() == nanoseconds{22});
assert(tod.mode() == 0);
}
{
static_assert(is_same<decltype(make_time(microseconds{18429000022})),
@ -78,7 +56,6 @@ main()
assert(tod.minutes() == minutes{7});
assert(tod.seconds() == seconds{9});
assert(tod.subseconds() == microseconds{22});
assert(tod.mode() == 0);
}
{
static_assert(is_same<decltype(make_time(seconds{18429})),
@ -87,7 +64,6 @@ main()
assert(tod.hours() == hours{5});
assert(tod.minutes() == minutes{7});
assert(tod.seconds() == seconds{9});
assert(tod.mode() == 0);
}
{
static_assert(is_same<decltype(make_time(minutes{307})),
@ -95,70 +71,11 @@ main()
auto tod = make_time(minutes{307});
assert(tod.hours() == hours{5});
assert(tod.minutes() == minutes{7});
assert(tod.mode() == 0);
}
{
static_assert(is_same<decltype(make_time(hours{5})),
time_of_day<hours>>{}, "");
auto tod = make_time(hours{5});
assert(tod.hours() == hours{5});
assert(tod.mode() == 0);
}
{
static_assert(is_same<decltype(make_time(hours{5}, minutes{7}, seconds{9},
nanoseconds{22}, pm)),
time_of_day<nanoseconds>>{}, "");
auto tod = make_time(hours{5}, minutes{7}, seconds{9}, nanoseconds{22}, pm);
assert(tod.hours() == hours{5});
assert(tod.minutes() == minutes{7});
assert(tod.seconds() == seconds{9});
assert(tod.subseconds() == nanoseconds{22});
assert(tod.mode() == pm);
}
{
static_assert(is_same<decltype(make_time(hours{5}, minutes{7}, seconds{9},
microseconds{22}, 0)),
time_of_day<microseconds>>{}, "");
auto tod = make_time(hours{5}, minutes{7}, seconds{9}, microseconds{22}, 0);
assert(tod.hours() == hours{5});
assert(tod.minutes() == minutes{7});
assert(tod.seconds() == seconds{9});
assert(tod.subseconds() == microseconds{22});
assert(tod.mode() == 0);
}
{
static_assert(is_same<decltype(make_time(hours{5}, minutes{7}, seconds{9},
milliseconds{22}, am)),
time_of_day<milliseconds>>{}, "");
auto tod = make_time(hours{5}, minutes{7}, seconds{9}, milliseconds{22}, am);
assert(tod.hours() == hours{5});
assert(tod.minutes() == minutes{7});
assert(tod.seconds() == seconds{9});
assert(tod.subseconds() == milliseconds{22});
assert(tod.mode() == am);
}
{
static_assert(is_same<decltype(make_time(hours{5}, minutes{7}, seconds{9}, am)),
time_of_day<seconds>>{}, "");
auto tod = make_time(hours{5}, minutes{7}, seconds{9}, am);
assert(tod.hours() == hours{5});
assert(tod.minutes() == minutes{7});
assert(tod.seconds() == seconds{9});
assert(tod.mode() == am);
}
{
static_assert(is_same<decltype(make_time(hours{5}, minutes{7}, pm)),
time_of_day<minutes>>{}, "");
auto tod = make_time(hours{5}, minutes{7}, pm);
assert(tod.hours() == hours{5});
assert(tod.minutes() == minutes{7});
assert(tod.mode() == pm);
}
{
static_assert(is_same<decltype(make_time(hours{5}, 0)),
time_of_day<hours>>{}, "");
auto tod = make_time(hours{5}, 0);
assert(tod.hours() == hours{5});
assert(tod.mode() == 0);
}
}

View File

@ -57,7 +57,7 @@ main()
using tod = time_of_day<hours>;
static_assert(is_same<tod::precision::period, hours::period>{}, "");
static_assert(is_same<tod::precision::period, seconds::period>{}, "");
static_assert( is_trivially_destructible<tod>{}, "");
static_assert( is_default_constructible<tod>{}, "");
@ -74,7 +74,6 @@ main()
constexpr tod t1 = tod{hours{13}};
static_assert(t1.hours() == hours{13}, "");
static_assert(t1.mode() == 0, "");
#if __cplusplus >= 201402
static_assert(static_cast<tod::precision>(t1) == hours{13}, "");
static_assert(t1.to_duration() == hours{13}, "");
@ -82,23 +81,20 @@ main()
auto t2 = t1;
assert(t2.hours() == t1.hours());
assert(t2.mode() == t1.mode());
assert(t2.to_duration() == t1.to_duration());
ostringstream os;
os << t2;
assert(os.str() == "1300");
assert(os.str() == "13:00:00");
t2.make12();
os.str("");
assert(t2.hours() == hours{1});
assert(t2.mode() == pm);
assert(t2.to_duration() == t1.to_duration());
os << t2;
assert(os.str() == "1pm");
assert(os.str() == "1:00:00PM");
t2.make24();
os.str("");
assert(t2.hours() == hours{13});
assert(t2.mode() == 0);
assert(t2.to_duration() == t1.to_duration());
os << t2;
assert(os.str() == "1300");
assert(os.str() == "13:00:00");
}

View File

@ -111,7 +111,7 @@ main()
t2.make12();
os.str("");
os << t2;
assert(os.str() == "1:07:06.0480pm");
assert(os.str() == "1:07:06.0480PM");
t2.make24();
os.str("");
os << t2;

View File

@ -85,7 +85,6 @@ main()
static_assert(t1.minutes() == minutes{7}, "");
static_assert(t1.seconds() == seconds{5}, "");
static_assert(t1.subseconds() == milliseconds{22}, "");
static_assert(t1.mode() == 0, "");
#if __cplusplus >= 201402
static_assert(static_cast<tod::precision>(t1) == hours{13} + minutes{7}
+ seconds{5} + milliseconds{22}, "");
@ -98,7 +97,6 @@ main()
assert(t2.minutes() == t1.minutes());
assert(t2.seconds() == t1.seconds());
assert(t2.subseconds() == t1.subseconds());
assert(t2.mode() == t1.mode());
assert(t2.to_duration() == t1.to_duration());
ostringstream os;
os << t2;
@ -109,17 +107,15 @@ main()
assert(t2.minutes() == minutes{7});
assert(t2.seconds() == seconds{5});
assert(t2.subseconds() == milliseconds{22});
assert(t2.mode() == pm);
assert(t2.to_duration() == t1.to_duration());
os << t2;
assert(os.str() == "1:07:05.022pm");
assert(os.str() == "1:07:05.022PM");
t2.make24();
os.str("");
assert(t2.hours() == hours{13});
assert(t2.minutes() == minutes{7});
assert(t2.seconds() == seconds{5});
assert(t2.subseconds() == milliseconds{22});
assert(t2.mode() == 0);
assert(t2.to_duration() == t1.to_duration());
os << t2;
assert(os.str() == "13:07:05.022");

View File

@ -59,7 +59,7 @@ main()
using tod = time_of_day<minutes>;
static_assert(is_same<tod::precision::period, minutes::period>{}, "");
static_assert(is_same<tod::precision::period, seconds::period>{}, "");
static_assert( is_trivially_destructible<tod>{}, "");
static_assert( is_default_constructible<tod>{}, "");
@ -77,7 +77,6 @@ main()
constexpr tod t1 = tod{hours{13} + minutes{7}};
static_assert(t1.hours() == hours{13}, "");
static_assert(t1.minutes() == minutes{7}, "");
static_assert(t1.mode() == 0, "");
#if __cplusplus >= 201402
static_assert(static_cast<tod::precision>(t1) == hours{13} + minutes{7}, "");
static_assert(t1.to_duration() == hours{13} + minutes{7}, "");
@ -86,25 +85,22 @@ main()
auto t2 = t1;
assert(t2.hours() == t1.hours());
assert(t2.minutes() == t1.minutes());
assert(t2.mode() == t1.mode());
assert(t2.to_duration() == t1.to_duration());
ostringstream os;
os << t2;
assert(os.str() == "13:07");
assert(os.str() == "13:07:00");
t2.make12();
os.str("");
assert(t2.hours() == hours{1});
assert(t2.minutes() == minutes{7});
assert(t2.mode() == pm);
assert(t2.to_duration() == t1.to_duration());
os << t2;
assert(os.str() == "1:07pm");
assert(os.str() == "1:07:00PM");
t2.make24();
os.str("");
assert(t2.hours() == hours{13});
assert(t2.minutes() == minutes{7});
assert(t2.mode() == 0);
assert(t2.to_duration() == t1.to_duration());
os << t2;
assert(os.str() == "13:07");
assert(os.str() == "13:07:00");
}

View File

@ -85,7 +85,6 @@ main()
static_assert(t1.minutes() == minutes{7}, "");
static_assert(t1.seconds() == seconds{5}, "");
static_assert(t1.subseconds() == nanoseconds{22}, "");
static_assert(t1.mode() == 0, "");
#if __cplusplus >= 201402
static_assert(static_cast<tod::precision>(t1) == hours{13} + minutes{7}
+ seconds{5} + nanoseconds{22}, "");
@ -98,7 +97,6 @@ main()
assert(t2.minutes() == t1.minutes());
assert(t2.seconds() == t1.seconds());
assert(t2.subseconds() == t1.subseconds());
assert(t2.mode() == t1.mode());
assert(t2.to_duration() == t1.to_duration());
ostringstream os;
os << t2;
@ -109,17 +107,15 @@ main()
assert(t2.minutes() == minutes{7});
assert(t2.seconds() == seconds{5});
assert(t2.subseconds() == nanoseconds{22});
assert(t2.mode() == pm);
assert(t2.to_duration() == t1.to_duration());
os << t2;
assert(os.str() == "1:07:05.000000022pm");
assert(os.str() == "1:07:05.000000022PM");
t2.make24();
os.str("");
assert(t2.hours() == hours{13});
assert(t2.minutes() == minutes{7});
assert(t2.seconds() == seconds{5});
assert(t2.subseconds() == nanoseconds{22});
assert(t2.mode() == 0);
assert(t2.to_duration() == t1.to_duration());
os << t2;
assert(os.str() == "13:07:05.000000022");

View File

@ -79,7 +79,6 @@ main()
static_assert(t1.hours() == hours{13}, "");
static_assert(t1.minutes() == minutes{7}, "");
static_assert(t1.seconds() == seconds{5}, "");
static_assert(t1.mode() == 0, "");
#if __cplusplus >= 201402
static_assert(static_cast<tod::precision>(t1) == hours{13} + minutes{7}
+ seconds{5}, "");
@ -90,7 +89,6 @@ main()
assert(t2.hours() == t1.hours());
assert(t2.minutes() == t1.minutes());
assert(t2.seconds() == t1.seconds());
assert(t2.mode() == t1.mode());
assert(t2.to_duration() == t1.to_duration());
ostringstream os;
os << t2;
@ -100,16 +98,14 @@ main()
assert(t2.hours() == hours{1});
assert(t2.minutes() == minutes{7});
assert(t2.seconds() == seconds{5});
assert(t2.mode() == pm);
assert(t2.to_duration() == t1.to_duration());
os << t2;
assert(os.str() == "1:07:05pm");
assert(os.str() == "1:07:05PM");
t2.make24();
os.str("");
assert(t2.hours() == hours{13});
assert(t2.minutes() == minutes{7});
assert(t2.seconds() == seconds{5});
assert(t2.mode() == 0);
assert(t2.to_duration() == t1.to_duration());
os << t2;
assert(os.str() == "13:07:05");