Ephemeris library vs a custom panchang engine

An open-source ephemeris gives the Sun and Moon's positions. A panchang engine turns them into dates by canonical rules. Here is where the library stops.

Mihira8 min read
Panchang

Ephemeris library vs a custom panchang engine

An ephemeris library gives the Sun and Moon's positions. A custom panchang engine turns them into dates by canonical rules. Use the library for the astronomy and build the rules yourself. Mihira, an iPhone panchang, uses the Swiss Ephemeris for positions and its own rule engine, written from the texts, for every date.

Key takeaways

  • A library such as the Swiss Ephemeris supplies longitudes, sunrise and a choice of ayanamsa. It does not supply any panchang rule.
  • Every date a family acts on comes from a decision: which sunrise, which window of the day, which month naming, which tradition. Those decisions live in the engine.
  • A library's licence is a design input. The Swiss Ephemeris is dual-licensed under the AGPL or a paid professional licence.
  • A good engine shows its source for each rule, shows the alternative where traditions differ, and says so when it cannot finish a rule.

What does an ephemeris library actually do?

It converts a moment in time into positions. The Swiss Ephemeris is the library most panchang software builds on. It compresses NASA JPL's DE431 data and reproduces it to 0.001 arcseconds, and since May 2026 it is based on DE441 (Astrodienst, Swiss Ephemeris overview). For a panchang, three of its functions matter.

  • Longitude of the Sun and Moon for any instant. A tithi is the Moon minus the Sun in steps of 12°, and a nakshatra is the Moon's sidereal position in steps of 13°20′.
  • Sidereal mode. You choose an ayanamsa with swe_set_sid_mode(), and the library subtracts it from the tropical longitude. It ships with more than 20 predefined modes and accepts a user-defined one (programming interface).
  • Rise and set. swe_rise_trans() returns sunrise for a latitude, longitude and height. It reports whether the Sun rises at all.

That is a large part of the astronomy, and it is exact. For the maths behind it, see Surya Siddhanta vs modern ephemeris. None of it is a rule from a text.

Where does the library stop and the canonical rule start?

Panchang engine layersThe ephemeris library is the base layer, the time and place layer sits above it, and the rule engine is on top.Rule engineCanonical decisions: which day, which month, which traditionWritten from the textsTime and place layerSunrise, sunset and time zone for the chosen cityLibrary call plus own checksEphemeris librarySun and Moon longitude for any instantSwiss Ephemeris
The library fixes where the Sun and Moon are. Everything above it is a decision, and each decision has a source.Source: Swiss Ephemeris documentation for the library layer; Mihira's design for the layers above.

Four decisions sit above the library. A library call cannot make any of them, because each one is a matter of śāstra and not of astronomy.

1. Which instant counts for the day

A tithi does not start and end with the civil day. It runs for roughly 19 to 26 hours (why a tithi is not 24 hours), so it often covers two sunrises or none. The engine must choose a rule for the observance. Many vratas follow the tithi atsunrise. A śrāddha follows the aparāhṇa, the fifth part of the day, so the engine has to compute that window from the city's own sunrise and sunset and test how much of the tithi covers it. For a worked case, see what to do when a shraddha tithi falls on two days.

2. Which tradition decides a split

When Ekadashi touches two sunrises, the Smārta and Vaiṣṇava traditions can name different days. Both are legitimate. The library has no opinion. The engine must hold both rules, show the common date first, name the tradition and give the alternative. See Smārta vs Vaiṣṇava Ekadashi for the difference.

3. How a month gets its name

A lunar month runs new moon to new moon. Its name comes from the solar sign the Sun is in. A month in which the Sun does not enter a new sign is the adhika (extra) month, and the rare month in which it enters two is the kṣaya month. The library gives the Sun's sign at each new moon, and the engine does the naming. Then it must apply Amānta or Pūrṇimānta reckoning, which moves the label of the dark fortnight and no astronomy.

4. Which ayanamsa, and who chose it

