A theater counts same-day ticket sales in New York. An event arrives as 2026-01-08T02:15:00+00:00. It belongs in the theater's January 7 report, because the local clock still reads 9:15 p.m. Convert each aware timestamp to the theater's time zone before taking its date.
from datetime import datetime
from zoneinfo import ZoneInfo
report_zone = ZoneInfo("America/New_York")
local = datetime.fromisoformat("2026-01-08T02:15:00+00:00").astimezone(report_zone)
print(local.date()) # 2026-01-07
Keep the original timestamp alongside the report date so a disputed sale can be traced back to the receipt export. If the source drops the offset, treat that as a data contract issue and confirm the intended time zone before grouping. Deployments that lack a system copy of the IANA database can install the first-party tzdata package.
Keep both events in the repeated hour
For a second check, convert 2026-11-01T05:30:00+00:00 and 2026-11-01T06:30:00+00:00. In New York both show 1:30 a.m., with different offsets. Python sets the second timestamp's fold to 1. The local day should contain both tickets. If you need to deduplicate, keep a ticket or event identifier so the repeated clock reading doesn't collapse the two sales.
Test the reporting midnight as a separate boundary
Add 2026-01-08T04:59:00+00:00 and 2026-01-08T05:00:00+00:00 as tickets with different IDs. In New York the first belongs to January 7 and the second to January 8. Group them alongside the original 02:15 UTC sale and expect two tickets on January 7 and one on January 8.
If the reports are filtered before grouping, build the interval by converting each local midnight to UTC. Start at the beginning of the requested date and exclude the next local midnight. Check that the 05:00 UTC ticket appears in exactly one daily report.
