1
1
#include "datetime.h"
2
+ #include "numpy/arrayobject.h"
3
+ #include "numpy/arrayscalars.h"
4
+ #include <stdio.h>
2
5
3
6
#if PY_MAJOR_VERSION >= 3
4
7
#define PyInt_AS_LONG PyLong_AsLong
@@ -9,15 +12,16 @@ void mangle_nat(PyObject *val) {
9
12
PyDateTime_GET_DAY (val ) = -1 ;
10
13
}
11
14
12
- long get_long_attr (PyObject * o , const char * attr ) {
13
- return PyInt_AS_LONG (PyObject_GetAttrString (o , attr ));
15
+ npy_int64 get_long_attr (PyObject * o , const char * attr ) {
16
+ PyObject * value = PyObject_GetAttrString (o , attr );
17
+ return PyLong_Check (value ) ? PyLong_AsLongLong (value ) : PyInt_AS_LONG (value );
14
18
}
15
19
16
- double total_seconds (PyObject * td ) {
20
+ npy_float64 total_seconds (PyObject * td ) {
17
21
// Python 2.6 compat
18
- long microseconds = get_long_attr (td , "microseconds" );
19
- long seconds = get_long_attr (td , "seconds" );
20
- long days = get_long_attr (td , "days" );
21
- long days_in_seconds = days * 24 * 3600 ;
22
+ npy_int64 microseconds = get_long_attr (td , "microseconds" );
23
+ npy_int64 seconds = get_long_attr (td , "seconds" );
24
+ npy_int64 days = get_long_attr (td , "days" );
25
+ npy_int64 days_in_seconds = days * 24LL * 3600LL ;
22
26
return (microseconds + (seconds + days_in_seconds ) * 1000000.0 ) / 1000000.0 ;
23
27
}
0 commit comments