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.
| 129 | /// false if the conversion failed ('unix_time_micros' will be undefined), otherwise |
| 130 | /// true. |
| 131 | inline 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 | |
| 152 | inline bool TimestampValue::FloorUtcToUnixTimeMicros(int64_t* unix_time_micros) const { |
| 153 | DCHECK(unix_time_micros != nullptr); |