* Wraps `localtime` functionality for multiple platforms. This * converts a time value to a time structure in the local timezone. * If size(NPY_TIME_T) == 4, then years must be between 1970 and 2038. If * size(NPY_TIME_T) == 8, then years must be later than 1970. If the years are * not in this range, then get_localtime() will fail on some platforms. * * Returns 0 on success, -1 on failure.
| 73 | * [1] https://en.wikipedia.org/wiki/Year_2038_problem |
| 74 | */ |
| 75 | static int |
| 76 | get_localtime(NPY_TIME_T *ts, struct tm *tms) |
| 77 | { |
| 78 | char *func_name = "<unknown>"; |
| 79 | #if defined(_WIN32) |
| 80 | #if defined(_MSC_VER) && (_MSC_VER >= 1400) |
| 81 | if (localtime_s(tms, ts) != 0) { |
| 82 | func_name = "localtime_s"; |
| 83 | goto fail; |
| 84 | } |
| 85 | #elif defined(NPY_MINGW_USE_CUSTOM_MSVCR) |
| 86 | if (_localtime64_s(tms, ts) != 0) { |
| 87 | func_name = "_localtime64_s"; |
| 88 | goto fail; |
| 89 | } |
| 90 | #else |
| 91 | struct tm *tms_tmp; |
| 92 | tms_tmp = localtime(ts); |
| 93 | if (tms_tmp == NULL) { |
| 94 | func_name = "localtime"; |
| 95 | goto fail; |
| 96 | } |
| 97 | memcpy(tms, tms_tmp, sizeof(struct tm)); |
| 98 | #endif |
| 99 | #else |
| 100 | if (localtime_r(ts, tms) == NULL) { |
| 101 | func_name = "localtime_r"; |
| 102 | goto fail; |
| 103 | } |
| 104 | #endif |
| 105 | |
| 106 | return 0; |
| 107 | |
| 108 | fail: |
| 109 | PyErr_Format(PyExc_OSError, "Failed to use '%s' to convert " |
| 110 | "to a local time", func_name); |
| 111 | return -1; |
| 112 | } |
| 113 | |
| 114 | /* |
| 115 | * Converts a datetimestruct in UTC to a datetimestruct in local time, |
no outgoing calls
no test coverage detected