Get off of day_point

This commit is contained in:
Howard Hinnant 2016-05-21 10:24:25 -04:00
parent 823176c1ea
commit 76c906d779
14 changed files with 68 additions and 114 deletions

21
date.h
View File

@ -101,9 +101,6 @@ template <class Duration>
using local_seconds = local_time<std::chrono::seconds>;
using local_days = local_time<days>;
// deprecated:
using day_point = sys_days;
// types
struct last_spec
@ -1326,19 +1323,14 @@ year::is_leap() const NOEXCEPT
}
CONSTCD11 inline year::operator int() const NOEXCEPT {return y_;}
CONSTCD11 inline bool year::ok() const NOEXCEPT {return min() <= *this && *this <= max();}
CONSTCD11 inline bool year::ok() const NOEXCEPT {return true;}
CONSTCD11
inline
year
year::min() NOEXCEPT
{
using namespace std::chrono;
static_assert(sizeof(seconds)*CHAR_BIT >= 41, "seconds may overflow");
static_assert(sizeof(hours)*CHAR_BIT >= 30, "hours may overflow");
return sizeof(minutes)*CHAR_BIT < 34 ?
year{1970} + duration_cast<years>(minutes::min()) :
year{std::numeric_limits<short>::min()};
return year{std::numeric_limits<short>::min()};
}
CONSTCD11
@ -1346,12 +1338,7 @@ inline
year
year::max() NOEXCEPT
{
using namespace std::chrono;
static_assert(sizeof(seconds)*CHAR_BIT >= 41, "seconds may overflow");
static_assert(sizeof(hours)*CHAR_BIT >= 30, "hours may overflow");
return sizeof(minutes)*CHAR_BIT < 34 ?
year{1969} + duration_cast<years>(minutes::max()) :
year{std::numeric_limits<short>::max()};
return year{std::numeric_limits<short>::max()};
}
CONSTCD11
@ -2709,7 +2696,7 @@ inline
days
year_month_weekday::to_days() const NOEXCEPT
{
auto d = day_point(y_/m_/1);
auto d = sys_days(y_/m_/1);
return (d + (wdi_.weekday() - date::weekday(d) + days{(wdi_.index()-1)*7})
).time_since_epoch();
}

View File

@ -41,9 +41,6 @@ using years = date::years;
using sys_days = date::sys_days;
using local_days = date::local_days;
// deprecated:
using day_point = sys_days;
// types
struct last_week

View File

@ -36,7 +36,7 @@
//
// time_point
//
// using day_point = std::chrono::time_point<std::chrono::system_clock, days>;
// using sys_days = std::chrono::time_point<std::chrono::system_clock, days>;
#include "date.h"
@ -54,7 +54,7 @@ static_assert(date::years{400} == date::days{146097}, "");
static_assert(date::days{365} < date::years{1} && date::years{1} < date::days{366}, "");
static_assert(date::weeks{52} < date::years{1} && date::years{1} < date::weeks{53}, "");
static_assert(std::is_same<date::day_point::duration, date::days>{}, "");
static_assert(std::is_same<date::sys_days::duration, date::days>{}, "");
int
main()

View File

@ -34,7 +34,7 @@ main()
static_assert(sizeof(months) == 4, "");
static_assert(sizeof(years) == 4, "");
static_assert(sizeof(day_point) == 4, "");
static_assert(sizeof(sys_days) == 4, "");
static_assert(sizeof(last_spec) == 1, "");

View File

