10#include <boost/python.hpp>
13#define PY_ARRAY_UNIQUE_SYMBOL CORE_ARRAY_API
14#define NO_IMPORT_ARRAY
15#include <numpy/arrayobject.h>
16#include <numpy/arrayscalars.h>
19using Mantid::Types::Core::DateAndTime;
23const npy_datetime UNIX_EPOCH_NS = DateAndTime(
"1970-01-01T00:00").totalNanoseconds();
29 return static_cast<npy_datetime
>(dateandtime.totalNanoseconds()) - UNIX_EPOCH_NS;
34 PyObject *ret = PyArray_Scalar(
reinterpret_cast<char *
>(&abstime),
descr_ns(),
nullptr);
49std::shared_ptr<Types::Core::DateAndTime>
to_dateandtime(
const PyObject *datetime) {
51 if (!PyArray_IsScalar(datetime, Datetime)) {
53 throw std::runtime_error(
"Expected datetime64");
56 const auto *npdatetime =
reinterpret_cast<const PyDatetimeScalarObject *
>(datetime);
57 npy_datetime
value = npdatetime->obval;
60 switch (npdatetime->obmeta.base) {
76 throw std::runtime_error(
"Not implemented time unit");
78 return std::make_shared<DateAndTime>(UNIX_EPOCH_NS +
value);
82 boost::python::extract<Types::Core::DateAndTime> converter_dt(
value);
83 if (converter_dt.check()) {
84 return std::make_shared<DateAndTime>(converter_dt());
87 boost::python::extract<std::string> converter_str(
value);
88 if (converter_str.check()) {
89 return std::make_shared<DateAndTime>(converter_str());
92 boost::python::extract<double> converter_dbl(
value);
93 if (converter_dbl.check()) {
94 return std::make_shared<DateAndTime>(
static_cast<int64_t
>(converter_dbl()));
97 boost::python::extract<int64_t> converter_int64(
value);
98 if (converter_int64.check()) {
99 return std::make_shared<DateAndTime>(converter_int64());
102 boost::python::extract<int64_t> converter_int32(
value);
103 if (converter_int32.check()) {
104 return std::make_shared<DateAndTime>(converter_int32());
double value
The value of the point.
_PyArray_Descr PyArray_Descr
#define GNU_DIAG_OFF(x)
This is a collection of macros for turning compiler warnings off in a controlled manner.
MANTID_PYTHONINTERFACE_CORE_DLL PyArray_Descr * func_PyArray_Descr(const char *datadescr)
MANTID_PYTHONINTERFACE_CORE_DLL PyArray_Descr * descr_ns()
MANTID_PYTHONINTERFACE_CORE_DLL std::shared_ptr< Types::Core::DateAndTime > to_dateandtime(const boost::python::api::object &value)
MANTID_PYTHONINTERFACE_CORE_DLL PyObject * to_datetime64(const Types::Core::DateAndTime &dateandtime)
Convert to numpy's datetime64. This is panda's name for the function.
MANTID_PYTHONINTERFACE_CORE_DLL npy_datetime to_npy_datetime(const Types::Core::DateAndTime &dateandtime)
Total nanoseconds since the unix epoch.