* This provides the casting rules for the DATETIME data type units. */
| 1295 | * This provides the casting rules for the DATETIME data type units. |
| 1296 | */ |
| 1297 | NPY_NO_EXPORT npy_bool |
| 1298 | can_cast_datetime64_units(NPY_DATETIMEUNIT src_unit, |
| 1299 | NPY_DATETIMEUNIT dst_unit, |
| 1300 | NPY_CASTING casting) |
| 1301 | { |
| 1302 | switch (casting) { |
| 1303 | /* Allow anything with unsafe casting */ |
| 1304 | case NPY_UNSAFE_CASTING: |
| 1305 | return 1; |
| 1306 | |
| 1307 | /* |
| 1308 | * Can cast between all units with 'same_kind' casting. |
| 1309 | */ |
| 1310 | case NPY_SAME_KIND_CASTING: |
| 1311 | if (src_unit == NPY_FR_GENERIC || dst_unit == NPY_FR_GENERIC) { |
| 1312 | return src_unit == NPY_FR_GENERIC; |
| 1313 | } |
| 1314 | else { |
| 1315 | return 1; |
| 1316 | } |
| 1317 | |
| 1318 | /* |
| 1319 | * Casting is only allowed towards more precise units with 'safe' |
| 1320 | * casting. |
| 1321 | */ |
| 1322 | case NPY_SAFE_CASTING: |
| 1323 | if (src_unit == NPY_FR_GENERIC || dst_unit == NPY_FR_GENERIC) { |
| 1324 | return src_unit == NPY_FR_GENERIC; |
| 1325 | } |
| 1326 | else { |
| 1327 | return (src_unit <= dst_unit); |
| 1328 | } |
| 1329 | |
| 1330 | /* Enforce equality with 'no' or 'equiv' casting */ |
| 1331 | default: |
| 1332 | return src_unit == dst_unit; |
| 1333 | } |
| 1334 | } |
| 1335 | |
| 1336 | /* |
| 1337 | * This provides the casting rules for the TIMEDELTA data type units. |
no outgoing calls
no test coverage detected