SlHelpers
Loading...
Searching...
No Matches
pybindSupp.h
1// SPDX-License-Identifier: GPL-2.0-only
2
3#pragma once
4
5#include <chrono>
6
7#include <pybind11/pybind11.h>
8
9namespace pybind11::detail {
10
12template <> struct type_caster<std::chrono::year_month_day> {
14 PYBIND11_TYPE_CASTER(std::chrono::year_month_day, _("datetime.date"));
16 static handle cast(std::chrono::year_month_day ymd, return_value_policy, handle) {
17 return pybind11::module_::import("datetime").attr("date")(
18 int(ymd.year()),
19 unsigned(ymd.month()),
20 unsigned(ymd.day())
21 ).release();
22 }
23};
24
25}
static handle cast(std::chrono::year_month_day ymd, return_value_policy, handle)
Casts a std::chrono::year_month_day to a Python datetime.date object.
Definition pybindSupp.h:16
PYBIND11_TYPE_CASTER(std::chrono::year_month_day, _("datetime.date"))
The necessary boilerplate for casting std::chrono::year_month_day to Python.