Boost C++ Libraries: Ticket #10285: local_time is not monotonic https://svn.boost.org/trac10/ticket/10285 <p> The following snippet seems to generate non monotonic local_date. </p> <p> I'm using boost 1.55 on linux. </p> <p> #include &lt;boost/date_time/local_time/local_time.hpp&gt; #include &lt;boost/ptr_container/ptr_vector.hpp&gt; </p> <p> int main() { </p> <blockquote> <p> const boost::local_time::time_zone_ptr theTimeZone( </p> <blockquote> <p> new boost::local_time::posix_time_zone( </p> <blockquote> <p> "CET+01CEST+01,M3.5.0/02:00,M10.5.0/03:00") </p> </blockquote> </blockquote> <p> ); </p> </blockquote> <blockquote> <p> boost::local_time::local_date_time myOldValue( </p> <blockquote> <p> boost::local_time::local_microsec_clock::local_time(theTimeZone)); </p> </blockquote> </blockquote> <blockquote> <p> for (size_t i = 0; ; ++i) { </p> <blockquote> <p> const boost::local_time::local_date_time myLocalTime = </p> <blockquote> <p> boost::local_time::local_microsec_clock::local_time(theTimeZone); </p> </blockquote> </blockquote> </blockquote> <blockquote> <blockquote> <p> if (myLocalTime &lt; myOldValue) { </p> <blockquote> <p> std::cout &lt;&lt; myOldValue &lt;&lt; std::endl; std::cout &lt;&lt; myLocalTime &lt;&lt; std::endl; std::cout &lt;&lt; boost::local_time::local_microsec_clock::local_time(theTimeZone) &lt;&lt; std::endl; std::cout &lt;&lt; "====================" &lt;&lt; std::endl; </p> </blockquote> <p> } </p> </blockquote> </blockquote> <blockquote> <blockquote> <p> myOldValue = myLocalTime; </p> </blockquote> <p> } </p> </blockquote> <p> } </p> <p> As you can see the program is not supposed to print anything ever, however this is what I'm getting: </p> <p> 2014-Jul-31 00:24:56.005625 CEST 2014-Jul-31 00:24:55.005631 CEST &lt;== 1 second back 2014-Jul-31 00:24:56.005946 CEST ==================== 2014-Jul-31 00:24:58.005625 CEST 2014-Jul-31 00:24:57.005629 CEST &lt;== 1 second back 2014-Jul-31 00:24:58.005824 CEST ==================== 2014-Jul-31 00:25:02.005624 CEST 2014-Jul-31 00:25:01.005628 CEST &lt;== 1 second back 2014-Jul-31 00:25:02.005838 CEST ==================== 2014-Jul-31 00:25:04.005625 CEST 2014-Jul-31 00:25:03.005630 CEST &lt;== 1 second back 2014-Jul-31 00:25:04.005826 CEST ==================== 2014-Jul-31 00:25:06.005624 CEST 2014-Jul-31 00:25:05.005633 CEST &lt;== 1 second back 2014-Jul-31 00:25:06.005853 CEST ==================== 2014-Jul-31 00:25:07.005625 CEST 2014-Jul-31 00:25:06.005631 CEST &lt;== 1 second back 2014-Jul-31 00:25:07.005846 CEST ==================== 2014-Jul-31 00:25:12.005625 CEST 2014-Jul-31 00:25:11.005631 CEST &lt;== 1 second back 2014-Jul-31 00:25:12.005822 CEST ==================== </p> <p> as you can see when the local_date is near 0.005631 second fraction it goes back of one second and then forward again on the following call. </p> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/10285 Trac 1.4.3 James E. King, III Sat, 06 Jan 2018 15:43:11 GMT owner, status changed https://svn.boost.org/trac10/ticket/10285#comment:1 https://svn.boost.org/trac10/ticket/10285#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> <li><strong>status</strong> <span class="trac-field-old">new</span> → <span class="trac-field-new">assigned</span> </li> </ul> <p> I can confirm this behavior in boost 1.66.0 with gcc-7.2 on Ubuntu Artful. It looks like a rounding error, as the difference between old, new, and current is approx. 1 second: </p> <pre class="wiki">jking@ubuntu:~/boost/libs/date_time/test$ ../../../bin.v2/libs/date_time/test/foo.test/gcc-gnu-7/debug/threadapi-pthread/foo 2018-Jan-06 16:40:15.004246000 CET 2018-Jan-06 16:40:14.004293000 CET 2018-Jan-06 16:40:15.004732000 CET ==================== 2018-Jan-06 16:40:16.003909000 CET 2018-Jan-06 16:40:15.003974000 CET 2018-Jan-06 16:40:16.004328000 CET ==================== 2018-Jan-06 16:40:24.004164000 CET 2018-Jan-06 16:40:23.004217000 CET 2018-Jan-06 16:40:24.004610000 CET ==================== 2018-Jan-06 16:40:25.003827000 CET 2018-Jan-06 16:40:24.003878000 CET 2018-Jan-06 16:40:25.004240000 CET ==================== </pre> Ticket