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

Method Format

be/src/runtime/timestamp-parse-util.cc:257–377  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

255}
256
257int TimestampParser::Format(const DateTimeFormatContext& dt_ctx, const date& d,
258 const time_duration& t, int max_length, char* dst) {
259 DCHECK(dt_ctx.toks.size() > 0);
260 if (dt_ctx.has_date_toks && d.is_special()) return -1;
261 if (dt_ctx.has_time_toks && t.is_special()) return -1;
262 int pos = 0;
263 char buff[12];
264 for (const DateTimeFormatToken& tok: dt_ctx.toks) {
265 int32_t num_val = -1;
266 switch (tok.type) {
267 case YEAR:
268 case ROUND_YEAR: {
269 num_val = AdjustYearToLength(d.year(), tok.divisor);
270 break;
271 }
272 case QUARTER_OF_YEAR: {
273 num_val = GetQuarter(d.month());
274 break;
275 }
276 case MONTH_IN_YEAR: num_val = d.month().as_number(); break;
277 case MONTH_NAME:
278 case MONTH_NAME_SHORT: {
279 AppendToBuffer(FormatMonthName(d.month().as_number(), tok), dst, pos, max_length);
280 break;
281 }
282 case WEEK_OF_YEAR: {
283 num_val = GetWeekOfYear(d.year(), d.month(), d.day());
284 break;
285 }
286 case WEEK_OF_MONTH: {
287 num_val = GetWeekOfMonth(d.day());
288 break;
289 }
290 case DAY_OF_WEEK: {
291 // Value in [1-7] where 1 represents Sunday, 2 represents Monday, etc.
292 num_val = d.day_of_week() + 1;
293 break;
294 }
295 case DAY_IN_MONTH: num_val = d.day(); break;
296 case DAY_IN_YEAR: {
297 num_val = GetDayInYear(d.year(), d.month(), d.day());
298 break;
299 }
300 case DAY_NAME:
301 case DAY_NAME_SHORT: {
302 AppendToBuffer(FormatDayName(d.day_of_week() + 1, tok), dst, pos, max_length);
303 break;
304 }
305 case HOUR_IN_DAY: num_val = t.hours(); break;
306 case HOUR_IN_HALF_DAY: {
307 num_val = t.hours();
308 if (num_val == 0) num_val = 12;
309 if (num_val > 12) num_val -= 12;
310 break;
311 }
312 case MERIDIEM_INDICATOR: {
313 const MERIDIEM_INDICATOR_TEXT* indicator_txt = (tok.len == 2) ? &AM : &AM_LONG;
314 if (t.hours() >= 12) {

Callers

nothing calls this directly

Calls 11

AdjustYearToLengthFunction · 0.85
GetQuarterFunction · 0.85
GetWeekOfYearFunction · 0.85
GetWeekOfMonthFunction · 0.85
GetDayInYearFunction · 0.85
FormatTextTokenFunction · 0.85
FastInt32ToBufferLeftFunction · 0.85
yearMethod · 0.80
monthMethod · 0.80
dayMethod · 0.80
sizeMethod · 0.45

Tested by

no test coverage detected