| 76 | } |
| 77 | |
| 78 | std::string UtcTimestamp::ToIsoDateTime(bool include_ms) const { |
| 79 | const auto ms_sec = (utc_timestamp_ / 1'000'000) % 1'000; |
| 80 | const auto system_time = static_cast<std::time_t>(utc_timestamp_ / 1'000'000'000); |
| 81 | std::ostringstream text; |
| 82 | if (struct tm *bt = std::gmtime(&system_time); |
| 83 | bt != nullptr ) { |
| 84 | text << std::put_time(bt, "%Y-%m-%dT%H:%M:%S"); |
| 85 | } |
| 86 | if (ms_sec > 0 && include_ms) { |
| 87 | text << '.' << std::setfill('0') << std::setw(3) << ms_sec; |
| 88 | } |
| 89 | text << "Z"; |
| 90 | return text.str(); |
| 91 | } |
| 92 | |
| 93 | void UtcTimestamp::FromIsoDateTime(const std::string &date_time) { |
| 94 | enum DateState { |