Beispiel #1
0
void BoostDateTimeTestCase::test_gregorian_daysAlive()
{
    std::string s("2012-01-17");
    try 
    {
        boost::gregorian::date  birthday(boost::gregorian::from_simple_string(s));
        boost::gregorian::date  today = boost::gregorian::day_clock::local_day();
        boost::gregorian::days  days_alive = today - birthday;
        boost::gregorian::days  one_day(1);

        if(days_alive == one_day)
        {
            std::cout << "Born yesterday, very funny" << std::endl;
        }
        else if(days_alive < boost::gregorian::days(0))
        {
            std::cout << "Not born yet, hmm: " << days_alive.days() 
                      << " days" <<std::endl;
        }
        else
        {
            std::cout << "Days alive: " << days_alive.days() << std::endl;
        }

    }
    catch(...) 
    {
        std::cout << "Bad date entered: " << s << std::endl;
    }
}
 //! Return next kday given.
 date_type get_date(date_type start_day) const
 {
   duration_type one_day(1);
   date_type d = start_day - one_day;
   while (dow_ != d.day_of_week()) {
     d = d - one_day;
   }
   return d;
 }
 //! Return a concrete date when provided with a year specific year.
 date_type get_date(year_type year) const
 {
   date_type d(year, month_, calendar_type::end_of_month_day(year,month_));
   duration_type one_day(1);
   while (dow_ != d.day_of_week()) {
     d = d - one_day;
   }
   return d;
 }
 //! Return a concrete date when provided with a year specific year.
 date_type get_date(year_type year) const
 {
   date_type d(year, month_,1);
   duration_type one_day(1);
   while (dow_ != d.day_of_week()) {
     d = d + one_day;
   }
   return d;
 }
 //! Return a concrete date when provided with a year specific year.
 date_type get_date(year_type y) const
 {
   date_type d(y, month_, 1); //first day of month
   duration_type one_day(1);
   duration_type one_week(7);
   while (dow_ != d.day_of_week()) {
     d = d + one_day;
   }
   int week = 1;
   while (week < wn_) {
     d = d + one_week;
     week++;
   }
   // remove wrapping to next month behavior
   if(d.month() != month_) {
     d = d - one_week;
   }
   return d;
 }