https://gcc.gnu.org/bugzilla/show_bug.cgi?id=118811

--- Comment #16 from Nicholas Williams <nicholas at nicholaswilliams dot net> 
---
(In reply to Jonathan Wakely from comment #13)
> Unrelated to the lifetime bug, but why not just use utc_clock here?
> 
>   auto timestamp( std::chrono::duration_cast< std::chrono::nanoseconds >(
>     std::chrono::system_clock::now().time_since_epoch() ) );
>   std::chrono::zoned_time zt(
>     "UTC",
>     std::chrono::time_point_cast< std::chrono::microseconds >(
>       std::chrono::sys_time< std::chrono::nanoseconds >( timestamp ) ) );
>   return std::format( "{:%Y-%m-%dT%TZ}", zt );
> 
> 
> Why not simply:
> 
>   auto ut = std::chrono::utc_clock::now();
>   auto mut = std::chrono::time_point_cast<std::chrono::microseconds>(ut);
>   return std::format( "{:%Y-%m-%dT%TZ}", mut );
> 
> ?

Our exact use case is quite a bit more complicated than this. We don't have a
simplistic timestamp() method that does what the one in this example does. Log
events at creation are assigned a timestamp in nanoseconds based on our
pluggable time provider API (which just so happens to default to
std::chrono::system_clock::now().time_since_epoch()), and then perhaps many
seconds later at flush time those nanosecond timestamps are formatted into the
readable timestamp.

Reply via email to