It's seems faster than the algorithm now in use.
The execute file and project file please see the attach.
DateValidate cost : 00:00:17.765546
boost_date_validate cost : 00:00:50.232232
Below is cpp source of the algorithm and test
----------------------------------------------------------------------------------------
#include
#include
#include
#include
#include <iostream>
#include <string>
#include
using namespace std;
using namespace boost;
using namespace boost::posix_time;
using namespace boost::gregorian;
int create_date()
{
int year=rand() %200+1900;
int month=rand() %20;
int day=rand() %40;
return year*10000+month*100+day;
}
void date_validate(int date)
{
static int daysOfMonth[] =
{
0,31,28,31,30,31,30,31,31,30,31,30,31
};
int monthDay = date % 10000;
if (monthDay >= 1300) throw bad_month();
if (monthDay > 1231) throw bad_day_of_month();
if (monthDay == 229)
{
int year = date / 10000;
if ( (year % 4) != 0) throw bad_day_of_month();
if (year %100 == 0 && year % 16 != 0) throw bad_day_of_month();
}
int month = monthDay / 100;
int day = monthDay % 100;
if (! (day > 0 && day <= daysOfMonth[month]) ) throw bad_day_of_month();
}
bool DateValidate (string date)
{
try
{
date_validate( lexical_cast<int> (date));
return true;
}
catch (...)
{
return false;
}
}
bool boost_date_validate (string date)
{
try
{
from_undelimited_string (date);
return true;
}
catch (...)
{
return false;
}
}
int main()
{
int n=1000000;
ptime createDateBegin (microsec_clock::local_time() );
for (int i=0;i