Re: [Boost-bugs] [Boost C++ Libraries] #9584: date_time::difference produces incorrect values

Subject: Re: [Boost-bugs] [Boost C++ Libraries] #9584: date_time::difference produces incorrect values
From: Boost C++ Libraries (noreply_at_[hidden])
Date: 2014-01-20 20:03:28

#9584: date_time::difference produces incorrect values
  Reporter: Alexey Spiridonov <bstbg.20.lesha@…> | Owner: artyom
      Type: Bugs | Status: new
 Milestone: To Be Determined | Component: locale
   Version: Boost 1.54.0 | Severity: Problem
Resolution: | Keywords:

Comment (by Alexey Spiridonov <bstbg.20.lesha@…>):

 What does my *original* code print for you?

 a) I'm clearly not intending to use the current time, since I'm
 overwriting all of YMDHMS with the values from a fixed timestamp. The
 current time should have no effect on this code.

 b) How do you want me to be setting YMDHMS? The documentation does not
 suggest a better way to set all of YMDHMS together, and in any case, why
 is this incorrect? How can the results be different? If they can be, such
 an API is extremely unsafe to use (and the documentation again provides no

 c) I found no method that reveals the current back-end name. Can you
 suggest one? This is Ubuntu 13.10 with a full install of Boost, and ICU is
 installed also, so I assume that it's using ICU.

 d) The off-by-one-second error I originally reported is not so good (it
 might be due to rounding errors in the way I construct local_dt above),
 and I'd encourage you to actually try my original code to see if you can
 reproduce it. However, this seems even worse:

 #include <boost/locale.hpp>
 #include <iostream>

 int main(int argc, char **argv) {
   if (argc < 4) {
     return 1;

   using namespace std;
   using namespace boost::locale;

   locale loc = generator{}("");
   auto cal = (strlen(argv[3]) == 0) ? calendar(loc) : calendar(loc,

   date_time a((double)atoi(argv[1]), cal);
   date_time b((double)atoi(argv[2]), cal);

   cout << a << " - " << b << " = " << a.difference(b, period::second()) <<
     << b << " - " << a << " = " << b.difference(a, period::second()) <<
   return 0;

 Neither of its outputs is even remotely correct. If the library cannot
 handle a 40-year difference, it should probably throw rather than make up

 g++ -std=c++11 bug.cpp -o bug -lboost_locale; ./bug 0 1390247464 ''
 0 - 1.39025e+09 = 0
 1.39025e+09 - 0 = 536870912

Ticket URL: <>
Boost C++ Libraries <>
Boost provides free peer-reviewed portable C++ source libraries.

This archive was generated by hypermail 2.1.7 : 2017-02-16 18:50:15 UTC