MCPcopy Create free account
hub / github.com/Meituan-Dianping/SQLAdvisor / get_date_from_daynr

Function get_date_from_daynr

sql/sql_time.cc:148–188  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

146 /* Daynr 0 is returned as date 00.00.00 */
147
148void get_date_from_daynr(long daynr,uint *ret_year,uint *ret_month,
149 uint *ret_day)
150{
151 uint year,temp,leap_day,day_of_year,days_in_year;
152 uchar *month_pos;
153 DBUG_ENTER("get_date_from_daynr");
154
155 if (daynr <= 365L || daynr >= 3652500)
156 { /* Fix if wrong daynr */
157 *ret_year= *ret_month = *ret_day =0;
158 }
159 else
160 {
161 year= (uint) (daynr*100 / 36525L);
162 temp=(((year-1)/100+1)*3)/4;
163 day_of_year=(uint) (daynr - (long) year * 365L) - (year-1)/4 +temp;
164 while (day_of_year > (days_in_year= calc_days_in_year(year)))
165 {
166 day_of_year-=days_in_year;
167 (year)++;
168 }
169 leap_day=0;
170 if (days_in_year == 366)
171 {
172 if (day_of_year > 31+28)
173 {
174 day_of_year--;
175 if (day_of_year == 31+28)
176 leap_day=1; /* Handle leapyears leapday */
177 }
178 }
179 *ret_month=1;
180 for (month_pos= days_in_month ;
181 day_of_year > (uint) *month_pos ;
182 day_of_year-= *(month_pos++), (*ret_month)++)
183 ;
184 *ret_year=year;
185 *ret_day=day_of_year+leap_day;
186 }
187 DBUG_VOID_RETURN;
188}
189
190 /* Functions to handle periods */
191

Callers 3

date_add_intervalFunction · 0.85
mix_date_and_timeFunction · 0.85
extract_date_timeFunction · 0.85

Calls 1

calc_days_in_yearFunction · 0.85

Tested by

no test coverage detected