Skip to content

Message.date contains incorrectly formatted datetime with wrong tzinfo, causing logical errors in time comparison #192

@WubbaLubbaDubDubDev

Description

@WubbaLubbaDubDubDev

Checklist

  • I am sure the error is coming from Pyrogram's code and not elsewhere
  • I have searched in the issue tracker for similar bug reports, including closed ones
  • I ran pip3 install https://github.com/TelegramPlayground/pyrogram/archive/dev.zip --force-reinstall and reproduced the issue using the latest development version

Description

Issue:
The date parameter in the Message object contains an incorrectly formatted datetime object, where tzinfo is set to UTC instead of the expected Europe/Kiev timezone.
This causes the following problem:

last_message_time = messages.date returns a time like 2025-08-19 11:00:12+00:00 (UTC).
datetime_now = datetime.now(last_message_time.tzinfo) returns the current time in UTC (e.g., 2025-08-19 10:19:27.040198+00:00).
As a result, datetime_now appears to be earlier than last_message_time, making it seem as if messages were received from the future.

Steps to reproduce

  1. Fetch a Message object where the date field is incorrectly formatted with tzinfo=UTC.
  2. Extract the date value from the Message object (e.g., last_message_time = message.date).
  3. Get the current time using the timezone from the Message object:
  4. Copy datetime_now = datetime.now(last_message_time.tzinfo)
  5. Compare last_message_time and datetime_now.
  6. Observe that datetime_now is earlier than last_message_time, which is impossible in reality.

Code example

last_message_time = messages.date

# Current time
datetime_now = datetime.now(last_message_time.tzinfo)

# Calculate the time difference
inactive_threshold = (datetime_now - last_message_time).total_seconds()

Logs

Metadata

Metadata

Assignees

Labels

bugSomething isn't workingdocumentationImprovements or additions to documentation

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions