Boost logo

Boost :

Subject: [boost] [chrono/date] validated versus valid dates
From: Vicente J. Botet Escriba (vicente.botet_at_[hidden])
Date: 2013-05-05 16:01:43


Hi,

Allowing to build dates that are not validated doesn't mean that they
are not valid. A validated date is always valid. E.g

   date d(year(2013), may, day(5));

d is not a validated date but is valid.

Having a is_validated() function in addition to is_valid() could have
its uses

   assert( ! d.is_validated() && d.is_valid() );

is_validated() function forces to use a bit to store this information on
the date representation, but it improves the performances of the
is_valid() function.

Moving from a possible unvalidated to a validated one would need

   date d1;
   ...
   date d2(d1.year(), d1.month(), d1.day(), check);

Instead of this a validate factory makes this clearer

   date d1;
   ...
   date d2 = validate(d1);

date validate(date const& dt)
{
   if (dt.is_validated()) return *this;
   else if (dt.is_valid())
   {
     date res(dt);
     res.set_validated_(); // this is private
     return res;
   }
   throw bad_date();
}

Best,
Vicente


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk