いいえだけを取得する方法はありますか。2 つのブースト日の間の平日の数。
以下では、暦日のみを取得しています。
date begin_dt(2011,Aug,3);
date end_dt(day_clock::local_day());
days duration=end_dt-begin_dt;
std::cout<<"calendar days between begin & end date are: "<<duration<<std::endl;
いいえだけを取得する方法はありますか。2 つのブースト日の間の平日の数。
以下では、暦日のみを取得しています。
date begin_dt(2011,Aug,3);
date end_dt(day_clock::local_day());
days duration=end_dt-begin_dt;
std::cout<<"calendar days between begin & end date are: "<<duration<<std::endl;
おそらく最も簡単な方法は、day_iterator を最初から最後まで実行することです。
#include <iostream>
#include <boost/date_time.hpp>
int main()
{
using namespace boost::gregorian;
date begin_dt(2011,Aug,3);
date end_dt(day_clock::local_day());
days duration=end_dt-begin_dt;
std::cout<<"calendar days between begin & end date are:" << duration << '\n';
int cnt=0;
for(day_iterator iter = begin_dt; iter!=end_dt; ++iter)
{
if( iter->day_of_week() != boost::date_time::Saturday
&& iter->day_of_week() != boost::date_time::Sunday)
++cnt;
}
std::cout << "of them " << cnt << " are weekdays\n";
}
翌週の開始日までの日数を差し引き、土曜日かそれ以前か日曜日かによって、1 日か 2 日を削除することができます。次に、残りの日数を 7 で割り、その数に 2 を掛けて、日数を引きます。残りの部分についても主張する必要があります。6(土)ならもう1つ外さなきゃいけない。簡単ではありませんが、アイデアは得られます。