11#include "datetime.h"
2+ #include "numpy/arrayobject.h"
3+ #include "numpy/arrayscalars.h"
4+ #include <stdio.h>
25
36#if PY_MAJOR_VERSION >= 3
47#define PyInt_AS_LONG PyLong_AsLong
@@ -9,15 +12,16 @@ void mangle_nat(PyObject *val) {
912 PyDateTime_GET_DAY (val ) = -1 ;
1013}
1114
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 );
1418}
1519
16- double total_seconds (PyObject * td ) {
20+ npy_float64 total_seconds (PyObject * td ) {
1721 // 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 ;
2226 return (microseconds + (seconds + days_in_seconds ) * 1000000.0 ) / 1000000.0 ;
2327}
0 commit comments