2
2
"""
3
3
Cython implementations of functions resembling the stdlib calendar module
4
4
"""
5
- from libc.stdlib cimport abs as c_abs
6
5
cimport cython
7
6
from numpy cimport (
8
7
int32_t,
@@ -19,8 +18,7 @@ cdef int32_t* days_per_month_array = [
19
18
31 , 28 , 31 , 30 , 31 , 30 , 31 , 31 , 30 , 31 , 30 , 31 ,
20
19
31 , 29 , 31 , 30 , 31 , 30 , 31 , 31 , 30 , 31 , 30 , 31 ]
21
20
22
- cdef int * sakamoto_arr = [0 , 3 , 2 , 5 , 0 , 3 , 5 , 1 , 4 , 6 , 2 , 4 ]
23
- cdef int * em = [0 ,0 ,31 ,59 ,90 ,120 ,151 ,181 ,212 ,243 ,273 ,304 ,334 ]
21
+ cdef int * em = [0 , 0 , 31 , 59 , 90 , 120 , 151 , 181 , 212 , 243 , 273 , 304 , 334 ]
24
22
25
23
# The first 13 entries give the month days elapsed as of the first of month N
26
24
# (or the total number of days in the year for N=13) in non-leap years.
@@ -74,16 +72,18 @@ cpdef int32_t get_days_in_month(int year, Py_ssize_t month) noexcept nogil:
74
72
"""
75
73
return days_per_month_array[12 * is_leapyear(year) + month - 1 ]
76
74
75
+
77
76
@ cython.wraparound (False )
78
77
@ cython.boundscheck (False )
79
78
@ cython.cdivision (True )
80
79
cdef long quot(long a , long b) noexcept nogil:
81
80
cdef long x
82
- x = a/ b
83
- if ( a < 0 ):
84
- x -= ( a % b != 0 )
81
+ x = a/ b
82
+ if (a < 0 ):
83
+ x -= (a % b != 0 )
85
84
return x
86
85
86
+
87
87
@ cython.wraparound (False )
88
88
@ cython.boundscheck (False )
89
89
@ cython.cdivision (True )
@@ -115,23 +115,22 @@ cdef int dayofweek(int y, int m, int d) noexcept nogil:
115
115
[2] https://en.wikipedia.org/wiki/\
116
116
Determination_of_the_day_of_the_week#Gauss's_algorithm
117
117
"""
118
-
119
- cdef:
120
- long c
118
+ cdef:
119
+ long c
121
120
int g
122
121
int f
123
122
int e
124
-
123
+
125
124
if (m < 3 ):
126
125
y -= 1
127
-
128
- c = quot(y, 100 )
129
- g = y - quot(y, 100 ) * 100
126
+
127
+ c = quot(y, 100 )
128
+ g = y - quot(y, 100 ) * 100
130
129
f = 5 * (c - quot(c, 4 ) * 4 )
131
- e = em[m]
132
-
130
+ e = em[m]
131
+
133
132
if (m > 2 ):
134
- e -= 1 ;
133
+ e -= 1
135
134
return (- 1 + d + e + f + g + g/ 4 ) % 7
136
135
137
136
cdef bint is_leapyear(int64_t year) noexcept nogil:
0 commit comments