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

Function FormatSubSecond

be/src/util/time.cc:79–96  ·  view source on GitHub ↗

Format the sub-second part of a time point, at the precision specified by 'p'. The returned string is meant to be appended to the string returned by FormatSecond() above. Note that for time points before the Unix epoch 'subsecond' might have a negative value. In this case 'subsecond' has to be adjusted based on the precision.

Source from the content-addressed store, hash-verified

77// above. Note that for time points before the Unix epoch 'subsecond' might have a
78// negative value. In this case 'subsecond' has to be adjusted based on the precision.
79static string FormatSubSecond(int64_t subsecond, TimePrecision p) {
80 stringstream ss;
81 if (p == TimePrecision::Millisecond) {
82 if (subsecond < 0) subsecond = 1000 + subsecond;
83 ss << "." << std::setfill('0') << std::setw(3) << subsecond;
84 } else if (p == TimePrecision::Microsecond) {
85 if (subsecond < 0) subsecond = 1000000 + subsecond;
86 ss << "." << std::setfill('0') << std::setw(6) << subsecond;
87 } else if (p == TimePrecision::Nanosecond) {
88 if (subsecond < 0) subsecond = 1000000000 + subsecond;
89 ss << "." << std::setfill('0') << std::setw(9) << subsecond;
90 } else {
91 // 1-second precision or unknown unit. Return empty string.
92 DCHECK_EQ(TimePrecision::Second, p);
93 ss << "";
94 }
95 return ss.str();
96}
97
98// Convert time point 't' into date-time string at precision 'p'.
99// Output string is in UTC time zone if 'utc' is true, else it is in the

Callers 1

ToStringFunction · 0.85

Calls 1

strMethod · 0.45

Tested by

no test coverage detected