Why Daily Sales Change After Converting UTC to IST: A Python Exercise
Test a midnight boundary in Python and learn why daily sales can disagree even when the grand total matches. A practical online learning exercise for Chennai and Tambaram learners.
Why can the same sale appear on different dates?
A daily sales report needs a reporting timezone, not just a date taken from an exported timestamp. In this fictional exercise, a sale at 18:30 UTC belongs to the next calendar day in Chennai. If one spreadsheet uses UTC dates and another uses India dates, both can contain the same transactions but disagree about daily totals.
The rule for this exercise is explicit: group each order by its Asia/Kolkata calendar date, using its event timestamp. Values are invented whole rupee amounts, not student or business records.
A small Python exercise you can run locally
Prerequisites: Python 3.9 or later and available IANA timezone data. Some installations, including Windows setups, may need the first-party tzdata package. The example below was executed with Python 3.12.14 on 20 November 2026; its assertions passed.
from datetime import datetime
from zoneinfo import ZoneInfo
orders = [
('A', '2026-10-31T18:29:59+00:00', 100),
('B', '2026-10-31T18:30:00+00:00', 250),
('C', '2026-11-01T03:00:00+00:00', 150),
]
report_zone = ZoneInfo('Asia/Kolkata')
totals = {}
for order_id, timestamp, amount in orders:
local_time = datetime.fromisoformat(timestamp).astimezone(report_zone)
report_date = local_time.date().isoformat()
totals[report_date] = totals.get(report_date, 0) + amount
print(order_id, local_time.isoformat())
print(totals)
assert totals == {'2026-10-31': 100, '2026-11-01': 400}
Expected output
A 2026-10-31T23:59:59+05:30
B 2026-11-01T00:00:00+05:30
C 2026-11-01T08:30:00+05:30
{'2026-10-31': 100, '2026-11-01': 400}
Order B is the boundary case: one second after A, it belongs to a different local day. Extracting the first ten characters of the original timestamp would instead put both A and B into October 31. That shortcut would produce 350 for October 31 and 150 for November 1. The total remains 500, so checking only the overall sum would miss the error.
The original strings include a UTC offset. Convert the instant before extracting its date. Replacing a timezone label is not the same operation as converting an instant.
A useful online practice session for Chennai and Tambaram learners
Before an online demo, run these three rows on your own laptop and keep both the original timestamp and converted value visible. Ask the teaching team to explain why B changes day, then change the test data together. This lets you assess explanation and debugging support rather than only watching a dashboard presentation. Admission enquiries are handled through the Tambaram contact; an online exercise does not imply an additional training branch.
Try two changes and explain the results
- Add order D at 2026-11-01T18:29:59+00:00 for 50. November 1 should become 450.
- Add order E at 2026-11-01T18:30:00+00:00 for 75. November 2 should contain 75.
- Compare daily totals from the UTC dates and India dates. Explain why an unchanged grand total is insufficient evidence that a daily report is correct.
The extension answers are provided for practice; only the original three-row example above was executed for this guide.
What this example does not solve
A timestamp without an offset needs an agreed source timezone; do not silently assume your laptop's timezone. Real reports must also define how refunds, duplicate order IDs, late arrivals and business closing times are treated. Monetary fractions require an appropriate decimal or integer-minor-unit policy. Keep timezone data maintained when working across regions. This tiny in-memory exercise does not validate a production reporting pipeline.
For another reporting check, read average of averages versus weighted averages.
Next learning step
Explore the Data Analytics course pathway and use the demo enquiry form to ask about prerequisites, current online schedules and project feedback. Include the boundary case you found; confirm the current course scope and fees with the team.