Conversation
| auto now_us = std::chrono::duration_cast<std::chrono::microseconds>(now.time_since_epoch()) % 1000000; | ||
| return os << std::put_time(std::localtime(&now_time_t), "%F %T") << "." << std::setw(6) << std::setfill('0') | ||
| << now_us.count(); | ||
| using namespace std::chrono; |
There was a problem hiding this comment.
Bad practice for middle-ware software developing.
DO NOT using namespace to avoid naming conflicting.
See https://google.github.io/styleguide/cppguide.html#Namespaces
Do not use using-directives (e.g., using namespace foo). Do not use inline namespaces.
There was a problem hiding this comment.
use namespace sc = std::chrono; instead for simplification.
There was a problem hiding this comment.
This is a bad indirection redefinition, and hurts readability. It's okay to just use std::chrono
| << now_us.count(); | ||
| #if __cplusplus >= 202002L | ||
| auto zt = std::chrono::zoned_time(std::chrono::current_zone(), std::chrono::floor<std::chrono::microseconds>(now)); | ||
| return os << std::format("{:%F %T}", zt); |
There was a problem hiding this comment.
Also should shows 6 decimal places (microseconds):
std::cout << chrono::format("{:%F %T}", zt); // prints up to seconds, no fraction
// To print fractional seconds:
// The standard chrono format supports floating-point seconds with `%S` by specifying precision:
std::cout << chrono::format("{:%F %H:%M:%S.%6f}", zt); // shows 6 decimal places (microseconds)There was a problem hiding this comment.
Decimals are added by default when printing std::chrono::zoned_time by "%S" with an accuracy of nanoseconds, so std::chrono::floor is used here to limit it to an accuracy of microseconds
| << now_us.count(); | ||
| #if __cplusplus >= 202002L | ||
| auto zt = std::chrono::zoned_time(std::chrono::current_zone(), std::chrono::floor<std::chrono::microseconds>(now)); | ||
| return os << std::format("{:%F %T}", zt); |

Uh oh!
There was an error while loading. Please reload this page.