* Determines whether the 'divisor' metadata divides evenly into * the 'dividend' metadata. */
| 1202 | * the 'dividend' metadata. |
| 1203 | */ |
| 1204 | NPY_NO_EXPORT npy_bool |
| 1205 | datetime_metadata_divides( |
| 1206 | PyArray_DatetimeMetaData *dividend, |
| 1207 | PyArray_DatetimeMetaData *divisor, |
| 1208 | int strict_with_nonlinear_units) |
| 1209 | { |
| 1210 | npy_uint64 num1, num2; |
| 1211 | |
| 1212 | /* |
| 1213 | * Any unit can always divide into generic units. In other words, we |
| 1214 | * should be able to convert generic units into any more specific unit. |
| 1215 | */ |
| 1216 | if (dividend->base == NPY_FR_GENERIC) { |
| 1217 | return 1; |
| 1218 | } |
| 1219 | /* |
| 1220 | * However, generic units cannot always divide into more specific units. |
| 1221 | * We cannot safely convert datetimes with units back into generic units. |
| 1222 | */ |
| 1223 | else if (divisor->base == NPY_FR_GENERIC) { |
| 1224 | return 0; |
| 1225 | } |
| 1226 | |
| 1227 | num1 = (npy_uint64)dividend->num; |
| 1228 | num2 = (npy_uint64)divisor->num; |
| 1229 | |
| 1230 | /* If the bases are different, factor in a conversion */ |
| 1231 | if (dividend->base != divisor->base) { |
| 1232 | /* |
| 1233 | * Years and Months are incompatible with |
| 1234 | * all other units (except years and months are compatible |
| 1235 | * with each other). |
| 1236 | */ |
| 1237 | if (dividend->base == NPY_FR_Y) { |
| 1238 | if (divisor->base == NPY_FR_M) { |
| 1239 | num1 *= 12; |
| 1240 | } |
| 1241 | else if (strict_with_nonlinear_units) { |
| 1242 | return 0; |
| 1243 | } |
| 1244 | else { |
| 1245 | /* Could do something complicated here */ |
| 1246 | return 1; |
| 1247 | } |
| 1248 | } |
| 1249 | else if (divisor->base == NPY_FR_Y) { |
| 1250 | if (dividend->base == NPY_FR_M) { |
| 1251 | num2 *= 12; |
| 1252 | } |
| 1253 | else if (strict_with_nonlinear_units) { |
| 1254 | return 0; |
| 1255 | } |
| 1256 | else { |
| 1257 | /* Could do something complicated here */ |
| 1258 | return 1; |
| 1259 | } |
| 1260 | } |
| 1261 | else if (dividend->base == NPY_FR_M || divisor->base == NPY_FR_M) { |
no test coverage detected