Skip to content

How to test Hindu calendar code: a three-layer plan

October 9, 2026 · Updated November 9, 2026

Hindu calendar code fails quietly. A tithi transition two minutes off looks fine until it crosses sunrise. A timezone bug shows up for half the year. A festival rule is right for Delhi and wrong for Denver. Users find these errors on the day they matter.

The usual instinct is to compare your output with another library or website. That catches gross errors but not shared assumptions, and if both use the same ephemeris and the same sunrise definition, it proves almost nothing. This post describes the three-layer approach we are using for TithiKit's public accuracy suite, adapted so you can apply it to your own code.

Layer 1: astronomy against an independent source

What it tests: Sun and Moon positions, transition instants (tithi, nakshatra, sankranti, new and full moon), and sunrise and sunset.

Reference: a different, high-precision implementation. If your production code uses a fast approximate library, test it against a JPL ephemeris through Skyfield. If production already uses Skyfield, an internal comparison is not independent; spot-check a sample of instants by hand against JPL Horizons instead and record each check.

How:

  1. Generate a few thousand random instants across your supported date range.
  2. Compare Sun and Moon longitudes; set a tolerance in arcseconds.
  3. Compare transition instants for a sample of months; set a tolerance in seconds.
  4. Compute sunrise and sunset for a list of cities that includes high latitudes and both hemispheres, every day of a year; set a tolerance (for example ±1 minute).

Decide what gates a release. Not every check needs to block. Sunrise, which drives the day, usually should.

Layer 2: rules against printed almanacs

What it tests: what users actually see. Tithi at sunrise, month names, leap months, festival dates, regional solar dates.

Reference: printed panchangams and published community or temple calendars, transcribed by hand. This is slow and that is the point: it is the only layer that checks your rules against the traditions you claim to follow.

How to record a case:

- id: te-2027-0001
  source: "<almanac title>, <edition>, page <n>"
  place: "<city the almanac computes for>"
  date: "YYYY-MM-DD"
  field: tithi_at_sunrise
  expected: "shukla Ekadashi"
  printed_sunrise: "HH:MM"
  notes: ""

Rules of thumb:

  • Cite every case. Edition, page and place for print; URL and access date for online calendars.
  • Record the printed sunrise. Many disagreements trace back to a different sunrise definition. See which sunrise?.
  • Compare dates exactly and times with a tolerance, for example ±2 minutes, documented per source.
  • Record disagreements between references as variance, with both values, rather than picking the one you match.
  • Do not scrape commercial almanac sites or other APIs to build references. Their terms may not allow it, and you inherit their assumptions.
  • Gate rules on coverage. A festival rule is not "stable" until it passes a minimum number of cases, for example three. Until then label it beta in your UI.

Transcription is work that native readers of each regional almanac do best. Budget for it per region.

Layer 3: properties and edge cases

What it tests: invariants that must always hold, whatever the date or place. These catch the bugs that reference cases are too sparse to find.

Examples:

  • Round trip: every local time you output converts back to the original UTC instant.
  • Continuity: each tithi's end equals the next tithi's start; there are 30 tithis per lunar month; no gaps or overlaps.
  • Sunrise ordering: for every day with a sunrise, sunrise is before sunset, and the day's sunrise tithi is the tithi in effect at that instant.
  • Kshaya and vriddhi: a day with two tithi changes exists in some months; a tithi spanning two sunrises exists in some months; your output represents both.
  • Months: each amanta month contains zero, one or two sankrantis; zero means adhika; two means kshaya.
  • DST: on the spring-forward day no output time falls in the missing hour; on the fall-back day, times in the repeated hour carry the correct offset.
  • Polar: for a location above the Arctic Circle in midsummer, your code returns its documented no-sunrise fallback rather than throwing.
  • Date line: a location just west of the date line and one just east produce consistent results.

Use a property-based testing library (Hypothesis in Python, fast-check in TypeScript) to generate dates and coordinates, and pin any failure it finds as a regular test.

The DST guide lists concrete timezone cases to include.

Version everything

A calendar result depends on the engine version, the ephemeris, the ayanamsa definition, the sunrise definition and the timezone database. Record all of them with each test run and, ideally, with each result you serve. When a user reports a wrong date six months later, you can reproduce exactly what you computed and why.

Publish failures

If you publish accuracy claims, publish the failures too. A pass rate without the failing cases tells users little. A list of known failures, each with an issue and a status, tells them what to watch out for and shows the rest of the suite is real.

A minimal starting plan

If you are one developer with a weekend:

  1. Sunrise for ten cities across both hemispheres for one year, against Skyfield.
  2. Thirty hand-transcribed tithi-at-sunrise cases from one printed almanac you trust.
  3. Five property tests: round trip, continuity, sunrise ordering, DST gap, polar fallback.

That will catch most of the bugs that reach users.

Where TithiKit fits

TithiKit's suite follows this structure, and we plan to publish it openly (data under CC BY 4.0, runner under MIT) alongside the engine. It is not published yet. Join early access to hear when it is.

Calendar and astronomical data for cultural and religious observance. Not advice of any kind.