| 275 | |
| 276 | namespace { |
| 277 | std::string toStringAlt( |
| 278 | const Timestamp& t, |
| 279 | TimestampToStringOptions::Precision precision) { |
| 280 | auto seconds = t.getSeconds(); |
| 281 | std::tm tmValue; |
| 282 | BOLT_CHECK_NOT_NULL(gmtime_r((const time_t*)&seconds, &tmValue)); |
| 283 | auto width = static_cast<int>(precision); |
| 284 | auto value = precision == TimestampToStringOptions::Precision::kMilliseconds |
| 285 | ? t.getNanos() / 1'000'000 |
| 286 | : t.getNanos(); |
| 287 | std::ostringstream oss; |
| 288 | oss << std::put_time(&tmValue, "%F %T"); |
| 289 | oss << '.' << std::setfill('0') << std::setw(width) << value; |
| 290 | return oss.str(); |
| 291 | } |
| 292 | } // namespace |
| 293 | |
| 294 | TEST(TimestampTest, compareWithToStringAlt) { |