Boost logo

Boost :

From: Jeff Garland (jeff_at_[hidden])
Date: 2006-03-26 17:59:40

On Sun, 26 Mar 2006 22:25:13 +0000 (UTC), george wrote
> > template<class point_rep, class duration_rep>
> > inline
> > void period<point_rep,duration_rep>::expand(const duration_rep& d)
> > {
> > begin_ = begin_ - d;
> > last_ = last_ + d;
> > }
> >
> > Jeff
> thanks Jeff,nice patch.
> but if I want period to get smaller?
> I have to go with a tmp period object?
> are you planing to add a method for this also?
> I don't want to play with boost::date_time and do it by myself
> becouse the source will be open to others and I want to use the
> 'standard' boost. this patch will be in 1.34?

Well, you could write a 'contract' method. However, contract is much more
dangerous in that there is the possibility of making an ill formed period.
I'd stick with the temporary object approach -- you can easily write this into
your own little functions that hide the details. Something like this:

contract(const date_period& dp, days len)
   if (dp.length() < len) {
     //handle errors here -- after contraction nothing is left...
   return date_period(dp.start() + len, dp.end()-len);

In use:
  date_period dp(....);
  dp = contract(dp, days(2));

expand won't be in 1.34 b/c we've already had a feature freeze. For now you
could trivially write the expand as I'm suggesting above.


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