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

Function days_to_yearsdays

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

* Modifies '*days_' to be the day offset within the year, * and returns the year. */

Source from the content-addressed store, hash-verified

194 * and returns the year.
195 */
196static npy_int64
197days_to_yearsdays(npy_int64 *days_)
198{
199 const npy_int64 days_per_400years = (400*365 + 100 - 4 + 1);
200 /* Adjust so it's relative to the year 2000 (divisible by 400) */
201 npy_int64 days = (*days_) - (365*30 + 7);
202 npy_int64 year;
203
204 /* Break down the 400 year cycle to get the year and day within the year */
205 year = 400 * extract_unit_64(&days, days_per_400years);
206
207 /* Work out the year/day within the 400 year cycle */
208 if (days >= 366) {
209 year += 100 * ((days-1) / (100*365 + 25 - 1));
210 days = (days-1) % (100*365 + 25 - 1);
211 if (days >= 365) {
212 year += 4 * ((days+1) / (4*365 + 1));
213 days = (days+1) % (4*365 + 1);
214 if (days >= 366) {
215 year += (days-1) / 365;
216 days = (days-1) % 365;
217 }
218 }
219 }
220
221 *days_ = days;
222 return year + 2000;
223}
224
225/* Extracts the month number from a 'datetime64[D]' value */
226NPY_NO_EXPORT int

Callers 2

days_to_month_numberFunction · 0.85
set_datetimestruct_daysFunction · 0.85

Calls 1

extract_unit_64Function · 0.85

Tested by

no test coverage detected