MCPcopy Create free account
hub / github.com/pybind/pybind11 / load

Method load

include/pybind11/chrono.h:33–59  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

31 using days = std::chrono::duration<int_least32_t, std::ratio<86400>>;
32
33 bool load(handle src, bool) {
34 using namespace std::chrono;
35
36 // Lazy initialise the PyDateTime import
37 if (!PyDateTimeAPI) {
38 PyDateTime_IMPORT;
39 }
40
41 if (!src) {
42 return false;
43 }
44 // If invoked with datetime.delta object
45 if (PyDelta_Check(src.ptr())) {
46 value = type(duration_cast<duration<rep, period>>(
47 days(PyDateTime_DELTA_GET_DAYS(src.ptr()))
48 + seconds(PyDateTime_DELTA_GET_SECONDS(src.ptr()))
49 + microseconds(PyDateTime_DELTA_GET_MICROSECONDS(src.ptr()))));
50 return true;
51 }
52 // If invoked with a float we assume it is seconds and convert
53 if (PyFloat_Check(src.ptr())) {
54 value = type(duration_cast<duration<rep, period>>(
55 duration<double>(PyFloat_AsDouble(src.ptr()))));
56 return true;
57 }
58 return false;
59 }
60
61 // If this is a duration just return it back
62 static const std::chrono::duration<rep, period> &

Callers

nothing calls this directly

Calls 2

ptrMethod · 0.80
typeClass · 0.70

Tested by

no test coverage detected