-
I am working on a project where I read values into a vector of objects. I have a class structure that looks something like: class ReadHelper {
public:
ReadHelper() {}
virtual ~ReadHelper() {}
virtual nb::object Read(const hyperapi::Value &value) { return nb::none(); }
};
class IntegralReadHelper : public ReadHelper {
nb::object Read(const hyperapi::Value &value) {
if (value.isNull()) {
return nb::none();
}
return nb::int_(value.get<int64_t>());
}
};
class FloatReadHelper : public ReadHelper {
nb::object Read(const hyperapi::Value &value) {
if (value.isNull()) {
return nb::none();
}
return nb::float_(value.get<double>());
}
}; I am struggling to figure out how to extend this to datetime objects. I see #175 added a built in caster but I don't see how to use that outside of the Python<>C++ bridge. I also noticed |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
You would use the types from Did you see this part of the documentation? -> https://nanobind.readthedocs.io/en/latest/api_extra.html#timestamp-and-duration-conversions |
Beta Was this translation helpful? Give feedback.
You would use the types from
<chrono>
on the C++ side and then let the type caster convert them into their Python analogs at the C++<->Python transition. There currently isn't a wrapper class for datetime objects, you are welcome to propose one in a PR.Did you see this part of the documentation? -> https://nanobind.readthedocs.io/en/latest/api_extra.html#timestamp-and-duration-conversions