diff --git a/td/telegram/Global.cpp b/td/telegram/Global.cpp index 18187122..81036187 100644 --- a/td/telegram/Global.cpp +++ b/td/telegram/Global.cpp @@ -93,7 +93,7 @@ Status Global::init(const TdParameters ¶meters, ActorId td, unique_ptrget_binlog_pmc()->get("server_time_difference"); - auto system_time = Clocks::system(); + auto system_time = max(1577285000.0, Clocks::system()); auto default_time_difference = system_time - Time::now(); if (saved_diff_str.empty()) { server_time_difference_ = default_time_difference; @@ -128,7 +128,7 @@ void Global::update_server_time_difference(double diff) { void Global::save_server_time() { auto t = Time::now(); - if (system_time_saved_at_.load(std::memory_order_relaxed) + 10 < t) { + if (server_time_difference_was_updated_ && system_time_saved_at_.load(std::memory_order_relaxed) + 10 < t) { system_time_saved_at_ = t; do_save_server_time_difference(); } diff --git a/td/telegram/Global.h b/td/telegram/Global.h index 8b428ab3..8cd6e3cf 100644 --- a/td/telegram/Global.h +++ b/td/telegram/Global.h @@ -409,7 +409,7 @@ class Global : public ActorContext { std::atomic dns_time_difference_{0.0}; std::atomic dns_time_difference_was_updated_{false}; std::atomic close_flag_{false}; - std::atomic system_time_saved_at_{0.0}; + std::atomic system_time_saved_at_{-1e10}; std::vector> net_stats_file_callbacks_;