diff --git a/include/pybind11/chrono.h b/include/pybind11/chrono.h index d82f14309..e60db3fa0 100644 --- a/include/pybind11/chrono.h +++ b/include/pybind11/chrono.h @@ -23,7 +23,7 @@ public: bool load(handle src, bool) { using namespace std::chrono; - PyDateTime_IMPORT; + if(!PyDateTimeAPI) { PyDateTime_IMPORT; } if (!src) return false; if (PyDelta_Check(src.ptr())) { @@ -41,7 +41,7 @@ public: static handle cast(const std::chrono::duration &src, return_value_policy /* policy */, handle /* parent */) { using namespace std::chrono; - PyDateTime_IMPORT; + if(!PyDateTimeAPI) { PyDateTime_IMPORT; } // Declare these special duration types so the conversions happen with the correct primitive types (int) typedef duration> dd_t; @@ -61,7 +61,7 @@ public: typedef std::chrono::time_point type; bool load(handle src, bool) { using namespace std::chrono; - PyDateTime_IMPORT; + if(!PyDateTimeAPI) { PyDateTime_IMPORT; } if (!src) return false; if (PyDateTime_Check(src.ptr())) { @@ -82,7 +82,7 @@ public: static handle cast(const std::chrono::time_point &src, return_value_policy /* policy */, handle /* parent */) { using namespace std::chrono; - PyDateTime_IMPORT; + if(!PyDateTimeAPI) { PyDateTime_IMPORT; } time_t tt = system_clock::to_time_t(src); // this function uses static memory so it's best to copy it out asap just in case @@ -108,7 +108,7 @@ public: typedef std::chrono::time_point type; bool load(handle src, bool) { using namespace std::chrono; - PyDateTime_IMPORT; + if(!PyDateTimeAPI) { PyDateTime_IMPORT; } if (!src) return false; if (PyTime_Check(src.ptr())) { @@ -125,7 +125,7 @@ public: static handle cast(const std::chrono::time_point &src, return_value_policy /* policy */, handle /* parent */) { using namespace std::chrono; - PyDateTime_IMPORT; + if(!PyDateTimeAPI) { PyDateTime_IMPORT; } // Declare these special duration types so the conversions happen with the correct primitive types (int) typedef duration> hh_t;