Daylight saving pitfalls in Hindu calendar code
India has no daylight saving time, so calendar code written for Indian users can get away with a fixed UTC+5:30 offset. Ship the same code to users in New Jersey, London or Melbourne and it breaks twice a year, quietly. This guide lists the failure modes and the tests that catch them.
The rules differ by country
| Region | Clocks go forward | Clocks go back |
|---|---|---|
| United States and most of Canada | Second Sunday in March, 02:00 local | First Sunday in November, 02:00 local |
| European Union and United Kingdom | Last Sunday in March, 01:00 UTC | Last Sunday in October, 01:00 UTC |
| New South Wales, Victoria (Australia) | First Sunday in October | First Sunday in April |
| India, Singapore | No daylight saving | No daylight saving |
These rules change when governments change them, and some places have unusual rules (Australia's Lord Howe Island shifts by only 30 minutes). Never encode them yourself; use the IANA timezone database and keep it updated.
Pitfall 1: fixed offsets
Storing “UTC−5” for a New York user is right in winter and an hour wrong in summer. Every transition time you show between March and November is then off by an hour, and any comparison with sunrise is wrong. Store the zone name (America/New_York), never the offset.
Pitfall 2: the missing hour
On the spring-forward day, local times from 02:00 to 02:59 do not exist in the US. A tithi that ends at an instant mapping to that hour must be shown in the new offset (03:xx EDT). Code that builds local times by adding hours to midnight produces impossible times like 02:30.
Pitfall 3: the repeated hour
On the fall-back day, 01:00 to 01:59 happens twice. “01:30” is ambiguous unless you also show the zone abbreviation (EDT or EST). Always format transition times with the abbreviation or offset, and always store instants in UTC.
from datetime import datetime
from zoneinfo import ZoneInfo
ny = ZoneInfo("America/New_York")
# 1 November 2026 is the US fall-back day; 01:30 happens twice.
first = datetime(2026, 11, 1, 1, 30, tzinfo=ny) # fold=0 -> EDT
second = datetime(2026, 11, 1, 1, 30, fold=1, tzinfo=ny) # fold=1 -> EST
print(first.strftime("%H:%M %Z"), second.strftime("%H:%M %Z"))Pitfall 4: a day is not 24 hours
The transition days are 23 and 25 hours long. Code that finds “tomorrow's sunrise” by adding 24 hours lands an hour off. Compute each civil day's boundaries from the date in the zone, then convert to UTC.
Pitfall 5: the southern hemisphere runs the other way
Sydney and Melbourne are on daylight time during the northern winter. A test suite built only on US and European cases will not catch a bug that inverts the season.
Pitfall 6: sunrise in UTC, date in local time
Sunrise is computed as a UTC instant. The civil date it belongs to must be taken in the local zone. In the Americas, local sunrise can fall on the previous UTC date or the same one depending on longitude and season. Mixing the two shifts the whole panchang by a day.
Pitfall 7: stale timezone data
The IANA database is updated several times a year. Runtimes bundle a copy. If yours is old, recent rule changes are missing. Record the tzdb version your code used next to each computed result, so you can explain and fix a wrong date later. TithiKit plans to report it in every response.
Tests every implementation needs
- Each spring-forward and fall-back day for the US, EU/UK and south-eastern Australia.
- A transition instant inside the missing hour, and one inside the repeated hour.
- Sunrise on both transition days, checked against an independent source.
- A location near the date line (for example Auckland) and one west of UTC−8.
- A zone with no DST (Asia/Kolkata, Asia/Singapore) as a control.
- A property test: every transition time you output, converted back to UTC, equals the original instant.
The accuracy suite plans to cover these as L3 property tests. Related reading: why festival dates differ outside India and the post on storing locations and timezones.