@ -25,7 +25,7 @@
// unsigned char wd_;
// public:
// explicit constexpr weekday(unsigned wd) noexcept;
// constexpr weekday(const day_point& dp) noexcept;
// constexpr weekday(const sys_days& dp) noexcept;
//
// weekday& operator++() noexcept;
// weekday operator++(int) noexcept;
@ -76,10 +76,10 @@ static_assert( std::is_trivially_move_constructible<date::weekday>{}, "");
static_assert( std::is_trivially_move_assignable<date::weekday>{}, "");
static_assert( std::is_nothrow_constructible<date::weekday, unsigned>{}, "");
static_assert( std::is_nothrow_constructible<date::weekday, date::day_point>{}, "");
static_assert( std::is_nothrow_constructible<date::weekday, date::sys_days>{}, "");
static_assert( std::is_nothrow_constructible<unsigned, date::weekday>{}, "");
static_assert(!std::is_convertible<unsigned, date::weekday>{}, "");
static_assert( std::is_convertible<date::day_point, date::weekday>{}, "");
static_assert( std::is_convertible<date::sys_days, date::weekday>{}, "");
static_assert(!std::is_convertible<date::weekday, unsigned>{}, "");
static_assert(static_cast<unsigned>(date::weekday{1u}) == 1, "");

View File

