MCPcopy Create free account
hub / github.com/numpy/numpy / add_minutes_to_datetimestruct

Function add_minutes_to_datetimestruct

numpy/core/src/multiarray/datetime.c:2059–2091  ·  view source on GitHub ↗

* Adjusts a datetimestruct based on a minutes offset. Assumes * the current values are valid. */

Source from the content-addressed store, hash-verified

2057 * the current values are valid.
2058 */
2059NPY_NO_EXPORT void
2060add_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

Calls 2

extract_unit_32Function · 0.85
is_leapyearFunction · 0.85

Tested by

no test coverage detected