Safe conversion to unix time.
GitOrigin-RevId: cd851e5196ea43269e7e3ec52ac0df8093966c9a
This commit is contained in:
parent
bd559bf13a
commit
a1b67327b1
@ -104,8 +104,10 @@ Status Global::init(const TdParameters ¶meters, ActorId<Td> td, unique_ptr<T
|
||||
double diff = saved_diff.diff + default_time_difference;
|
||||
if (saved_diff.system_time > system_time) {
|
||||
double time_backwards_fix = saved_diff.system_time - system_time;
|
||||
LOG(WARNING) << "Fix system time which went backwards: " << format::as_time(time_backwards_fix) << " "
|
||||
<< tag("saved_system_time", saved_diff.system_time) << tag("system_time", system_time);
|
||||
if (time_backwards_fix > 60) {
|
||||
LOG(WARNING) << "Fix system time which went backwards: " << format::as_time(time_backwards_fix) << " "
|
||||
<< tag("saved_system_time", saved_diff.system_time) << tag("system_time", system_time);
|
||||
}
|
||||
diff += time_backwards_fix;
|
||||
}
|
||||
LOG(DEBUG) << "LOAD: " << tag("server_time_difference", diff);
|
||||
@ -118,6 +120,11 @@ Status Global::init(const TdParameters ¶meters, ActorId<Td> td, unique_ptr<T
|
||||
return Status::OK();
|
||||
}
|
||||
|
||||
int32 Global::to_unix_time(double server_time) {
|
||||
LOG_CHECK(1.0 <= server_time && server_time <= 2140000000.0) << server_time << " " << Clocks::system();
|
||||
return static_cast<int32>(server_time);
|
||||
}
|
||||
|
||||
void Global::update_server_time_difference(double diff) {
|
||||
if (!server_time_difference_was_updated_ || server_time_difference_ < diff) {
|
||||
server_time_difference_ = diff;
|
||||
|
@ -124,9 +124,6 @@ class Global : public ActorContext {
|
||||
return *shared_config_;
|
||||
}
|
||||
|
||||
double from_server_time(double date) const {
|
||||
return date - get_server_time_difference();
|
||||
}
|
||||
double to_server_time(double now) const {
|
||||
return now + get_server_time_difference();
|
||||
}
|
||||
@ -137,10 +134,10 @@ class Global : public ActorContext {
|
||||
return to_server_time(Time::now_cached());
|
||||
}
|
||||
int32 unix_time() const {
|
||||
return static_cast<int32>(server_time());
|
||||
return to_unix_time(server_time());
|
||||
}
|
||||
int32 unix_time_cached() const {
|
||||
return static_cast<int32>(server_time_cached());
|
||||
return to_unix_time(server_time_cached());
|
||||
}
|
||||
|
||||
void update_server_time_difference(double diff);
|
||||
@ -426,6 +423,8 @@ class Global : public ActorContext {
|
||||
|
||||
std::unordered_map<int64, int64> location_access_hashes_;
|
||||
|
||||
static int32 to_unix_time(double server_time);
|
||||
|
||||
void do_save_server_time_difference();
|
||||
|
||||
void do_close(Promise<> on_finish, bool destroy_flag);
|
||||
|
Loading…
Reference in New Issue
Block a user