* Gets a tzoffset in minutes by calling the fromutc() function on * the Python datetime.tzinfo object. */
| 2323 | * the Python datetime.tzinfo object. |
| 2324 | */ |
| 2325 | NPY_NO_EXPORT int |
| 2326 | get_tzoffset_from_pytzinfo(PyObject *timezone_obj, npy_datetimestruct *dts) |
| 2327 | { |
| 2328 | PyObject *dt, *loc_dt; |
| 2329 | npy_datetimestruct loc_dts; |
| 2330 | |
| 2331 | /* Create a Python datetime to give to the timezone object */ |
| 2332 | dt = PyDateTime_FromDateAndTime((int)dts->year, dts->month, dts->day, |
| 2333 | dts->hour, dts->min, 0, 0); |
| 2334 | if (dt == NULL) { |
| 2335 | return -1; |
| 2336 | } |
| 2337 | |
| 2338 | /* Convert the datetime from UTC to local time */ |
| 2339 | loc_dt = PyObject_CallMethod(timezone_obj, "fromutc", "O", dt); |
| 2340 | Py_DECREF(dt); |
| 2341 | if (loc_dt == NULL) { |
| 2342 | return -1; |
| 2343 | } |
| 2344 | |
| 2345 | /* Convert the local datetime into a datetimestruct */ |
| 2346 | if (convert_pydatetime_to_datetimestruct(loc_dt, &loc_dts, NULL, 0) < 0) { |
| 2347 | Py_DECREF(loc_dt); |
| 2348 | return -1; |
| 2349 | } |
| 2350 | |
| 2351 | Py_DECREF(loc_dt); |
| 2352 | |
| 2353 | /* Calculate the tzoffset as the difference between the datetimes */ |
| 2354 | return (int)(get_datetimestruct_minutes(&loc_dts) - |
| 2355 | get_datetimestruct_minutes(dts)); |
| 2356 | } |
| 2357 | |
| 2358 | /* |
| 2359 | * Converts a PyObject * into a datetime, in any of the forms supported. |
no test coverage detected