Boost C++ Libraries: Ticket #13280: "20170101" gives surprising result parsed as extended ISO 8601 https://svn.boost.org/trac10/ticket/13280 <pre class="wiki">#include &lt;locale&gt; #include &lt;iostream&gt; #include &lt;sstream&gt; #include &lt;boost/date_time/gregorian/gregorian.hpp&gt; int main() { std::string value = "20170105"; boost::gregorian::date d; auto * f = new boost::gregorian::date_input_facet(); f-&gt;set_iso_extended_format(); std::stringstream ss; std::locale loc(std::locale::classic(), f); ss.imbue(loc); ss &lt;&lt; value; ss &gt;&gt; d; std::cout &lt;&lt; value &lt;&lt; " =&gt; " &lt;&lt; d &lt;&lt; '\n'; return 0; } </pre><p> When I run this I get: </p> <p> 20170105 =&gt; 2017-Oct-01 </p> <p> I expected an exception to be raised. </p> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/13280 Trac 1.4.3 Thomas Guest <thomas.guest@…> Mon, 30 Oct 2017 17:05:49 GMT <link>https://svn.boost.org/trac10/ticket/13280#comment:1 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/13280#comment:1</guid> <description> <p> Apologies - version should be 1.65.1 </p> </description> <category>Ticket</category> </item> <item> <dc:creator>James E. King, III</dc:creator> <pubDate>Thu, 21 Dec 2017 14:24:39 GMT</pubDate> <title>version changed https://svn.boost.org/trac10/ticket/13280#comment:2 https://svn.boost.org/trac10/ticket/13280#comment:2 <ul> <li><strong>version</strong> <span class="trac-field-old">Boost 1.63.0</span> → <span class="trac-field-new">Boost 1.65.0</span> </li> </ul> Ticket James E. King, III Thu, 21 Dec 2017 15:53:17 GMT owner changed https://svn.boost.org/trac10/ticket/13280#comment:3 https://svn.boost.org/trac10/ticket/13280#comment:3 <ul> <li><strong>owner</strong> changed from <span class="trac-author">az_sw_dude</span> to <span class="trac-author">James E. King, III</span> </li> </ul> Ticket James E. King, III Thu, 21 Dec 2017 16:06:35 GMT status changed; resolution set https://svn.boost.org/trac10/ticket/13280#comment:4 https://svn.boost.org/trac10/ticket/13280#comment:4 <ul> <li><strong>status</strong> <span class="trac-field-old">new</span> → <span class="trac-field-new">closed</span> </li> <li><strong>resolution</strong> → <span class="trac-field-new">worksforme</span> </li> </ul> <p> I just added this test to testdate_input_facet and using Boost 1.66.0 with msvc-14.1 it works properly. You did not enable exceptions in your example. Before calling imbue, you want to call: </p> <pre class="wiki"> ss.exceptions(std::ios_base::failbit); // turn on exceptions </pre><p> if you want an exception to be raised. </p> <p> Example (add this to the testdate_input_facet unit test to see it work): </p> <pre class="wiki"> // prove trac 13280 on extended iso format is behaving properly { std::string value = "20171221"; date_input_facet *f13280_bad = new date_input_facet(); f13280_bad-&gt;set_iso_extended_format(); std::stringstream s13280_bad; s13280_bad.imbue(std::locale(s13280_bad.getloc(), f13280_bad)); s13280_bad &lt;&lt; value; boost::gregorian::date d13280_bad; check("extended ISO with YYYYMMDD sets failbit", failure_test(d13280_bad, value, f13280_bad)); check("extended iso with YYYYMMDD is not a date", d13280_bad.is_not_a_date()); } </pre> Ticket James E. King, III Thu, 21 Dec 2017 20:01:35 GMT <link>https://svn.boost.org/trac10/ticket/13280#comment:5 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/13280#comment:5</guid> <description> <p> The documentation is clear on this one as well: </p> <p> <a href="http://www.boost.org/doc/libs/1_66_0/doc/html/date_time/date_time_io.html">http://www.boost.org/doc/libs/1_66_0/doc/html/date_time/date_time_io.html</a> </p> <pre class="wiki">Exception Handling on Streams When an error occurs during the input streaming process, the std::ios_base::failbit will (always) be set on the stream. It is also possible to have exceptions thrown when an error occurs. To "turn on" these exceptions, call the stream's exceptions function with a parameter of std::ios_base::failbit. </pre> </description> <category>Ticket</category> </item> </channel> </rss>