It would be v helpful to have a Datetime conversion from D.
Looks like there is a macro for converting from ymd in
datetime.h, so I guess one could just write some code against
this API in C, D, or Cython and link it in with D so one can
transfer data structures over more easily.
I know just enough about that topic to be very scared.
I should be able to call these from D without changing PyD, I
think, for D to Python. Not sure about Python to D, but maybe.
https://github.com/ariovistus/pyd/blob/master/infrastructure/python/python.d
From D to Python datetime.datetime
===================================
PyObject *PyDate_FromDate()(int year, int month, int day) {
return PyDateTimeAPI.Date_FromDate(year, month, day,
PyDateTimeAPI.DateType);
}
PyObject *PyDateTime_FromDateAndTime()(int year, int month, int
day, int hour, int min, int sec, int usec) {
return PyDateTimeAPI.DateTime_FromDateAndTime(year, month, day,
hour,
min, sec, usec, Py_None, PyDateTimeAPI.DateTimeType);
}
From Python datetime.datetime to D
===================================
// D translations of C macros:
int PyDateTime_GET_YEAR()(PyObject *o) {
PyDateTime_Date *ot = cast(PyDateTime_Date *) o;
return (ot.data[0] << 8) | ot.data[1];
}
int PyDateTime_GET_MONTH()(PyObject *o) {
PyDateTime_Date *ot = cast(PyDateTime_Date *) o;
return ot.data[2];
}
int PyDateTime_GET_DAY()(PyObject *o) {
PyDateTime_Date *ot = cast(PyDateTime_Date *) o;
return ot.data[3];
}
int PyDateTime_DATE_GET_HOUR()(PyObject *o) {
PyDateTime_DateTime *ot = cast(PyDateTime_DateTime *) o;
return ot.data[4];
}
int PyDateTime_DATE_GET_MINUTE()(PyObject *o) {
PyDateTime_DateTime *ot = cast(PyDateTime_DateTime *) o;
return ot.data[5];
}
int PyDateTime_DATE_GET_SECOND()(PyObject *o) {
PyDateTime_DateTime *ot = cast(PyDateTime_DateTime *) o;
return ot.data[6];
}
int PyDateTime_DATE_GET_MICROSECOND()(PyObject *o) {
PyDateTime_DateTime *ot = cast(PyDateTime_DateTime *) o;
return (ot.data[7] << 16) | (ot.data[8] << 8) | ot.data[9];
}