Skip to content

Commit

Permalink
Epoch formatting: set whole seconds precision
Browse files Browse the repository at this point in the history
There was a change in fmt-10.0.0 which adds support for subsecond
precision printing.
Given that we want only whole seconds on the output round the time point
to `std::chrono::seconds`.

Closes: rpm-software-management#1020
  • Loading branch information
kontura committed Nov 20, 2023
1 parent 057da52 commit 596cab7
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion common/utils/string.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,8 @@ template <typename T>
inline std::string format_epoch(T epoch_num) {
if (std::in_range<time_t>(epoch_num)) {
const auto epoch = static_cast<time_t>(epoch_num);
return fmt::format("{:%F %X}", std::chrono::system_clock::from_time_t(epoch));
return fmt::format(
"{:%F %T}", std::chrono::round<std::chrono::seconds>(std::chrono::system_clock::from_time_t(epoch)));
}
return fmt::format("{} seconds since Unix epoch", epoch_num);
}
Expand Down

0 comments on commit 596cab7

Please sign in to comment.