Skip to content

Commit a0a4dfd

Browse files
committed
Fix server time and add uptime
1 parent 04d26d2 commit a0a4dfd

2 files changed

Lines changed: 8 additions & 0 deletions

File tree

pyrogram/client.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1525,12 +1525,19 @@ async def set_dc(
15251525
def server_time(self) -> float:
15261526
return self._last_sync_time + (time.monotonic() - self._last_monotonic)
15271527

1528+
@property
1529+
def uptime(self) -> float:
1530+
if not self._is_server_time_synced:
1531+
return 0
1532+
return int(time.monotonic() - self._last_monotonic)
1533+
15281534
def _set_server_time(self, msg_id: int):
15291535
if self._is_server_time_synced:
15301536
return
15311537

15321538
self._last_sync_time = msg_id / float(2**32)
15331539
self._last_monotonic = time.monotonic()
1540+
self._is_server_time_synced = True
15341541
log.info(f"Time synced: {utils.timestamp_to_datetime(self._last_sync_time)}")
15351542

15361543
def guess_mime_type(self, filename: Union[str, BytesIO]) -> Optional[str]:

pyrogram/methods/auth/disconnect.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,3 +38,4 @@ async def disconnect(
3838
await self.session.stop()
3939
await self.storage.close()
4040
self.is_connected = False
41+
self._is_server_time_synced = False

0 commit comments

Comments
 (0)