MCPcopy Create free account
hub / github.com/apache/orc / timestampToString

Function timestampToString

c++/test/TestConvertColumnReader.cc:1005–1030  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1003 }
1004
1005 static std::string timestampToString(int64_t seconds, int64_t nanos,
1006 const std::string& zoneName) {
1007 auto& timezone = getTimezoneByName(zoneName);
1008 seconds = timezone.convertToUTC(seconds);
1009 time_t t = static_cast<time_t>(seconds);
1010 char buffer[100];
1011 constexpr auto SECOND_IN_DAY = 3600 * 24;
1012 auto day = t < 0 ? (t - SECOND_IN_DAY + 1) / SECOND_IN_DAY : t / SECOND_IN_DAY;
1013
1014 auto [y, m, d] = civil_from_days(day);
1015 auto second_in_day = t % (3600 * 24);
1016 if (second_in_day < 0) {
1017 second_in_day += 3600 * 24;
1018 }
1019 auto h = second_in_day % (3600 * 24) / 3600;
1020 auto min = second_in_day % 3600 / 60;
1021 auto s = second_in_day % 60;
1022 std::snprintf(buffer, sizeof(buffer), "%04d-%02d-%02d %02ld:%02ld:%02ld", y, m, d, h, min, s);
1023 std::string result(buffer);
1024 if (nanos) {
1025 while (nanos % 10 == 0) nanos /= 10;
1026 result = result + "." + std::to_string(nanos);
1027 }
1028 result = result + " " + zoneName;
1029 return result;
1030 }
1031
1032 TEST(ConvertColumnReader, TestConvertStringVariantToTimestamp) {
1033 constexpr int DEFAULT_MEM_STREAM_SIZE = 10 * 1024 * 1024;

Callers 1

TESTFunction · 0.85

Calls 3

civil_from_daysFunction · 0.85
to_stringFunction · 0.50
convertToUTCMethod · 0.45

Tested by

no test coverage detected