summaryrefslogtreecommitdiffstats
path: root/tests/samplebinding/date_conversions.h
diff options
context:
space:
mode:
Diffstat (limited to 'tests/samplebinding/date_conversions.h')
-rw-r--r--tests/samplebinding/date_conversions.h35
1 files changed, 35 insertions, 0 deletions
diff --git a/tests/samplebinding/date_conversions.h b/tests/samplebinding/date_conversions.h
new file mode 100644
index 00000000..ef459114
--- /dev/null
+++ b/tests/samplebinding/date_conversions.h
@@ -0,0 +1,35 @@
+namespace Shiboken {
+template <>
+struct PythonConverter<SbkDate>
+{
+ static bool isPythonConvertible(PyObject* pyObj)
+ {
+ if (!PyDateTimeAPI)
+ PyDateTime_IMPORT;
+
+ return PyDate_Check(pyObj);
+ }
+
+ static SbkDate* transformFromPython(PyObject* obj)
+ {
+ if (isPythonConvertible(obj)) {
+ int day = PyDateTime_GET_DAY(obj);
+ int month = PyDateTime_GET_MONTH(obj);
+ int year = PyDateTime_GET_YEAR(obj);
+ return new SbkDate(day, month, year);
+ }
+ return 0;
+ }
+
+ static PyObject* transformToPython(SbkDate* d)
+ {
+ if (d) {
+ if (!PyDateTimeAPI)
+ PyDateTime_IMPORT;
+
+ return PyDate_FromDate(d->day(), d->month(), d->year());
+ }
+ return 0;
+ }
+};
+}