Boost logo

Boost :

Subject: Re: [boost] [chrono/date] conversion between concrete dates
From: Roland Bock (rbock_at_[hidden])
Date: 2013-05-11 05:54:54

On 2013-05-08 18:08, Vicente J. Botet Escriba wrote:
> Hi,
> as the conversion between concrete dates could be expensive I guess
> that these conversion must be explicit.
> But this has some consequences when used the implicit conversion was
> hidden a not efficient implementation, e.g.
> date ISO_week_start = mon <= jan/day(4)/y;
> jan/day(4)/y should be ymd_date as is the efficient representation.
> The date generator was declared as
> date operator<=(weekday wd, date x);


Do you really want to allow/document/support/advocate the American date
format in C++? Why not restrict the format to something close to ISO
date format for ISO C++? That way you could introduce a new type, say
ym_type and

ym_type operator/(year y, month m);
date operator/(ym_type ym, day d);

Neither explicit nor implicit conversion necessary :-)

Another question I have about this is: Is is really a good idea to use
operator/()? It does prevent you from calculating ratios between
periods, e.g.

int ratio = year(3)/month(4); // ratio = 9

I'd therefore prefer another operator, e.g. operator <<

But to be completely honest: I don't see the benefit of constructing
dates this way. Why not simply use a constructor?

date(year, month, day);

With C++11 you could then write:

date ISO_week_start = mon <= { y, jan, day(4) };

That's the way I'd prefer :-)



Boost list run by bdawes at, gregod at, cpdaniel at, john at