The library offers many ayanamsas, and the choice moves nakshatra and rāśi boundaries. Tithi is unaffected, because the ayanamsa cancels when you subtract the Sun from the Moon. So the engine must pick one, name it and apply it the same way everywhere.

What do open-source panchang libraries do with these decisions?

Open-source libraries are a good way to learn the structure of the problem. For this article I read the public source and documentation of two panchang libraries built on the Swiss Ephemeris. The table describes what those two do. It is a reading of public code, not a test run, and other libraries may differ.

DecisionWhat the two libraries read doWhat an engine from the texts adds
Day for a tithiReports the tithi at sunrise, with its end timeA named rule per observance: sunrise, aparāhṇa, pradoṣa, moonrise
End timeInterpolates between a few samples after sunriseSolves for the exact crossing, then checks it against the reference
Tradition splitPick one tradition; one documents whichShows both, labelled
Rule that cannot be finishedOne falls back to the sunrise rule so the date never vanishesStates on screen that the rule could not be completed
Source of the ruleA code comment, if anyA cited text for every rule, in a fixed order of authority

The skipped tithi is the case where a silent fallback hides the most. Fallbacks are sensible in a library, because a caller needs a number. They are a poor fit for a family deciding when to break an Ekadashi fast. A confident date that comes from a silent fallback is worse than an honest gap.

What does a ground-up engine keep faithful?

Fidelity is a property of the rules, so it needs three habits.

  1. An order of authority. Mihira ranks its sources as śruti first, then ṛṣi texts, then nibandhas, then custom. A rule from a lower tier never overrides a higher one. See which source decides a panchang rule.
  2. An honest label for custom. Rahu kalam has no text behind it, so Mihira labels it "Traditional practice" and does not call it scripture.
  3. A check on the astronomy, kept separate from the rules. The positions are tested against NASA JPL Horizons (DE441). That proves the Sun and Moon are right. It cannot prove that a rule is the right rule, which is why the two checks stay apart. See how a panchang is checked against JPL Horizons.

Mihira tests Diwali, Holi, Holika Dahan, Navratri, Ganesh Chaturthi, Janmashtami, Karva Chauth, Maha Shivaratri and Ekadashi city by city in internal tests. Those are internal QA checks. The authority for each rule stays the canonical text.

Ephemeris library vs custom panchang engine: which should you use?

Use the library for the astronomy and build the rules yourself. A library has no reason to be rebuilt, and an engine has no reason to be borrowed. One input needs a decision first: the licence.

If you are building for yourself and publishing the code, an AGPL library gives you a head start on structure. If you are building a product where families rely on the date, the engine is the product, and its rules need sources.

How does Mihira do this?

Mihira calculates on the iPhone for the city you choose, from an offline catalogue of 34,135 cities. There is no server and no network call. The Swiss Ephemeris supplies the positions. Mihira's own rule engine decides the day. Each rule shows the text it comes from. Where traditions differ, it shows the common date first, names the tradition and notes the alternative. When a rule cannot be completed, the screen says so and does not guess. Mihira is in free beta, and the App Store submission is in review.

FAQ

Is the Swiss Ephemeris accurate enough for a panchang?

Yes. The Swiss Ephemeris reproduces NASA JPL's DE431 data to 0.001 arcseconds. Its positions are far more precise than a tithi boundary needs, so errors in a panchang come from rules and ayanamsa choices, not from the astronomy.

Does the ayanamsa change a tithi time?

No. A tithi is the Moon's longitude minus the Sun's, so the ayanamsa cancels. It does change nakshatra, yoga and rāśi boundaries, because those use the sidereal longitude directly.

Why not use an open-source panchang library?

You can, for learning or for personal use. The two libraries read report the tithi at sunrise, and one falls back when a rule has no clean answer. A product that families rely on needs a named rule, a cited source and an honest gap instead.

Can the Swiss Ephemeris be used in a closed-source app?

Only with the Swiss Ephemeris Professional License, which is a paid contract. The alternative is the AGPL, which requires the whole project to be released under the AGPL or a compatible licence.

To see tithi and nakshatra times for your city, with the rule and source behind each, visit mihira.app.

More to read