Skip to content

Commit

Permalink
Refs #21314. Protect current_time_since_unix_epoch against clock adju…
Browse files Browse the repository at this point in the history
…stments.

Signed-off-by: Miguel Company <[email protected]>
  • Loading branch information
MiguelCompany committed Aug 29, 2024
1 parent d5e2ecc commit 3d20ab3
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/cpp/utils/time_t_helpers.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,12 @@ static void current_time_since_unix_epoch(
{
using namespace std::chrono;

static const auto init_time_since_epoch = system_clock::now().time_since_epoch();
static const auto init_steady_time = steady_clock::now();

// Get time since epoch
auto t_since_epoch = system_clock::now().time_since_epoch();
auto t_elapsed = steady_clock::now() - init_steady_time;
auto t_since_epoch = init_time_since_epoch + t_elapsed;
// Get seconds
auto secs_t = duration_cast<seconds>(t_since_epoch);
// Remove seconds from time
Expand Down

0 comments on commit 3d20ab3

Please sign in to comment.