Daily totals in a local time zone
`daily_totals(orders, tz)` builds a report of daily totals in the local time
zone `tz`.
`orders` is a list of orders with UTC timestamps:
```python
{
"order_id": "A-1",
"amount": 1500, # integer, minor units
"created_at": datetime(2026, 1, 15, 23, 30, tzinfo=timezone.utc),
}
```
`tz` is an IANA zone name: `"Europe/Berlin"`, `"America/New_York"`, `"UTC"`.
The result contains the days that have orders, sorted by date:
```python
[
{"date": "2026-01-15", "total": 1500, "orders": 1},
{"date": "2026-01-16", "total": 250, "orders": 3},
]
```
Contract:
- `date` is the local calendar date of the order in `tz`, formatted
`YYYY-MM-DD`;
- an order exactly at local midnight belongs to the new day;
- every order is counted exactly once: the daylight-saving transition neither
creates nor loses orders;
- `total` is the sum of `amount`, `orders` is the number of orders that day;
- a negative `amount` is valid (a refund) and reduces the total;
- days without orders are not added;
- `created_at` is an aware `datetime`; naive time raises `ValueError` — silently
treating it as UTC is not allowed;
- `amount` is an integer but not `bool`;
- `tz` is a non-empty string naming an existing zone, otherwise `ValueError`;
- an empty order list returns `[]`.
Write tests for: the local midnight boundary, an order at exactly midnight, the
daylight-saving transition, the same instant in different zones, several orders
on one day, day ordering, an empty list, and invalid input.
The AI mentor is available after you log in: it sees your attempt history and does not spend resources on anonymous requests.
Log in and askHint 1
What happens to an order at `23:30Z` when viewed from Berlin? And an order at
exactly `00:00` local time — is it today or already tomorrow?