@ -108,29 +108,29 @@ main()
#if __cplusplus >= 201402
using int64_t = std::int64_t;
static_assert(day_point(year::min()/jan/1) - day_point(1970_y/jan/1)
static_assert(sys_days(year::min()/jan/1) - sys_days(1970_y/jan/1)
>= as<int64_t>(days::min()), "");
static_assert(day_point(year::min()/jan/1) - day_point(1970_y/jan/1)
static_assert(sys_days(year::min()/jan/1) - sys_days(1970_y/jan/1)
>= as<int64_t>(hours::min()), "");
static_assert(day_point(year::min()/jan/1) - day_point(1970_y/jan/1)
static_assert(sys_days(year::min()/jan/1) - sys_days(1970_y/jan/1)
>= as<int64_t>(minutes::min()), "");
static_assert(day_point(year::min()/jan/1) - day_point(1970_y/jan/1)
static_assert(sys_days(year::min()/jan/1) - sys_days(1970_y/jan/1)
>= as<int64_t>(seconds::min()), "");
static_assert(day_point(year::min()/jan/1) - day_point(1970_y/jan/1)
static_assert(sys_days(year::min()/jan/1) - sys_days(1970_y/jan/1)
>= as<int64_t>(milliseconds::min()), "");
static_assert(day_point(year::min()/jan/1) - day_point(1970_y/jan/1)
static_assert(sys_days(year::min()/jan/1) - sys_days(1970_y/jan/1)
>= as<int64_t>(microseconds::min()), "");
static_assert(day_point(year::max()/dec/31) - day_point(1970_y/jan/1)
static_assert(sys_days(year::max()/dec/31) - sys_days(1970_y/jan/1)
<= as<int64_t>(microseconds::max()), "");
static_assert(day_point(year::max()/dec/31) - day_point(1970_y/jan/1)
static_assert(sys_days(year::max()/dec/31) - sys_days(1970_y/jan/1)
<= as<int64_t>(milliseconds::max()), "");
static_assert(day_point(year::max()/dec/31) - day_point(1970_y/jan/1)
static_assert(sys_days(year::max()/dec/31) - sys_days(1970_y/jan/1)
<= as<int64_t>(seconds::max()), "");
static_assert(day_point(year::max()/dec/31) - day_point(1970_y/jan/1)
static_assert(sys_days(year::max()/dec/31) - sys_days(1970_y/jan/1)
<= as<int64_t>(minutes::max()), "");
static_assert(day_point(year::max()/dec/31) - day_point(1970_y/jan/1)
static_assert(sys_days(year::max()/dec/31) - sys_days(1970_y/jan/1)
<= as<int64_t>(hours::max()), "");
static_assert(day_point(year::max()/dec/31) - day_point(1970_y/jan/1)
static_assert(sys_days(year::max()/dec/31) - sys_days(1970_y/jan/1)
<= as<int64_t>(days::max()), "");
#endif

View File

@ -26,7 +26,7 @@
// constexpr year_month_day(const date::year& y, const date::month& m,
// const date::day& d) noexcept;
// constexpr year_month_day(const year_month_day_last& ymdl) noexcept;
// constexpr year_month_day(const day_point& dp) noexcept;
// constexpr year_month_day(const sys_days& dp) noexcept;
//
// year_month_day& operator+=(const months& m) noexcept;
// year_month_day& operator-=(const months& m) noexcept;
@ -37,7 +37,7 @@
// constexpr date::month month() const noexcept;
// constexpr date::day day() const noexcept;
//
// constexpr operator day_point() const noexcept;
// constexpr operator sys_days() const noexcept;
// constexpr bool ok() const noexcept;
// };
@ -76,10 +76,10 @@ static_assert(std::is_nothrow_constructible<date::year_month_day, date::year,
static_assert(std::is_nothrow_constructible<date::year_month_day,
date::year_month_day_last>{}, "");
static_assert(std::is_convertible<date::year_month_day_last, date::year_month_day>{}, "");
static_assert(std::is_nothrow_constructible<date::year_month_day, date::day_point>{}, "");
static_assert(std::is_convertible<date::day_point, date::year_month_day>{}, "");
static_assert(std::is_nothrow_constructible<date::day_point, date::year_month_day>{}, "");
static_assert(std::is_convertible<date::year_month_day, date::day_point>{}, "");
static_assert(std::is_nothrow_constructible<date::year_month_day, date::sys_days>{}, "");
static_assert(std::is_convertible<date::sys_days, date::year_month_day>{}, "");
static_assert(std::is_nothrow_constructible<date::sys_days, date::year_month_day>{}, "");
static_assert(std::is_convertible<date::year_month_day, date::sys_days>{}, "");
void
test_arithmetic()
@ -131,7 +131,7 @@ test_day_point_conversion()
using namespace date;
year y = year{-1000};
year end = 3000_y;
day_point prev_dp = day_point(year_month_day{y, jan, 1_d}) - days{1};
sys_days prev_dp = sys_days(year_month_day{y, jan, 1_d}) - days{1};
weekday prev_wd = weekday{prev_dp};
for (; y <= end; ++y)
{
@ -143,7 +143,7 @@ test_day_point_conversion()
{
year_month_day ymd = {y, m, d};
assert(ymd.ok());
day_point dp = ymd;
sys_days dp = ymd;
assert(dp == prev_dp + days{1});
year_month_day ymd2 = dp;
assert(ymd2 == ymd);
@ -171,7 +171,7 @@ main()
static_assert(ymd1.day() == 9_d, "");
#if __cplusplus >= 201402
constexpr day_point dp = ymd1;
constexpr sys_days dp = ymd1;
static_assert(dp.time_since_epoch() == days{16656}, "");
constexpr year_month_day ymd2 = dp;
static_assert(ymd1 == ymd2, "");
@ -186,7 +186,7 @@ main()
static_assert(ymd3.day() == 31_d, "");
#if __cplusplus >= 201402
constexpr day_point dp3 = ymd3;
constexpr sys_days dp3 = ymd3;
static_assert(dp3.time_since_epoch() == days{-1}, "");
constexpr year_month_day ymd4 = dp3;
static_assert(ymd3 == ymd4, "");
@ -211,9 +211,9 @@ main()
static_assert( (2100_y/feb/28).ok(), "");
static_assert(!(2100_y/feb/29).ok(), "");
static_assert(day_point(2100_y/feb/28) + days{1} == day_point(2100_y/mar/1), "");
static_assert(day_point(2000_y/mar/1) - day_point(2000_y/feb/28) == days{2}, "");
static_assert(day_point(2100_y/mar/1) - day_point(2100_y/feb/28) == days{1}, "");
static_assert(sys_days(2100_y/feb/28) + days{1} == sys_days(2100_y/mar/1), "");
static_assert(sys_days(2000_y/mar/1) - sys_days(2000_y/feb/28) == days{2}, "");
static_assert(sys_days(2100_y/mar/1) - sys_days(2100_y/feb/28) == days{1}, "");
static_assert(jan/31/2015 == jan/last/2015, "");
static_assert(feb/28/2015 == feb/last/2015, "");

View File

@ -36,7 +36,7 @@
// constexpr date::month_day_last month_day_last() const noexcept;
// constexpr date::day day() const noexcept;
//
// constexpr operator day_point() const noexcept;
// constexpr operator sys_days() const noexcept;
// constexpr bool ok() const noexcept;
// };
@ -94,9 +94,9 @@ static_assert( std::is_trivially_move_assignable<date::year_month_day_last>{}, "
static_assert(std::is_nothrow_constructible<date::year_month_day_last,
date::year, date::month_day_last>{}, "");
static_assert(std::is_nothrow_constructible<date::day_point,
static_assert(std::is_nothrow_constructible<date::sys_days,
date::year_month_day_last>{}, "");
static_assert(std::is_convertible<date::year_month_day_last, date::day_point>{}, "");
static_assert(std::is_convertible<date::year_month_day_last, date::sys_days>{}, "");
void
test_arithmetic()
@ -154,7 +154,7 @@ main()
static_assert(ymdl1.month_day_last() == month_day_last{aug}, "");
#if __cplusplus >= 201402
static_assert(ymdl1.day() == 31_d, "");
constexpr day_point dp = ymdl1;
constexpr sys_days dp = ymdl1;
constexpr year_month_day ymd = dp;
static_assert(ymd == 2015_y/aug/31, "");
#endif

View File

@ -25,7 +25,7 @@
// public:
// constexpr year_month_weekday(const date::year& y, const date::month& m,
// const date::weekday_indexed& wdi) noexcept;
// constexpr year_month_weekday(const day_point& dp) noexcept;
// constexpr year_month_weekday(const sys_days& dp) noexcept;
//
// year_month_weekday& operator+=(const months& m) noexcept;
// year_month_weekday& operator-=(const months& m) noexcept;
@ -38,11 +38,11 @@
// constexpr unsigned index() const noexcept;
// constexpr date::weekday_indexed weekday_indexed() const noexcept;
//
// constexpr operator day_point() const noexcept;
// constexpr operator sys_days() const noexcept;
// constexpr bool ok() const noexcept;
//
// private:
// static constexpr year_month_weekday from_day_point(const day_point& dp) noexcept;
// static constexpr year_month_weekday from_day_point(const sys_days& dp) noexcept;
// };
// constexpr
@ -93,11 +93,11 @@ static_assert(std::is_nothrow_constructible<date::year_month_weekday,
date::year, date::month,
date::weekday_indexed>{}, "");
static_assert(std::is_nothrow_constructible<date::year_month_weekday,
date::day_point>{}, "");
static_assert(std::is_convertible<date::day_point, date::year_month_weekday>{}, "");
static_assert(std::is_nothrow_constructible<date::day_point,
date::sys_days>{}, "");
static_assert(std::is_convertible<date::sys_days, date::year_month_weekday>{}, "");
static_assert(std::is_nothrow_constructible<date::sys_days,
date::year_month_weekday>{}, "");
static_assert(std::is_convertible<date::year_month_weekday, date::day_point>{}, "");
static_assert(std::is_convertible<date::year_month_weekday, date::sys_days>{}, "");
void
test_arithmetic()
@ -158,7 +158,7 @@ main()
static_assert(ymdl1.index() == 2u, "");
static_assert(ymdl1.weekday_indexed() == fri[2], "");
#if __cplusplus >= 201402
constexpr day_point dp = ymdl1;
constexpr sys_days dp = ymdl1;
constexpr year_month_day ymd = dp;
static_assert(ymd == 2015_y/aug/14, "");
#endif

View File

@ -36,7 +36,7 @@
// constexpr date::weekday weekday() const noexcept;
// constexpr date::weekday_last weekday_last() const noexcept;
//
// constexpr operator day_point() const noexcept;
// constexpr operator sys_days() const noexcept;
// constexpr bool ok() const noexcept;
// };
@ -90,9 +90,9 @@ static_assert( std::is_trivially_move_assignable<date::year_month_weekday_last>{
static_assert(std::is_nothrow_constructible<date::year_month_weekday_last,
date::year, date::month,
date::weekday_last>{}, "");
static_assert(std::is_nothrow_constructible<date::day_point,
static_assert(std::is_nothrow_constructible<date::sys_days,
date::year_month_weekday_last>{}, "");
static_assert(std::is_convertible<date::year_month_weekday_last, date::day_point>{}, "");
static_assert(std::is_convertible<date::year_month_weekday_last, date::sys_days>{}, "");
void
test_arithmetic()
@ -150,7 +150,7 @@ main()
static_assert(ymdl1.weekday() == fri, "");
static_assert(ymdl1.weekday_last() == fri[last], "");
#if __cplusplus >= 201402
constexpr day_point dp = ymdl1;
constexpr sys_days dp = ymdl1;
constexpr year_month_day ymd = dp;
static_assert(ymd == 2015_y/aug/28, "");
#endif

View File

@ -26,7 +26,7 @@
// public:
// explicit constexpr weekday(unsigned wd) noexcept;
// constexpr weekday(date::weekday wd) noexcept;
// constexpr weekday(const day_point& dp) noexcept;
// constexpr weekday(const sys_days& dp) noexcept;
//
// weekday& operator++() noexcept;
// weekday operator++(int) noexcept;
@ -85,12 +85,12 @@ static_assert(std::is_standard_layout<iso_week::weekday>{}, "");
static_assert(std::is_literal_type<iso_week::weekday>{}, "");
static_assert( std::is_nothrow_constructible<iso_week::weekday, unsigned>{}, "");
static_assert( std::is_nothrow_constructible<iso_week::weekday, iso_week::day_point>{}, "");
static_assert( std::is_nothrow_constructible<iso_week::weekday, iso_week::sys_days>{}, "");
static_assert( std::is_nothrow_constructible<iso_week::weekday, date::weekday>{}, "");
static_assert( std::is_nothrow_constructible<date::weekday, iso_week::weekday>{}, "");
static_assert( std::is_nothrow_constructible<unsigned, iso_week::weekday>{}, "");
static_assert(!std::is_convertible<unsigned, iso_week::weekday>{}, "");
static_assert( std::is_convertible<iso_week::day_point, iso_week::weekday>{}, "");
static_assert( std::is_convertible<iso_week::sys_days, iso_week::weekday>{}, "");
static_assert( std::is_convertible<iso_week::weekday, date::weekday>{}, "");
static_assert( std::is_convertible<date::weekday, iso_week::weekday>{}, "");
static_assert(!std::is_convertible<iso_week::weekday, unsigned>{}, "");

View File

@ -33,7 +33,7 @@
// constexpr iso_week::weeknum weeknum() const noexcept;
// constexpr iso_week::weekday weekday() const noexcept;
//
// constexpr operator day_point() const noexcept;
// constexpr operator sys_days() const noexcept;
// constexpr bool ok() const noexcept;
// };
//
@ -69,10 +69,10 @@ static_assert(std::is_literal_type<iso_week::year_lastweek_weekday>{}, "");
static_assert( std::is_nothrow_constructible<iso_week::year_lastweek_weekday,
iso_week::year, iso_week::weekday>{}, "");
static_assert( std::is_nothrow_constructible<iso_week::day_point,
static_assert( std::is_nothrow_constructible<iso_week::sys_days,
iso_week::year_lastweek_weekday>{}, "");
static_assert( std::is_convertible<iso_week::year_lastweek_weekday,
iso_week::day_point>{}, "");
iso_week::sys_days>{}, "");
int
main()
@ -100,8 +100,8 @@ main()
assert(x3.weeknum() == 53_w);
assert(x3.weekday() == tue);
constexpr day_point dp = 2015_y/last/wed;
static_assert(dp == day_point{days{16799}}, "");
constexpr sys_days dp = 2015_y/last/wed;
static_assert(dp == sys_days{days{16799}}, "");
static_assert(x0.ok(), "");
assert(x3.ok());

View File

@ -28,7 +28,7 @@
// constexpr year_weeknum_weekday(const iso_week::year& y, const iso_week::weeknum& wn,
// const iso_week::weekday& wd) noexcept;
// constexpr year_weeknum_weekday(const year_lastweek_weekday& ylwwd) noexcept;
// constexpr year_weeknum_weekday(const day_point& dp) noexcept;
// constexpr year_weeknum_weekday(const sys_days& dp) noexcept;
//
// year_weeknum_weekday& operator+=(const years& y) noexcept;
// year_weeknum_weekday& operator-=(const years& y) noexcept;
@ -37,7 +37,7 @@
// constexpr iso_week::weeknum weeknum() const noexcept;
// constexpr iso_week::weekday weekday() const noexcept;
//
// constexpr operator day_point() const noexcept;
// constexpr operator sys_days() const noexcept;
// constexpr bool ok() const noexcept;
// };
//
@ -79,13 +79,13 @@ static_assert( std::is_nothrow_constructible<iso_week::year_weeknum_weekday,
static_assert( std::is_convertible<iso_week::year_lastweek_weekday,
iso_week::year_weeknum_weekday>{}, "");
static_assert( std::is_nothrow_constructible<iso_week::year_weeknum_weekday,
iso_week::day_point>{}, "");
static_assert( std::is_convertible<iso_week::day_point,
iso_week::sys_days>{}, "");
static_assert( std::is_convertible<iso_week::sys_days,
iso_week::year_weeknum_weekday>{}, "");
static_assert( std::is_nothrow_constructible<iso_week::day_point,
static_assert( std::is_nothrow_constructible<iso_week::sys_days,
iso_week::year_weeknum_weekday>{}, "");
static_assert( std::is_convertible<iso_week::year_weeknum_weekday,
iso_week::day_point>{}, "");
iso_week::sys_days>{}, "");
int
main()
@ -102,7 +102,7 @@ main()
static_assert(x1.weeknum() == 53_w, "");
static_assert(x1.weekday() == tue, "");
constexpr year_weeknum_weekday x2 = day_point{days{16792}};
constexpr year_weeknum_weekday x2 = sys_days{days{16792}};
static_assert(x2.year() == 2015_y, "");
static_assert(x2.weeknum() == 52_w, "");
static_assert(x2.weekday() == wed, "");
@ -118,8 +118,8 @@ main()
assert(x3.weeknum() == 52_w);
assert(x3.weekday() == wed);
constexpr day_point dp = 2015_y/52_w/wed;
static_assert(dp == day_point{days{16792}}, "");
constexpr sys_days dp = 2015_y/52_w/wed;
static_assert(dp == sys_days{days{16792}}, "");
static_assert(x0.ok(), "");
static_assert(x1.ok(), "");

30
tz.h
View File

@ -223,36 +223,6 @@ operator<<(std::ostream& os, const local_info& r);
using Info = sys_info;
class time_zone;
// deprecated:
using Zone = time_zone;
namespace detail
{
inline
days
sum()
{
return days{0};
}
template <class Duration>
inline
Duration
sum(Duration d)
{
return d;
}
template <class D1, class D2, class... Durations>
inline
std::common_type_t<D1, D2, Durations...>
sum(D1 d1, D2 d2, Durations ...durations)
{
return d1 + d2 + sum(durations...);
}
} // detail
template <class Duration>
class zoned_time