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

Method UtcToUnixTimeMicros

be/src/runtime/timestamp-value.inline.h:131–150  ·  view source on GitHub ↗

Interpret 'this' as a timestamp in UTC and convert to unix time in microseconds. Nanoseconds are rounded to the nearest microsecond supported by Impala. Returns false if the conversion failed ('unix_time_micros' will be undefined), otherwise true.

Source from the content-addressed store, hash-verified

129/// false if the conversion failed ('unix_time_micros' will be undefined), otherwise
130/// true.
131inline bool TimestampValue::UtcToUnixTimeMicros(int64_t* unix_time_micros) const {
132 const static int64_t MAX_UNIXTIME = 253402300799; // 9999-12-31 23:59:59
133 const static int64_t MAX_UNIXTIME_MICROS =
134 MAX_UNIXTIME * MICROS_PER_SEC + (MICROS_PER_SEC - 1);
135
136 DCHECK(unix_time_micros != nullptr);
137 time_t unixtime_seconds;
138 if (UNLIKELY(!UtcToUnixTime(&unixtime_seconds))) return false;
139
140 DCHECK(HasTime());
141 *unix_time_micros =
142 (static_cast<int64_t>(unixtime_seconds) * MICROS_PER_SEC) +
143 ((time_.fractional_seconds() + (NANOS_PER_MICRO / 2)) / NANOS_PER_MICRO);
144
145 // Rounding may result in the timestamp being MAX_UNIXTIME_MICROS+1 and should be
146 // truncated.
147 DCHECK_LE(*unix_time_micros, MAX_UNIXTIME_MICROS + 1);
148 *unix_time_micros = std::min(MAX_UNIXTIME_MICROS, *unix_time_micros);
149 return true;
150}
151
152inline bool TimestampValue::FloorUtcToUnixTimeMicros(int64_t* unix_time_micros) const {
153 DCHECK(unix_time_micros != nullptr);

Callers 5

UtcToUnixMicrosMethod · 0.80
TestFromDoubleUnixTimeFunction · 0.80
RoundToMicrosFunction · 0.80
TESTFunction · 0.80

Calls 1

minFunction · 0.85

Tested by 3

TestFromDoubleUnixTimeFunction · 0.64
RoundToMicrosFunction · 0.64
TESTFunction · 0.64