Python · Date and Time
Python Time Zones: Convert the Instant Before Choosing Its Calendar Date
Use aware timestamps and an explicit reporting zone so daily reports assign events to the intended local date.

A daily report can assign an event to the wrong day when it extracts a UTC date before considering the reporting time zone. One instant can belong to different calendar dates in different places.
Start with an aware timestamp
Use a datetime with an explicit time zone for an event that represents an instant. A naive datetime leaves its interpretation to application convention. For the current UTC time, datetime.now(timezone.utc) creates an aware value.
Convert before taking the date
This example places an evening UTC event in the following morning in Dhaka:
from datetime import datetime, timezone
from zoneinfo import ZoneInfo
instant = datetime(2026, 11, 3, 20, 30, tzinfo=timezone.utc)
local = instant.astimezone(ZoneInfo("Asia/Dhaka"))
reporting_day = local.date()
assert reporting_day.isoformat() == "2026-11-04"
The example uses astimezone() to preserve the instant while changing its local representation. Attaching a different tzinfo with replace() changes the interpretation of the clock fields instead of performing that conversion.
Make the rule part of the contract
Choose the reporting zone explicitly for daily quotas, activity reports and publication schedules. Retain enough timestamp information to repeat the calculation later; a date alone cannot reconstruct the original event time.
Check deployment data and boundaries
ZoneInfo needs system time zone data or the tzdata package. Include that dependency where the runtime lacks the database. Test events on both sides of local midnight and assert the intended reporting date.