* Sorts the array of dates provided in place and removes * NaT, duplicates and any date which is already excluded on account * of the weekmask. * * Returns the number of dates left after removing weekmask-excluded * dates. */
| 221 | * dates. |
| 222 | */ |
| 223 | NPY_NO_EXPORT void |
| 224 | normalize_holidays_list(npy_holidayslist *holidays, npy_bool *weekmask) |
| 225 | { |
| 226 | npy_datetime *dates = holidays->begin; |
| 227 | npy_intp count = holidays->end - dates; |
| 228 | |
| 229 | npy_datetime lastdate = NPY_DATETIME_NAT; |
| 230 | npy_intp trimcount, i; |
| 231 | int day_of_week; |
| 232 | |
| 233 | /* Sort the dates */ |
| 234 | qsort(dates, count, sizeof(npy_datetime), &qsort_datetime_compare); |
| 235 | |
| 236 | /* Sweep through the array, eliminating unnecessary values */ |
| 237 | trimcount = 0; |
| 238 | for (i = 0; i < count; ++i) { |
| 239 | npy_datetime date = dates[i]; |
| 240 | |
| 241 | /* Skip any NaT or duplicate */ |
| 242 | if (date != NPY_DATETIME_NAT && date != lastdate) { |
| 243 | /* Get the day of the week (1970-01-05 is Monday) */ |
| 244 | day_of_week = (int)((date - 4) % 7); |
| 245 | if (day_of_week < 0) { |
| 246 | day_of_week += 7; |
| 247 | } |
| 248 | |
| 249 | /* |
| 250 | * If the holiday falls on a possible business day, |
| 251 | * then keep it. |
| 252 | */ |
| 253 | if (weekmask[day_of_week] == 1) { |
| 254 | dates[trimcount++] = date; |
| 255 | lastdate = date; |
| 256 | } |
| 257 | } |
| 258 | } |
| 259 | |
| 260 | /* Adjust the end of the holidays array */ |
| 261 | holidays->end = dates + trimcount; |
| 262 | } |
| 263 | |
| 264 | /* |
| 265 | * Converts a Python input into a non-normalized list of holidays. |
no outgoing calls
no test coverage detected