* Modifies '*days_' to be the day offset within the year, * and returns the year. */
| 194 | * and returns the year. |
| 195 | */ |
| 196 | static npy_int64 |
| 197 | days_to_yearsdays(npy_int64 *days_) |
| 198 | { |
| 199 | const npy_int64 days_per_400years = (400*365 + 100 - 4 + 1); |
| 200 | /* Adjust so it's relative to the year 2000 (divisible by 400) */ |
| 201 | npy_int64 days = (*days_) - (365*30 + 7); |
| 202 | npy_int64 year; |
| 203 | |
| 204 | /* Break down the 400 year cycle to get the year and day within the year */ |
| 205 | year = 400 * extract_unit_64(&days, days_per_400years); |
| 206 | |
| 207 | /* Work out the year/day within the 400 year cycle */ |
| 208 | if (days >= 366) { |
| 209 | year += 100 * ((days-1) / (100*365 + 25 - 1)); |
| 210 | days = (days-1) % (100*365 + 25 - 1); |
| 211 | if (days >= 365) { |
| 212 | year += 4 * ((days+1) / (4*365 + 1)); |
| 213 | days = (days+1) % (4*365 + 1); |
| 214 | if (days >= 366) { |
| 215 | year += (days-1) / 365; |
| 216 | days = (days-1) % 365; |
| 217 | } |
| 218 | } |
| 219 | } |
| 220 | |
| 221 | *days_ = days; |
| 222 | return year + 2000; |
| 223 | } |
| 224 | |
| 225 | /* Extracts the month number from a 'datetime64[D]' value */ |
| 226 | NPY_NO_EXPORT int |
no test coverage detected