36
36
#define PyInt_AsUnsignedLongLongMask PyLong_AsUnsignedLongLongMask
37
37
#endif
38
38
39
+ const int days_per_month_table [2 ][12 ] = {
40
+ { 31 , 28 , 31 , 30 , 31 , 30 , 31 , 31 , 30 , 31 , 30 , 31 },
41
+ { 31 , 29 , 31 , 30 , 31 , 30 , 31 , 31 , 30 , 31 , 30 , 31 }
42
+ };
43
+
39
44
/*
40
45
* Returns 1 if the given year is a leap year, 0 otherwise.
41
46
*/
@@ -52,7 +57,7 @@ int is_leapyear(npy_int64 year)
52
57
int dayofweek (int y , int m , int d )
53
58
{
54
59
int day ;
55
- static int t [] = {0 , 3 , 2 , 5 , 0 , 3 , 5 , 1 , 4 , 6 , 2 , 4 };
60
+ static const int t [] = {0 , 3 , 2 , 5 , 0 , 3 , 5 , 1 , 4 , 6 , 2 , 4 };
56
61
y -= m < 3 ;
57
62
day = (y + y /4 - y /100 + y /400 + t [m - 1 ] + d ) % 7 ;
58
63
// convert to python day
@@ -97,12 +102,12 @@ add_minutes_to_datetimestruct(pandas_datetimestruct *dts, int minutes)
97
102
dts -> month = 12 ;
98
103
}
99
104
isleap = is_leapyear (dts -> year );
100
- dts -> day += _days_per_month_table [isleap ][dts -> month - 1 ];
105
+ dts -> day += days_per_month_table [isleap ][dts -> month - 1 ];
101
106
}
102
107
else if (dts -> day > 28 ) {
103
108
isleap = is_leapyear (dts -> year );
104
- if (dts -> day > _days_per_month_table [isleap ][dts -> month - 1 ]) {
105
- dts -> day -= _days_per_month_table [isleap ][dts -> month - 1 ];
109
+ if (dts -> day > days_per_month_table [isleap ][dts -> month - 1 ]) {
110
+ dts -> day -= days_per_month_table [isleap ][dts -> month - 1 ];
106
111
dts -> month ++ ;
107
112
if (dts -> month > 12 ) {
108
113
dts -> year ++ ;
@@ -120,7 +125,7 @@ get_datetimestruct_days(const pandas_datetimestruct *dts)
120
125
{
121
126
int i , month ;
122
127
npy_int64 year , days = 0 ;
123
- int * month_lengths ;
128
+ const int * month_lengths ;
124
129
125
130
year = dts -> year - 1970 ;
126
131
days = year * 365 ;
@@ -160,7 +165,7 @@ get_datetimestruct_days(const pandas_datetimestruct *dts)
160
165
days += year / 400 ;
161
166
}
162
167
163
- month_lengths = _days_per_month_table [is_leapyear (dts -> year )];
168
+ month_lengths = days_per_month_table [is_leapyear (dts -> year )];
164
169
month = dts -> month - 1 ;
165
170
166
171
/* Add the months */
@@ -250,10 +255,11 @@ add_seconds_to_datetimestruct(pandas_datetimestruct *dts, int seconds)
250
255
static void
251
256
set_datetimestruct_days (npy_int64 days , pandas_datetimestruct * dts )
252
257
{
253
- int * month_lengths , i ;
258
+ const int * month_lengths ;
259
+ int i ;
254
260
255
261
dts -> year = days_to_yearsdays (& days );
256
- month_lengths = _days_per_month_table [is_leapyear (dts -> year )];
262
+ month_lengths = days_per_month_table [is_leapyear (dts -> year )];
257
263
258
264
for (i = 0 ; i < 12 ; ++ i ) {
259
265
if (days < month_lengths [i ]) {
@@ -348,7 +354,7 @@ convert_pydatetime_to_datetimestruct(PyObject *obj, pandas_datetimestruct *out,
348
354
}
349
355
isleap = is_leapyear (out -> year );
350
356
if (out -> day < 1 ||
351
- out -> day > _days_per_month_table [isleap ][out -> month - 1 ]) {
357
+ out -> day > days_per_month_table [isleap ][out -> month - 1 ]) {
352
358
goto invalid_date ;
353
359
}
354
360
0 commit comments