summaryrefslogtreecommitdiffstats
path: root/tests/samplebinding/date_conversions.h
blob: ef459114a9b700d58d65eba080f7e524bb734db3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
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;
    }
};
}