Created
July 28, 2010 13:07
-
-
Save alexdong/494430 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "boost/date_time/gregorian/gregorian.hpp" | |
#include "boost/date_time/posix_time/posix_time.hpp" | |
#include <boost/python.hpp> | |
#include <iostream> | |
#include <string> | |
int utc_date_str_to_int(const char* s, int offset) { | |
using namespace boost::gregorian; | |
using namespace boost::posix_time; | |
date base(2006, Jan, 1); | |
/* parse input strings into datetime object */ | |
ptime st = time_from_string(s); | |
/* offset the input time with timezone */ | |
ptime ct = st + hours(offset); | |
date cd = ct.date(); | |
days diff = cd - base; | |
return diff.days(); | |
} | |
BOOST_PYTHON_MODULE(plumrain) | |
{ | |
using namespace boost::python; | |
def("utc_date_str_to_int", utc_date_str_to_int); | |
} | |
int main() { | |
// std::cout << utc_str_to_date("2010-10-9 8:12:00", 10) << std::endl; | |
for(int i=0; i<10000; i++) { | |
utc_date_str_to_int("2010-10-9 17:12:00", 10); | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment