Skip to content

Commit

Permalink
Emphasize Sunday over sun in the implementation
Browse files Browse the repository at this point in the history
*  Keep the three letter lower case spellings for backwards
   compatibility purposes.
  • Loading branch information
HowardHinnant committed Jun 3, 2018
1 parent 40b8365 commit be2ec23
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 41 deletions.
61 changes: 32 additions & 29 deletions include/date/date.h
Original file line number Diff line number Diff line change
Expand Up @@ -989,30 +989,30 @@ inline namespace literals
CONSTCD11 date::day operator "" _d(unsigned long long d) NOEXCEPT;
CONSTCD11 date::year operator "" _y(unsigned long long y) NOEXCEPT;

// CONSTDATA date::month jan{1};
// CONSTDATA date::month feb{2};
// CONSTDATA date::month mar{3};
// CONSTDATA date::month apr{4};
// CONSTDATA date::month may{5};
// CONSTDATA date::month jun{6};
// CONSTDATA date::month jul{7};
// CONSTDATA date::month aug{8};
// CONSTDATA date::month sep{9};
// CONSTDATA date::month oct{10};
// CONSTDATA date::month nov{11};
// CONSTDATA date::month dec{12};
//
// CONSTDATA date::weekday sun{0u};
// CONSTDATA date::weekday mon{1u};
// CONSTDATA date::weekday tue{2u};
// CONSTDATA date::weekday wed{3u};
// CONSTDATA date::weekday thu{4u};
// CONSTDATA date::weekday fri{5u};
// CONSTDATA date::weekday sat{6u};

} // inline namespace literals
#endif // !defined(_MSC_VER) || (_MSC_VER >= 1900)

// CONSTDATA date::month January{1};
// CONSTDATA date::month February{2};
// CONSTDATA date::month March{3};
// CONSTDATA date::month April{4};
// CONSTDATA date::month May{5};
// CONSTDATA date::month June{6};
// CONSTDATA date::month July{7};
// CONSTDATA date::month August{8};
// CONSTDATA date::month September{9};
// CONSTDATA date::month October{10};
// CONSTDATA date::month November{11};
// CONSTDATA date::month December{12};
//
// CONSTDATA date::weekday Sunday{0u};
// CONSTDATA date::weekday Monday{1u};
// CONSTDATA date::weekday Tuesday{2u};
// CONSTDATA date::weekday Wednesday{3u};
// CONSTDATA date::weekday Thursday{4u};
// CONSTDATA date::weekday Friday{5u};
// CONSTDATA date::weekday Saturday{6u};

#if HAS_VOID_T

template <class T, class = std::void_t<>>
Expand Down Expand Up @@ -2501,7 +2501,7 @@ year_month_day_last::day() const NOEXCEPT
date::day(31), date::day(31), date::day(30),
date::day(31), date::day(30), date::day(31)
};
return month() != feb || !y_.is_leap() ?
return month() != February || !y_.is_leap() ?
d[static_cast<unsigned>(month()) - 1] : date::day{29};
}

