首页 > 其他 > 详细

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

时间:2014-04-13 09:29:07      阅读:558      评论:0      收藏:0      [点我收藏+]
#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();


}


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


bubuko.com,布布扣

boost准模板库date_period()(时间段使用 续1)时间段之间的关系运算,布布扣,bubuko.com

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

原文:http://blog.csdn.net/onlysingleboy/article/details/23565507

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!