* Adjusts a datetimestruct based on a minutes offset. Assumes * the current values are valid. */
| 2057 | * the current values are valid. |
| 2058 | */ |
| 2059 | NPY_NO_EXPORT void |
| 2060 | add_minutes_to_datetimestruct(npy_datetimestruct *dts, int minutes) |
| 2061 | { |
| 2062 | int isleap; |
| 2063 | |
| 2064 | dts->min += minutes; |
| 2065 | |
| 2066 | /* propagate invalid minutes into hour and day changes */ |
| 2067 | dts->hour += extract_unit_32(&dts->min, 60); |
| 2068 | dts->day += extract_unit_32(&dts->hour, 24); |
| 2069 | |
| 2070 | /* propagate invalid days into month and year changes */ |
| 2071 | if (dts->day < 1) { |
| 2072 | dts->month--; |
| 2073 | if (dts->month < 1) { |
| 2074 | dts->year--; |
| 2075 | dts->month = 12; |
| 2076 | } |
| 2077 | isleap = is_leapyear(dts->year); |
| 2078 | dts->day += _days_per_month_table[isleap][dts->month-1]; |
| 2079 | } |
| 2080 | else if (dts->day > 28) { |
| 2081 | isleap = is_leapyear(dts->year); |
| 2082 | if (dts->day > _days_per_month_table[isleap][dts->month-1]) { |
| 2083 | dts->day -= _days_per_month_table[isleap][dts->month-1]; |
| 2084 | dts->month++; |
| 2085 | if (dts->month > 12) { |
| 2086 | dts->year++; |
| 2087 | dts->month = 1; |
| 2088 | } |
| 2089 | } |
| 2090 | } |
| 2091 | } |
| 2092 | |
| 2093 | /* |
| 2094 | * Tests for and converts a Python datetime.datetime or datetime.date |
no test coverage detected