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

Function FastTimeToBuffer

be/src/gutil/strings/util.cc:590–665  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

588}
589
590char* FastTimeToBuffer(time_t s, char* buffer) {
591 if (s == 0) {
592 time(&s);
593 }
594
595 struct tm tm;
596 if (PortableSafeGmtime(&s, &tm) == nullptr) {
597 // Error message must fit in 30-char buffer.
598 memcpy(buffer, "Invalid:", sizeof("Invalid:"));
599 FastInt64ToBufferLeft(s, buffer+strlen(buffer));
600 return buffer;
601 }
602
603 // strftime format: "%a, %d %b %Y %H:%M:%S GMT",
604 // but strftime does locale stuff which we do not want
605 // plus strftime takes > 10x the time of hard code
606
607 const char* weekday_name = "Xxx";
608 switch (tm.tm_wday) {
609 default: { DLOG(FATAL) << "tm.tm_wday: " << tm.tm_wday; } break;
610 case 0: weekday_name = "Sun"; break;
611 case 1: weekday_name = "Mon"; break;
612 case 2: weekday_name = "Tue"; break;
613 case 3: weekday_name = "Wed"; break;
614 case 4: weekday_name = "Thu"; break;
615 case 5: weekday_name = "Fri"; break;
616 case 6: weekday_name = "Sat"; break;
617 }
618
619 const char* month_name = "Xxx";
620 switch (tm.tm_mon) {
621 default: { DLOG(FATAL) << "tm.tm_mon: " << tm.tm_mon; } break;
622 case 0: month_name = "Jan"; break;
623 case 1: month_name = "Feb"; break;
624 case 2: month_name = "Mar"; break;
625 case 3: month_name = "Apr"; break;
626 case 4: month_name = "May"; break;
627 case 5: month_name = "Jun"; break;
628 case 6: month_name = "Jul"; break;
629 case 7: month_name = "Aug"; break;
630 case 8: month_name = "Sep"; break;
631 case 9: month_name = "Oct"; break;
632 case 10: month_name = "Nov"; break;
633 case 11: month_name = "Dec"; break;
634 }
635
636 // Write out the buffer.
637
638 memcpy(buffer+0, weekday_name, 3);
639 buffer[3] = ',';
640 buffer[4] = ' ';
641
642 PutTwoDigits(tm.tm_mday, buffer+5);
643 buffer[7] = ' ';
644
645 memcpy(buffer+8, month_name, 3);
646 buffer[11] = ' ';
647

Callers

nothing calls this directly

Calls 4

timeFunction · 0.85
PortableSafeGmtimeFunction · 0.85
FastInt64ToBufferLeftFunction · 0.85
PutTwoDigitsFunction · 0.85

Tested by

no test coverage detected