Mantid
Loading...
Searching...
No Matches
DateAndTime.cpp
Go to the documentation of this file.
1// Mantid Repository : https://github.com/mantidproject/mantid
2//
3// Copyright © 2018 ISIS Rutherford Appleton Laboratory UKRI,
4// NScD Oak Ridge National Laboratory, European Spallation Source,
5// Institut Laue - Langevin & CSNS, Institute of High Energy Physics, CAS
6// SPDX - License - Identifier: GPL - 3.0 +
9#include <boost/python/class.hpp>
10#include <boost/python/make_constructor.hpp>
11#include <boost/python/operators.hpp> // Also provides self
12#include <cstddef>
13#include <memory>
14#include <numpy/arrayobject.h>
15#include <numpy/arrayscalars.h>
16
17using namespace Mantid::Types::Core;
18using namespace Mantid::PythonInterface;
19using namespace boost::python;
20using boost::python::arg;
21
28std::string ISO8601StringPlusSpace(const DateAndTime &self) {
29 // TODO this should cmake check and turn off the behavior
30 return self.toISO8601String() + " ";
31}
32
33int64_t total_nanoseconds(const DateAndTime &self) {
34 PyErr_Warn(PyExc_DeprecationWarning, ".total_nanoseconds() is deprecated. Use .totalNanoseconds() instead.");
35 return self.totalNanoseconds();
36}
37
39 class_<DateAndTime>("DateAndTime", no_init)
40 // Constructors
41 .def(init<const std::string>((arg("self"), arg("ISO8601 string")), "Construct from an ISO8601 string"))
42 .def(init<double, double>((arg("self"), arg("seconds"), arg("nanoseconds")),
43 "Construct using a number of seconds and nanoseconds (floats)since "
44 "1990-01-01T00:00"))
45 .def(init<int64_t, int64_t>((arg("self"), arg("seconds"), arg("nanoseconds")),
46 "Construct using a number of seconds and nanoseconds (integers) "
47 "since 1990-01-01T00:00"))
48 .def(init<int64_t>((arg("self"), arg("total_nanoseconds")),
49 "Construct a total number of nanoseconds since 1990-01-01T00:00"))
50 .def("__init__", make_constructor(Converters::to_dateandtime, default_call_policies(), (arg("other"))),
51 "Construct from numpy.datetime64")
52 .def("total_nanoseconds", &total_nanoseconds, arg("self"), "Since 1990-01-01T00:00")
53 .def("totalNanoseconds", &DateAndTime::totalNanoseconds, arg("self"), "Since 1990-01-01T00:00")
54 .def("toISO8601String", &DateAndTime::toISO8601String, arg("self"),
55 "Converts the time into ISO8601Standard and returns the string")
56 .def("setToMinimum", &DateAndTime::setToMinimum, arg("self"))
57 .def("to_datetime64", &Mantid::PythonInterface::Converters::to_datetime64, arg("self"),
58 "Convert to numpy.datetime64") // this is panda's name for the
59 // function
60 .def("__str__", &ISO8601StringPlusSpace, arg("self"))
61 .def("__long__", &DateAndTime::totalNanoseconds, arg("self"))
62 .def("__int__", &DateAndTime::totalNanoseconds, arg("self"))
63 .def(self == self)
64 .def(self != self)
65 // cppcheck-suppress duplicateExpression
66 .def(self < self)
67 .def(self + int64_t())
68 .def(self += int64_t())
69 .def(self - int64_t())
70 .def(self -= int64_t())
71 .def(self - self);
72}
73
74int64_t time_duration_total_nanoseconds(time_duration &self) {
75 PyErr_Warn(PyExc_DeprecationWarning, ".total_nanoseconds() is deprecated. Use .totalNanoseconds() instead.");
76 return self.total_nanoseconds();
77}
78
80 class_<time_duration>("time_duration", no_init)
81 .def("hours", &time_duration::hours, arg("self"), "Returns the normalized number of hours")
82 .def("minutes", &time_duration::minutes, arg("self"), "Returns the normalized number of minutes +/-(0..59)")
83 .def("seconds", &time_duration::seconds, arg("self"), "Returns the normalized number of seconds +/-(0..59)")
84 .def("total_seconds", &time_duration::total_seconds, arg("self"),
85 "Get the total number of seconds truncating any fractional seconds")
86 .def("total_milliseconds", &time_duration::total_milliseconds, arg("self"),
87 "Get the total number of milliseconds truncating any remaining "
88 "digits")
89 .def("total_microseconds", &time_duration::total_microseconds, arg("self"),
90 "Get the total number of microseconds truncating any remaining "
91 "digits")
92 .def("total_nanoseconds", &time_duration_total_nanoseconds, arg("self"),
93 "Get the total number of nanoseconds truncating any remaining "
94 "digits")
95 .def("totalNanoseconds", &time_duration::total_nanoseconds, arg("self"),
96 "Get the total number of nanoseconds truncating any remaining "
97 "digits");
98}
void export_DateAndTime()
Definition: DateAndTime.cpp:38
int64_t time_duration_total_nanoseconds(time_duration &self)
Definition: DateAndTime.cpp:74
std::string ISO8601StringPlusSpace(const DateAndTime &self)
Circumvent a bug in IPython 1.1, which chokes on nanosecond precision datetimes.
Definition: DateAndTime.cpp:28
int64_t total_nanoseconds(const DateAndTime &self)
Definition: DateAndTime.cpp:33
void export_time_duration()
Definition: DateAndTime.cpp:79
MANTID_PYTHONINTERFACE_CORE_DLL std::shared_ptr< Types::Core::DateAndTime > to_dateandtime(const boost::python::api::object &value)
Definition: DateAndTime.cpp:81
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.