Boost C++ Libraries: Ticket #12910: boost::date_time::time_input_facet throws when using %j alone https://svn.boost.org/trac10/ticket/12910 <p> With a format such as <code>"%j-%H:%M:%S"</code>, <code>boost::date_time::time_input_facet</code> throws an error because when using <code>"%j"</code>, the computation of the date is: </p> <div class="wiki-code"><div class="code"><pre><span class="n">date_type</span> <span class="nf">d</span><span class="p">(</span><span class="n">not_a_date_time</span><span class="p">);</span> <span class="k">if</span> <span class="p">(</span><span class="n">day_of_year</span> <span class="o">&gt;</span> <span class="mi">0</span><span class="p">)</span> <span class="p">{</span> <span class="n">d</span> <span class="o">=</span> <span class="n">date_type</span><span class="p">(</span><span class="k">static_cast</span><span class="o">&lt;</span><span class="kt">unsigned</span> <span class="kt">short</span><span class="o">&gt;</span><span class="p">(</span><span class="n">t_year</span><span class="o">-</span><span class="mi">1</span><span class="p">),</span><span class="mi">12</span><span class="p">,</span><span class="mi">31</span><span class="p">)</span> <span class="o">+</span> <span class="n">date_duration_type</span><span class="p">(</span><span class="n">day_of_year</span><span class="p">);</span> <span class="p">}</span> </pre></div></div><p> And <code>t_year</code> is 1400! I am in a situation where I need to parse such a date/time though... </p> <p> Instead couldn't the computation be as follows? </p> <div class="wiki-code"><div class="code"><pre><span class="n">date_type</span> <span class="nf">d</span><span class="p">(</span><span class="n">not_a_date_time</span><span class="p">);</span> <span class="k">if</span> <span class="p">(</span><span class="n">day_of_year</span> <span class="o">&gt;</span> <span class="mi">0</span><span class="p">)</span> <span class="p">{</span> <span class="n">d</span> <span class="o">=</span> <span class="n">date_type</span><span class="p">(</span><span class="k">static_cast</span><span class="o">&lt;</span><span class="kt">unsigned</span> <span class="kt">short</span><span class="o">&gt;</span><span class="p">(</span><span class="n">t_year</span><span class="p">),</span> <span class="mi">1</span><span class="p">,</span> <span class="mi">1</span><span class="p">)</span> <span class="o">+</span> <span class="n">date_duration_type</span><span class="p">(</span><span class="n">day_of_year</span> <span class="o">-</span> <span class="mi">1</span><span class="p">);</span> <span class="p">}</span> </pre></div></div><p> If so, the result of parsing <code>"263-08:09:10"</code> would be <code>"1400-Sep-20 08:09:10 UTC"</code>. (And I'm good with that.) </p> <p> Test exposing the problem: <a class="ext-link" href="http://coliru.stacked-crooked.com/a/16f2f96ee808afa2"><span class="icon">​</span>http://coliru.stacked-crooked.com/a/16f2f96ee808afa2</a> </p> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/12910 Trac 1.4.3 James E. King, III Fri, 22 Dec 2017 15:06:11 GMT owner changed https://svn.boost.org/trac10/ticket/12910#comment:1 https://svn.boost.org/trac10/ticket/12910#comment:1 <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 Fri, 22 Dec 2017 15:14:38 GMT <link>https://svn.boost.org/trac10/ticket/12910#comment:2 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/12910#comment:2</guid> <description> <p> %j specifies the day of the year (which begs the question: which year?), without specifying the year, why would it be valid? It'll be interesting to see how strptime handles this for reference. </p> </description> <category>Ticket</category> </item> <item> <dc:creator>James E. King, III</dc:creator> <pubDate>Tue, 26 Dec 2017 17:03:08 GMT</pubDate> <title>status changed https://svn.boost.org/trac10/ticket/12910#comment:3 https://svn.boost.org/trac10/ticket/12910#comment:3 <ul> <li><strong>status</strong> <span class="trac-field-old">new</span> → <span class="trac-field-new">assigned</span> </li> </ul> <p> PR is out: <a class="ext-link" href="https://github.com/boostorg/date_time/pull/59"><span class="icon">​</span>https://github.com/boostorg/date_time/pull/59</a> </p> Ticket James E. King, III Thu, 18 Jan 2018 13:51:31 GMT milestone changed https://svn.boost.org/trac10/ticket/12910#comment:4 https://svn.boost.org/trac10/ticket/12910#comment:4 <ul> <li><strong>milestone</strong> <span class="trac-field-old">To Be Determined</span> → <span class="trac-field-new">Boost 1.67.0</span> </li> </ul> Ticket James E. King, III Sun, 28 Jan 2018 16:25:36 GMT status changed; resolution set https://svn.boost.org/trac10/ticket/12910#comment:5 https://svn.boost.org/trac10/ticket/12910#comment:5 <ul> <li><strong>status</strong> <span class="trac-field-old">assigned</span> → <span class="trac-field-new">closed</span> </li> <li><strong>resolution</strong> → <span class="trac-field-new">fixed</span> </li> </ul> <p> Fix merged to master; resolved. </p> Ticket