Converts to Unix time (seconds since the Unix epoch) representation. Returns false if the conversion failed (unix_time will be undefined), otherwise true.
| 191 | /// Returns false if the conversion failed (unix_time will be undefined), otherwise |
| 192 | /// true. |
| 193 | inline bool TimestampValue::ToUnixTime(const Timezone* local_tz, |
| 194 | time_t* unix_time) const { |
| 195 | DCHECK(unix_time != nullptr); |
| 196 | if (UNLIKELY(!HasDateAndTime())) return false; |
| 197 | |
| 198 | if (local_tz == UTCPTR) { |
| 199 | return UtcToUnixTime(unix_time); |
| 200 | } |
| 201 | |
| 202 | cctz::civil_second cs(date_.year(), date_.month(), date_.day(), time_.hours(), |
| 203 | time_.minutes(), time_.seconds()); |
| 204 | cctz::time_point<cctz::sys_seconds> tp = cctz::convert(cs, *local_tz); |
| 205 | cctz::sys_seconds seconds = tp.time_since_epoch(); |
| 206 | *unix_time = seconds.count(); |
| 207 | return true; |
| 208 | } |
| 209 | |
| 210 | /// Converts to Unix time with fractional seconds. The time zone interpretation of the |
| 211 | /// TimestampValue instance is determined as above. |