// Calctime.cpp : 定义控制台应用程序的入口点。
//
#include "stdafx.h"
#include <iostream>
#include <cmath>
#include <string>
#include <vector>
#include <sstream>
using namespace std;
struct Date{
int year;
int month;
int day;
};
int DAY[12] ={31,28,31,30,31,30,31,31,30,31,30,31};
class TimeSrv
{
public:
TimeSrv();
~TimeSrv();
static int DateDiff(string date1, string date2, const vector<string> &holiday_vec);
private:
static inline bool IsLeap(int year);
static inline bool StringToDate(const string &date, int& year, int& month, int& day);
static inline int ClaculateDays(Date date_max, Date date_min, const vector<string> &holiday_vec);
};
//IsLeap函数判断一个年份是否为闰年
bool TimeSrv::IsLeap(int year)
{
return (year % 4 ==0 || year % 400 ==0) && (year % 100 !=0);
}
//上面的StringToDate函数用于取出日期中的年月日并判断日期是否合法
//从字符中最得年月日 规定日期的格式是yyyymmdd
bool TimeSrv::StringToDate(const string &date, int& year, int& month, int& day)
{
if (date.length() < 8)
return false;
year = atoi((date.substr(0,4)).c_str());
month = atoi((date.
//
#include "stdafx.h"
#include <iostream>
#include <cmath>
#include <string>
#include <vector>
#include <sstream>
using namespace std;
struct Date{
int year;
int month;
int day;
};
int DAY[12] ={31,28,31,30,31,30,31,31,30,31,30,31};
class TimeSrv
{
public:
TimeSrv();
~TimeSrv();
static int DateDiff(string date1, string date2, const vector<string> &holiday_vec);
private:
static inline bool IsLeap(int year);
static inline bool StringToDate(const string &date, int& year, int& month, int& day);
static inline int ClaculateDays(Date date_max, Date date_min, const vector<string> &holiday_vec);
};
//IsLeap函数判断一个年份是否为闰年
bool TimeSrv::IsLeap(int year)
{
return (year % 4 ==0 || year % 400 ==0) && (year % 100 !=0);
}
//上面的StringToDate函数用于取出日期中的年月日并判断日期是否合法
//从字符中最得年月日 规定日期的格式是yyyymmdd
bool TimeSrv::StringToDate(const string &date, int& year, int& month, int& day)
{
if (date.length() < 8)
return false;
year = atoi((date.substr(0,4)).c_str());
month = atoi((date.