Skip to content

Instantly share code, notes, and snippets.

@alexdong
Created July 28, 2010 13:07
Show Gist options
  • Save alexdong/494430 to your computer and use it in GitHub Desktop.
Save alexdong/494430 to your computer and use it in GitHub Desktop.
#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