diff --git a/date.h b/date.h index 4489f4f..fd1e308 100644 --- a/date.h +++ b/date.h @@ -1403,14 +1403,21 @@ year::is_leap() const NOEXCEPT } CONSTCD11 inline year::operator int() const NOEXCEPT {return y_;} -CONSTCD11 inline bool year::ok() const NOEXCEPT {return true;} + +CONSTCD11 +inline +bool +year::ok() const NOEXCEPT +{ + return y_ != std::numeric_limits::min(); +} CONSTCD11 inline year year::min() NOEXCEPT { - return year{std::numeric_limits::min()}; + return year{std::numeric_limits::min()+1}; } CONSTCD11 @@ -5458,7 +5465,7 @@ from_stream(std::basic_istream& is, const CharT* fmt, const CharT* command = nullptr; auto modified = CharT{}; auto width = -1; - CONSTDATA int not_a_year = 33000; + CONSTDATA int not_a_year = numeric_limits::min(); int Y = not_a_year; CONSTDATA int not_a_century = not_a_year / 100; int C = not_a_century; @@ -6377,6 +6384,8 @@ from_stream(std::basic_istream& is, const CharT* fmt, year& y, using CT = seconds; fields fds{}; from_stream(is, fmt, fds, abbrev, offset); + if (!fds.ymd.year().ok()) + is.setstate(ios::failbit); if (!is.fail()) y = fds.ymd.year(); } diff --git a/test/date_test/format/range.pass.cpp b/test/date_test/format/range.pass.cpp index d268b04..6a10ba3 100644 --- a/test/date_test/format/range.pass.cpp +++ b/test/date_test/format/range.pass.cpp @@ -41,7 +41,7 @@ main() using namespace std::chrono; std::ostringstream os; os << format("%F %T", sys_days{jan/1/year::min()}); - assert(os.str() == "-32768-01-01 00:00:00"); + assert(os.str() == "-32767-01-01 00:00:00"); os.str(""); os << format("%F %T", sys_days{dec/last/year::max()}); assert(os.str() == "32767-12-31 00:00:00"); @@ -52,7 +52,7 @@ main() os.str(""); os << format("%Y-%m-%d %H:%M:%S", sys_days{jan/1/year::min()}); - assert(os.str() == "-32768-01-01 00:00:00"); + assert(os.str() == "-32767-01-01 00:00:00"); os.str(""); os << format("%Y-%m-%d %H:%M:%S", sys_days{dec/last/year::max()}); assert(os.str() == "32767-12-31 00:00:00"); @@ -63,14 +63,14 @@ main() os.str(""); os << format("%F %T", sys_days{jan/1/year::min()} + microfortnights{1}); - assert(os.str() == "-32768-01-01 00:00:01.2096"); + assert(os.str() == "-32767-01-01 00:00:01.2096"); os.str(""); os << format("%F %T", sys_days{dec/last/year::max()} + microfortnights{1}); assert(os.str() == "32767-12-31 00:00:01.2096"); os.str(""); os << format("%F %T", jan/1/year::min()); - assert(os.str() == "-32768-01-01 00:00:00"); + assert(os.str() == "-32767-01-01 00:00:00"); os.str(""); os << format("%F %T", dec/last/year::max()); assert(os.str() == "32767-12-31 00:00:00"); diff --git a/test/date_test/format/two_dight_year.pass.cpp b/test/date_test/format/two_dight_year.pass.cpp index d555142..3f615b3 100644 --- a/test/date_test/format/two_dight_year.pass.cpp +++ b/test/date_test/format/two_dight_year.pass.cpp @@ -117,5 +117,5 @@ main() os.str(""); os << format("%y", sys_days{jun/1/year::min()}); - assert(os.str() == "68"); + assert(os.str() == "67"); }