MCPcopy Create free account
hub / github.com/catboost/catboost / FindYear

Method FindYear

util/datetime/systime.cpp:157–172  ·  view source on GitHub ↗

lookup year by days since epoch, decrement day counter to the corresponding amount of days. The method returns the last year in the table, if year is too big

Source from the content-addressed store, hash-verified

155 // lookup year by days since epoch, decrement day counter to the corresponding amount of days.
156 // The method returns the last year in the table, if year is too big
157 int FindYear(ui32& days) const {
158 const ui32 yearIndex = days / DAYS_IN_LEAP_YEAR;
159
160 // we can miss by at most 1 year
161 Y_ASSERT(yearIndex < TableSize);
162 if (const auto diff = DaysSinceEpoch[yearIndex]; diff <= days) {
163 days -= diff;
164 return static_cast<int>(yearIndex + StartYear + 1);
165 }
166
167 if (yearIndex > 0) {
168 days -= DaysSinceEpoch[yearIndex - 1];
169 }
170
171 return static_cast<int>(yearIndex + StartYear);
172 }
173 };
174
175 constexpr TDayNoToYearLookupTable DAYS_TO_YEAR_LOOKUP;

Callers 1

GmTimeRFunction · 0.80

Calls

no outgoing calls

Tested by

no test coverage detected