Boost logo

Boost Users :

From: Erik Thiele (erik.thiele_at_[hidden])
Date: 2019-05-22 12:30:56


hi

please compile this program:

#include <boost/date_time/posix_time/ptime.hpp>
#include <iostream>
#include <vector>

using namespace boost::posix_time;
using namespace std;

#define x(v) cout << #v << " : " << (v) << '\n';

int main(int argc, char *argv[])
{
  time_duration a(not_a_date_time);
  time_duration b;
  x(a<b);
  x(a>b);
  x(a<=b);
  x(a>=b);
  x(b<a);
  x(b>a);
  x(b<=a);
  x(b>=a);
  x(a==b);
  x(b==a);
  x(a.is_special());
  x(b.is_special());
  vector<time_duration> v0, v1;
  v0.push_back(time_duration());
  v0.push_back(time_duration(not_a_date_time));
  sort(v0.begin(), v0.end());
  v1.push_back(time_duration(not_a_date_time));
  v1.push_back(time_duration());
  sort(v1.begin(), v1.end());
  x(v0==v1);
  return 0;
}

the output is:

a<b : 0
a>b : 0
a<=b : 1
a>=b : 1
b<a : 0
b>a : 0
b<=a : 1
b>=a : 1
a==b : 0
b==a : 0
a.is_special() : 1
b.is_special() : 0
v0==v1 : 0

if the time_duration datatype is a complete partial order which is for
example needed for it to be able to be sorted, then the above output is
partly illegal:

if not a<b and not b<a then must be a=b. but this is not the case.

if a<=b and b<=a then must be a=b. but this is not the case.

so as expected the two vectors v0 and v1 are not equal after being
sorted even though they certainly should be!

i do not understand why time_duration is behaving in such a strange way
here.

I am using time_duration(not_a_date_time) as a SQL-NULL value just like
i am using date(not_a_date_time) and ptime(not_a_date_time) as SQL-NULL
values.

obviously I should not use time_duration(not_a_date_time). maybe this
is the reason why time_duration() != time_duration(not_a_date_time)? I
don't understand the design here. for example
date()==date(not_a_date_time) and also ptime()==ptime(not_a_date_time)
but not with time_duration. why???

why is there no documentation that time_duration is not a complete
partial order and thus not sortable - at least when using
not_a_date_time?

cya
erik


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net