boost准模板库date_period()(时间段使用 续1)时间段之间的关系运算

来源:互联网 发布:php flash 上传 编辑:程序博客网 时间:2024/06/05 17:39
#define BOOST_DATE_TIME_SOURCE  #include<iostream>  #include<libs/date_time/src/gregorian/greg_names.hpp>  #include<libs/date_time/src/gregorian/date_generators.cpp>  #include<libs/date_time/src/gregorian/greg_month.cpp>  #include<libs/date_time/src/gregorian/greg_weekday.cpp>  #include<boost/date_time/gregorian/gregorian.hpp>  using namespace std;  using namespace boost::gregorian;  int main(){date d1(1991,5,1);days day(100);date_period dp(d1,day);cout<<dp<<endl;//移动前时间区间dp.shift(days(5));//向后移动5天cout<<dp<<endl;dp.shift(days(-10));//向前移动10天cout<<dp<<endl;cout<<dp.begin().day()<<endl;cout<<dp.length().days()<<endl;//区间大小dp.expand(days(10));//左右扩展10天cout<<dp<<endl;date birthday(1991,4,15);date mybirthday(1991,5,1);date temp(2010,1,1);date_period dp1(mybirthday,days(0));date_period dp2(birthday,days(0));date_period dp3(temp,days(10));dp1.expand(days(20));dp2.expand(days(20));cout<<"区间1   "<<dp1<<endl;cout<<"区间2   "<<dp2<<endl;cout<<"区间1是否在日期之前  "<<dp1.is_before(birthday)<<endl;//区间是否在某个日期之前cout<<"区间是否在日期之后   "<<dp1.is_after(birthday)<<endl;//区间是否在某个日期之后cout<<"日期是否在区间之内   "<<dp1.contains(birthday)<<endl;//区间是否包含日期cout<<"区间1是否包含区间2   "<<dp1.contains(dp2)<<endl;//区间是都包含另一个区间cout<<"区间之间是否有交集   "<<dp1.intersects(dp2)<<endl;//两个区间之间是否有交集cout<<"区间1 2之间的交集    "<<dp1.intersection(dp2)<<endl;//区间1 2之间的交集区间cout<<"区间之间是否相邻     "<<dp1.is_adjacent(dp2)<<endl;//区间是否相邻cout<<"区间之间的并集"<<dp1.merge(dp2)<<endl;//区间之间的并集,如果没有交集,并集是个无效区间cout<<"区间之间的并集"<<dp1.span(dp3)<<endl;//广义并集,填满两个区间间的间隔getchar();}


上面是对时间段之间以及时间段与时间之间的关系运算,运行结果如下:



0 0