MCPcopy Create free account
hub / github.com/apache/impala / Format

Method Format

be/src/runtime/date-parse-util.cc:149–232  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

147}
148
149string DateParser::Format(const DateTimeFormatContext& dt_ctx, const DateValue& date) {
150 DCHECK(dt_ctx.toks.size() > 0);
151 DCHECK(dt_ctx.has_date_toks && !dt_ctx.has_time_toks);
152
153 int year, month, day;
154 if (!date.ToYearMonthDay(&year, &month, &day)) return "";
155
156 DCHECK(date.IsValid());
157 string result;
158 result.reserve(dt_ctx.fmt_out_len);
159 for (const DateTimeFormatToken& tok: dt_ctx.toks) {
160 int32_t num_val = -1;
161 switch (tok.type) {
162 case YEAR:
163 case ROUND_YEAR: {
164 num_val = AdjustYearToLength(year, tok.divisor);
165 break;
166 }
167 case QUARTER_OF_YEAR: {
168 num_val = GetQuarter(month);
169 break;
170 }
171 case MONTH_IN_YEAR: num_val = month; break;
172 case MONTH_NAME:
173 case MONTH_NAME_SHORT: {
174 result.append(FormatMonthName(month, tok));
175 break;
176 }
177 case WEEK_OF_YEAR: {
178 num_val = GetWeekOfYear(year, month, day);
179 break;
180 }
181 case WEEK_OF_MONTH: {
182 num_val = GetWeekOfMonth(day);
183 break;
184 }
185 case DAY_OF_WEEK: {
186 num_val = GetDayOfWeek(date);
187 break;
188 }
189 case DAY_IN_MONTH: num_val = day; break;
190 case DAY_IN_YEAR: {
191 num_val = GetDayInYear(year, month, day);
192 break;
193 }
194 case DAY_NAME:
195 case DAY_NAME_SHORT: {
196 result.append(FormatDayName(GetDayOfWeek(date), tok));
197 break;
198 }
199 case SEPARATOR: {
200 result.append(tok.val, tok.len);
201 break;
202 }
203 case TEXT: {
204 result.append(FormatTextToken(tok));
205 break;
206 }

Callers

nothing calls this directly

Calls 15

AdjustYearToLengthFunction · 0.85
GetQuarterFunction · 0.85
GetWeekOfYearFunction · 0.85
GetWeekOfMonthFunction · 0.85
GetDayInYearFunction · 0.85
FormatTextTokenFunction · 0.85
ToYearMonthDayMethod · 0.80
reserveMethod · 0.80
Iso8601WeekOfYearMethod · 0.80
WeekDayMethod · 0.80
sizeMethod · 0.45

Tested by

no test coverage detected