Boost C++ Libraries: Ticket #4771: DST calculation inconsistencies https://svn.boost.org/trac10/ticket/4771 <p> One local_date_time constructor takes as argument a date and a time duration. However, its behaviour is not consistent. First, define a date prior to a DST change in the spring (one day prior is sufficient). Then assume you have to skip N minutes into the future, where N is large enough to get past the DST change. </p> <p> a) If you add floor(N/(24*60)) days to the date, and then construct a new local_date_time with the new date and N%(24*60) minutes, you get one result. </p> <p> b) If you construct a local_date_time with the original date and the N minutes (&gt;24*60) you get a second result. </p> <p> The results are different by one hour for regular EU DST rules. It seems like the constructor will not inspect DST rules unless the input date coincides with the DST change date. </p> <p> The effect: </p> <p> Instead of looping with one origin time + advancing time_duration, we have to advance the date whenever the number of minutes exceeds 24*60 and take modulo 24*60 for the duration in minutes. This produces the correct behaviour for our application. </p> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/4771 Trac 1.4.3 meisenbraun@… Sat, 19 Mar 2016 18:20:16 GMT <link>https://svn.boost.org/trac10/ticket/4771#comment:1 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/4771#comment:1</guid> <description> <p> Code to expose the issue: </p> <pre class="wiki">#include &lt;boost/date_time/local_time/local_time.hpp&gt; #include &lt;boost/date_time/posix_time/posix_time.hpp&gt; #include &lt;iostream&gt; #include &lt;cmath&gt; int main(int argc, char** argv ) { using namespace boost; using namespace boost::gregorian; using namespace boost::local_time; using namespace boost::posix_time; ptime sourceTime; tz_database db; db.load_from_file("date_time_zonespec.csv"); time_zone_ptr localTZ = db.time_zone_from_region("America/Chicago"); const unsigned int n = 26 * 60 +120; date preDST(2016,Mar,12); time_duration offset0 = hours(0); local_date_time dt0(preDST, offset0, localTZ, local_date_time::NOT_DATE_TIME_ON_ERROR); date date2 = preDST + days(std::floor(n/(24*60))); time_duration offset1 = minutes(n%(24*60)); local_date_time dt1(date2, offset1, localTZ, local_date_time::NOT_DATE_TIME_ON_ERROR); time_duration offset2 = minutes(n); local_date_time dt2(preDST, offset2, localTZ, local_date_time::NOT_DATE_TIME_ON_ERROR); std::cout &lt;&lt; "DT 0: " &lt;&lt; dt0 &lt;&lt; std::endl; std::cout &lt;&lt; "DT 1: " &lt;&lt; dt1 &lt;&lt; std::endl; // 04:00:00 CDT reported, 05:00:00 CDT expected std::cout &lt;&lt; "DT 2: " &lt;&lt; dt2 &lt;&lt; std::endl; // 05:00:00 CDT reported } </pre> </description> <category>Ticket</category> </item> </channel> </rss>