|
20 | 20 | #include "include/StrType.hh" |
21 | 21 | #include "include/IntType.hh" |
22 | 22 | #include "include/PromiseType.hh" |
| 23 | +#include "include/DateType.hh" |
23 | 24 | #include "include/ExceptionType.hh" |
24 | 25 | #include "include/BufferType.hh" |
25 | 26 |
|
|
28 | 29 | #include <js/Proxy.h> |
29 | 30 |
|
30 | 31 | #include <Python.h> |
| 32 | +#include <datetime.h> // https://docs.python.org/3/c-api/datetime.html |
31 | 33 |
|
32 | 34 | #define HIGH_SURROGATE_START 0xD800 |
33 | 35 | #define LOW_SURROGATE_START 0xDC00 |
@@ -65,6 +67,8 @@ size_t UCS4ToUTF16(const uint32_t *chars, size_t length, uint16_t **outStr) { |
65 | 67 | } |
66 | 68 |
|
67 | 69 | JS::Value jsTypeFactory(JSContext *cx, PyObject *object) { |
| 70 | + PyDateTime_IMPORT; // for PyDateTime_Check |
| 71 | + |
68 | 72 | JS::RootedValue returnType(cx); |
69 | 73 |
|
70 | 74 | if (PyBool_Check(object)) { |
@@ -145,6 +149,10 @@ JS::Value jsTypeFactory(JSContext *cx, PyObject *object) { |
145 | 149 | JSObject *error = ExceptionType(object).toJsError(cx); |
146 | 150 | returnType.setObject(*error); |
147 | 151 | } |
| 152 | + else if (PyDateTime_Check(object)) { |
| 153 | + JSObject *dateObj = DateType(object).toJsDate(cx); |
| 154 | + returnType.setObject(*dateObj); |
| 155 | + } |
148 | 156 | else if (PyObject_CheckBuffer(object)) { |
149 | 157 | BufferType *pmBuffer = new BufferType(object); |
150 | 158 | JSObject *typedArray = pmBuffer->toJsTypedArray(cx); // may return null |
|
0 commit comments