# Daily panchang for your user's city

> A panchang belongs to a place and a civil day, not to a person. Get the offset right for that date, show times in the city's zone, and one request can serve every user in that city.

Source: https://astronode.dev/recipes/daily-panchang-for-a-city · Updated: 2026-12-01

**What you build:** Tithi, nakshatra, sunrise and Rahu Kaal per city per day, in local time (Node.js, Python)

## Inputs: a place and a day, with that day's offset

[`POST /v1/panchang`](https://astronode.dev/capabilities/vedic/panchang) and the muhurta endpoints take `date`, `tz_offset_minutes`, `lat` and `lng` - no time. The offset tells the engine which civil day you mean; it has to be the offset the city observes **on that date**, so store an IANA zone per city (`Europe/London`), never a number. London is +60 in July and 0 in December.

Every time in the response - `sunrise`, `sunset`, `tithi.start` / `end`, the muhurta windows - is an ISO string in **UTC**. Delhi's sunrise on 1 Dec 2026 comes back as `2026-12-01T01:26:12.000Z`. Convert for display; never slice the string.

## Node: two calls per city-day

The panchang gives the five limbs and sun/moon times; [`/v1/muhurta/inauspicious`](https://astronode.dev/capabilities/vedic/muhurta-inauspicious) adds Rahu Kaal, Yamaganda and Gulika. `Intl.DateTimeFormat` with `timeZoneName: "longOffset"` gives the zone's offset for the date without a library:

city-panchang.mjs

```js
// city-panchang.mjs - node city-panchang.mjs
const API = process.env.ASTRONODE_API_URL ?? "https://api.astronode.dev";
const KEY = process.env.ASTRONODE_API_KEY;

// Your city table (or a geocoder): coordinates plus an IANA zone, never a fixed offset.
const CITIES = {
  delhi: { lat: 28.6139, lng: 77.209, zone: "Asia/Kolkata" },
  london: { lat: 51.5074, lng: -0.1278, zone: "Europe/London" },
};

// The zone's UTC offset at local noon on that date, east-positive minutes.
const offsetOn = (date, zone) => {
  const noon = new Date(`${date}T12:00:00Z`);
  const name = new Intl.DateTimeFormat("en-US", { timeZone: zone, timeZoneName: "longOffset" })
    .formatToParts(noon).find((p) => p.type === "timeZoneName").value; // "GMT+05:30"
  const m = /GMT([+-])(\d{2}):(\d{2})/.exec(name);
  return m ? (m[1] === "-" ? -1 : 1) * (Number(m[2]) * 60 + Number(m[3])) : 0;
};

const post = async (path, body) => {
  const res = await fetch(API + path, {
    method: "POST",
    headers: { authorization: `Bearer ${KEY}`, "content-type": "application/json" },
    body: JSON.stringify(body),
  });
  if (!res.ok) throw new Error(`${path} ${res.status}`);
  return (await res.json()).data;
};

const dailyPanchang = async (cityId, date) => {
  const c = CITIES[cityId];
  const body = { date, tz_offset_minutes: offsetOn(date, c.zone), lat: c.lat, lng: c.lng };
  const [p, bad] = await Promise.all([post("/v1/panchang", body), post("/v1/muhurta/inauspicious", body)]);
  // Every time in the response is UTC. Format it in the city's zone for display.
  const local = (iso) =>
    new Intl.DateTimeFormat("en-GB", { timeZone: c.zone, hour: "2-digit", minute: "2-digit" }).format(new Date(iso));
  return {
    city: cityId, date, tz_offset_minutes: body.tz_offset_minutes,
    tithi: `${p.tithi.paksha} ${p.tithi.name}`, nakshatra: p.nakshatra.name, yoga: p.yoga.name,
    sunrise: local(p.sunrise), sunset: local(p.sunset),
    rahu_kaal: `${local(bad.rahu_kaal.start)}-${local(bad.rahu_kaal.end)}`,
  };
};

console.log(await dailyPanchang("delhi", "2026-12-01"));
console.log(await dailyPanchang("london", "2026-07-01"));
```

Output:

```text
{
  city: 'delhi',
  date: '2026-12-01',
  tz_offset_minutes: 330,
  tithi: 'Krishna Ashtami',
  nakshatra: 'Magha',
  yoga: 'Vaidhriti',
  sunrise: '06:56',
  sunset: '17:23',
  rahu_kaal: '14:46-16:05'
}
{
  city: 'london',
  date: '2026-07-01',
  tz_offset_minutes: 60,
  tithi: 'Krishna Dwitiya',
  nakshatra: 'Uttara Ashadha',
  yoga: 'Mahendra',
  sunrise: '04:47',
  sunset: '21:20',
  rahu_kaal: '13:04-15:08'
}
```

## Python: a clock-change day, and a per-city cache

On 8 March 2026 New York moves its clocks forward at 02:00. Using the offset at **local noon** picks the offset that holds for daylight, which is what sunrise, sunset and muhurta windows need. Python 3.9's `zoneinfo` does this with the standard library, and a dictionary keyed by `(city, date)` stands in for your cache:

city_panchang.py

```python
# city_panchang.py - python3 city_panchang.py (3.9+: zoneinfo is in the standard library)
import json, os, urllib.request
from datetime import datetime
from zoneinfo import ZoneInfo

API = os.environ.get("ASTRONODE_API_URL", "https://api.astronode.dev")
KEY = os.environ["ASTRONODE_API_KEY"]
_cache = {}  # (city, date) -> panchang; one call serves every user in that city

def panchang(city, date, lat, lng, zone):
    if (city, date) in _cache:
        return _cache[(city, date)]
    noon = datetime.fromisoformat(date + "T12:00").replace(tzinfo=ZoneInfo(zone))
    offset = int(noon.utcoffset().total_seconds() // 60)
    body = {"date": date, "tz_offset_minutes": offset, "lat": lat, "lng": lng}
    req = urllib.request.Request(API + "/v1/panchang", data=json.dumps(body).encode(), method="POST",
                                 headers={"Authorization": "Bearer " + KEY,
                                          "Content-Type": "application/json"})
    with urllib.request.urlopen(req) as r:
        data = json.load(r)["data"]
    to_local = lambda iso: datetime.fromisoformat(iso.replace("Z", "+00:00")).astimezone(ZoneInfo(zone))
    _cache[(city, date)] = {"offset": offset, "sunrise": to_local(data["sunrise"]).strftime("%H:%M"),
                            "tithi_ends": to_local(data["tithi"]["end"]).strftime("%d %b %H:%M"),
                            "tithi": data["tithi"]["name"], "nakshatra": data["nakshatra"]["name"]}
    return _cache[(city, date)]

# 8 March 2026: US clocks go forward at 02:00, so local noon is already on EDT (-240).
for date in ["2026-03-07", "2026-03-08"]:
    print(date, panchang("new-york", date, 40.7128, -74.006, "America/New_York"))
```

Output:

```text
2026-03-07 {'offset': -300, 'sunrise': '06:20', 'tithi_ends': '07 Mar 08:47', 'tithi': 'Chaturthi', 'nakshatra': 'Swati'}
2026-03-08 {'offset': -240, 'sunrise': '07:18', 'tithi_ends': '08 Mar 11:41', 'tithi': 'Panchami', 'nakshatra': 'Vishakha'}
```

Local sunrise jumps from 06:20 to 07:18 overnight - not an astronomical event, just the clocks. If you had sent -300 for both days, the times would still be correct instants, but your "local" display would be an hour off on the 8th.

## Things to decide before you ship

- **The day starts at sunrise in a panchang, at midnight on your page.** A tithi often ends mid-morning (Delhi's Ashtami ends 23:14 IST on 1 Dec). Show `tithi.end` so users see the change, rather than labelling the whole civil day with one tithi.
- **Cache per city and date, not per user.** The response is identical for everyone in that city that day, and the calculation is deterministic, so a cache key of `(lat, lng, date, offset)` is safe for as long as you like.
- **Rahu Kaal needs a plan.** `/v1/panchang` is on the Free plan; the muhurta endpoints are Hobby.
- **Coordinates matter for sunrise.** Two suburbs of one metro differ by under a minute; two cities in one zone (Mumbai vs Kolkata) differ by over 40. Round to the city you show, not to the zone.
- **Polar cities** can have no sunrise on some dates; read [polar-latitude errors](https://astronode.dev/docs/errors/polar-latitude-errors) before offering Tromsø.

## Questions

**What do I end up with?**

Tithi, nakshatra, sunrise and Rahu Kaal per city per day, in local time. The code is in Node.js and Python.

**Which endpoints does this recipe call, and in what order?**

2 endpoints, in this order: Panchang (`POST /v1/panchang`), then Rahu Kaal, Yamaganda and Gulika (`POST /v1/muhurta/inauspicious`).

## Endpoints, in call order

- [`POST /v1/panchang`](https://astronode.dev/capabilities/vedic/panchang) - Panchang API
- [`POST /v1/muhurta/inauspicious`](https://astronode.dev/capabilities/vedic/muhurta-inauspicious) - Rahu Kaal, Yamaganda and Gulika API