Expand Down Expand Up @@ -2703,7 +2703,7 @@ year_month_day::to_days() const NOEXCEPT
"This algorithm has not been ported to a 16 bit unsigned integer");
static_assert(std::numeric_limits<int>::digits >= 20,
"This algorithm has not been ported to a 16 bit signed integer");
auto const y = static_cast<int>(y_) - (m_ <= feb);
auto const y = static_cast<int>(y_) - (m_ <= February);
auto const m = static_cast<unsigned>(m_);
auto const d = static_cast<unsigned>(d_);
auto const era = (y >= 0 ? y : y-399) / 400;
Expand Down Expand Up @@ -4851,7 +4851,8 @@ to_stream(std::basic_ostream<CharT, Traits>& os, const CharT* fmt,
os.setstate(std::ios::failbit);
auto ld = local_days(fds.ymd);
auto y = year_month_day{ld + days{3}}.year();
auto start = local_days((y - years{1})/date::dec/thu[last]) + (mon-thu);
auto start = local_days((y-years{1})/December/Thursday[last]) +
(Monday-Thursday);
if (ld < start)
--y;
if (*fmt == CharT{'G'})
Expand Down Expand Up @@ -4925,7 +4926,7 @@ to_stream(std::basic_ostream<CharT, Traits>& os, const CharT* fmt,
os.setstate(std::ios::failbit);
auto ld = local_days(fds.ymd);
auto y = fds.ymd.year();
auto doy = ld - local_days(y/jan/1) + days{1};
auto doy = ld - local_days(y/January/1) + days{1};
save_ostream<CharT, Traits> _(os);
os.fill('0');
os.flags(std::ios::dec | std::ios::right);
Expand Down Expand Up @@ -5233,7 +5234,7 @@ to_stream(std::basic_ostream<CharT, Traits>& os, const CharT* fmt,
if (modified == CharT{})
#endif
{
auto st = local_days(sun[1]/jan/ymd.year());
auto st = local_days(Sunday[1]/January/ymd.year());
if (ld < st)
os << CharT{'0'} << CharT{'0'};
else
Expand Down Expand Up @@ -5278,11 +5279,13 @@ to_stream(std::basic_ostream<CharT, Traits>& os, const CharT* fmt,
#endif
{
auto y = year_month_day{ld + days{3}}.year();
auto st = local_days((y - years{1})/12/thu[last]) + (mon-thu);
auto st = local_days((y-years{1})/12/Thursday[last]) +
(Monday-Thursday);
if (ld < st)
{
--y;
st = local_days((y - years{1})/12/thu[last]) + (mon-thu);
st = local_days((y - years{1})/12/Thursday[last]) +
(Monday-Thursday);
}
auto wn = duration_cast<weeks>(ld - st).count() + 1;
if (wn < 10)
Expand Down Expand Up @@ -5356,7 +5359,7 @@ to_stream(std::basic_ostream<CharT, Traits>& os, const CharT* fmt,
if (modified == CharT{})
#endif
{
auto st = local_days(mon[1]/jan/ymd.year());
auto st = local_days(Monday[1]/January/ymd.year());
if (ld < st)
os << CharT{'0'} << CharT{'0'};
else
Expand Down
22 changes: 12 additions & 10 deletions include/date/tz.h
Original file line number Diff line number Diff line change
Expand Up @@ -2032,7 +2032,7 @@ tai_clock::to_utc(const tai_time<Duration>& t) NOEXCEPT
using namespace std::chrono;
using duration = typename std::common_type<Duration, seconds>::type;
return utc_time<duration>{t.time_since_epoch()} -
(sys_days(year{1970}/jan/1) - sys_days(year{1958}/jan/1) + seconds{10});
(sys_days(year{1970}/January/1) - sys_days(year{1958}/January/1) + seconds{10});
}

template <class Duration>
Expand All @@ -2043,7 +2043,7 @@ tai_clock::from_utc(const utc_time<Duration>& t) NOEXCEPT
using namespace std::chrono;
using duration = typename std::common_type<Duration, seconds>::type;
return tai_time<duration>{t.time_since_epoch()} +
(sys_days(year{1970}/jan/1) - sys_days(year{1958}/jan/1) + seconds{10});
(sys_days(year{1970}/January/1) - sys_days(year{1958}/January/1) + seconds{10});
}

inline
Expand All @@ -2065,7 +2065,7 @@ to_stream(std::basic_ostream<CharT, Traits>& os, const CharT* fmt,
const string abbrev("TAI");
CONSTDATA seconds offset{0};
auto tp = sys_time<CT>{t.time_since_epoch()} -
seconds(sys_days(year{1970}/jan/1) - sys_days(year{1958}/jan/1));
seconds(sys_days(year{1970}/January/1) - sys_days(year{1958}/January/1));
auto const sd = floor<days>(tp);
year_month_day ymd = sd;
auto time = make_time(tp - sys_seconds{sd});
Expand Down Expand Up @@ -2101,7 +2101,7 @@ from_stream(std::basic_istream<CharT, Traits>& is, const CharT* fmt,
if (!is.fail())
tp = tai_time<Duration>{duration_cast<Duration>(
(sys_days(fds.ymd) +
(sys_days(year{1970}/jan/1) - sys_days(year{1958}/jan/1)) -
(sys_days(year{1970}/January/1) - sys_days(year{1958}/January/1)) -
*offptr + fds.tod.to_duration()).time_since_epoch())};
return is;
}
Expand Down Expand Up @@ -2144,7 +2144,8 @@ gps_clock::to_utc(const gps_time<Duration>& t) NOEXCEPT
using namespace std::chrono;
using duration = typename std::common_type<Duration, seconds>::type;
return utc_time<duration>{t.time_since_epoch()} +
(sys_days(year{1980}/jan/sun[1]) - sys_days(year{1970}/jan/1) + seconds{9});
(sys_days(year{1980}/January/Sunday[1]) - sys_days(year{1970}/January/1) +
seconds{9});
}

template <class Duration>
Expand All @@ -2155,7 +2156,8 @@ gps_clock::from_utc(const utc_time<Duration>& t) NOEXCEPT
using namespace std::chrono;
using duration = typename std::common_type<Duration, seconds>::type;
return gps_time<duration>{t.time_since_epoch()} -
(sys_days(year{1980}/jan/sun[1]) - sys_days(year{1970}/jan/1) + seconds{9});
(sys_days(year{1980}/January/Sunday[1]) - sys_days(year{1970}/January/1) +
seconds{9});
}

inline
Expand All @@ -2177,7 +2179,7 @@ to_stream(std::basic_ostream<CharT, Traits>& os, const CharT* fmt,
const string abbrev("GPS");
CONSTDATA seconds offset{0};
auto tp = sys_time<CT>{t.time_since_epoch()} +
seconds(sys_days(year{1980}/jan/sun[1]) - sys_days(year{1970}/jan/1));
seconds(sys_days(year{1980}/January/Sunday[1]) - sys_days(year{1970}/January/1));
auto const sd = floor<days>(tp);
year_month_day ymd = sd;
auto time = make_time(tp - sys_seconds{sd});
Expand Down Expand Up @@ -2212,9 +2214,9 @@ from_stream(std::basic_istream<CharT, Traits>& is, const CharT* fmt,
is.setstate(ios::failbit);
if (!is.fail())
tp = gps_time<Duration>{duration_cast<Duration>(
(sys_days(fds.ymd) -
(sys_days(year{1980}/jan/sun[1]) - sys_days(year{1970}/jan/1)) -
*offptr + fds.tod.to_duration()).time_since_epoch())};
(sys_days(fds.ymd) -
(sys_days(year{1980}/January/Sunday[1]) - sys_days(year{1970}/January/1)) -
*offptr + fds.tod.to_duration()).time_since_epoch())};
return is;
}

Expand Down
4 changes: 2 additions & 2 deletions src/tz.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -319,8 +319,8 @@ get_download_gz_file(const std::string& version)
CONSTDATA auto min_year = date::year::min();
CONSTDATA auto max_year = date::year::max();

CONSTDATA auto min_day = date::jan/1;
CONSTDATA auto max_day = date::dec/31;
CONSTDATA auto min_day = date::January/1;
CONSTDATA auto max_day = date::December/31;

#if USE_OS_TZDB

Expand Down

0 comments on commit be2ec23

Please sign in to comment.