# Build a dasha timeline: periods, bars and "you are here"

> A dasha timeline is a nested set of date ranges. The API gives you the ranges; your job is the layout, the "now" marker, and knowing when to walk the tree yourself versus asking for the active chain.

Source: https://astronode.dev/recipes/dasha-timeline · Updated: 2026-12-01

**What you build:** A proportional antardasha bar for the running mahadasha, plus the active chain to five levels (Node.js, Python)

## Two endpoints, two questions

*Tree versus lookup*

| You need | Call | Returns |
| --- | --- | --- |
| Every period to draw | [`/v1/dasha/vimshottari`](https://astronode.dev/capabilities/vedic/dasha-vimshottari) with `levels` 1-5 | The tree: `mahadasha[]`, each with `antardasha[]`, and so on |
| Only what is running on a date | [`/v1/dasha/lookup`](https://astronode.dev/capabilities/vedic/dasha-lookup) | One period per level: mahadasha → pran |

Each level multiplies the payload by about nine: a lifetime is ten mahadashas, about 90 antardashas at level 2 and over 800 periods at level 3. Draw with `levels: 2`, and use the lookup when you only need the deep levels for today.

## Lay out the running mahadasha

Find the mahadasha that contains "now", then express each antardasha as a left offset and a width in percent of it - exactly the numbers a flex row or an SVG `rect` needs. Pass "now" in as a value rather than reading the clock inside the function, so you can test the page for any date:

dasha-timeline.mjs

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

const birth = { date: "1973-04-24", time: "17:25:00", tz_offset_minutes: 330, lat: 19.076, lng: 72.8777 };
const res = await fetch(`${API}/v1/dasha/vimshottari`, {
  method: "POST",
  headers: { authorization: `Bearer ${KEY}`, "content-type": "application/json" },
  body: JSON.stringify({ ...birth, levels: 2 }), // mahadasha + antardasha
});
const { data } = await res.json();

// "Now" is your parameter, not the server's: pass it in, so the page is testable.
const now = Date.parse("2026-12-01T00:00:00Z");
const inside = (p) => Date.parse(p.start) <= now && now < Date.parse(p.end);

const maha = data.mahadasha.find(inside);
const t0 = Date.parse(maha.start);
const span = Date.parse(maha.end) - t0;

// One row per antardasha: offset and width as percentages of the mahadasha bar.
const rows = maha.antardasha.map((a) => ({
  lord: a.lord,
  from: a.start.slice(0, 10),
  left: +((100 * (Date.parse(a.start) - t0)) / span).toFixed(1),
  width: +((100 * (Date.parse(a.end) - Date.parse(a.start))) / span).toFixed(1),
  current: inside(a),
}));

console.log(`${maha.lord} mahadasha ${maha.start.slice(0, 10)} -> ${maha.end.slice(0, 10)}`);
for (const r of rows) {
  const bar = " ".repeat(Math.round(r.left / 2)) + "#".repeat(Math.max(1, Math.round(r.width / 2)));
  console.log(`${r.lord.padEnd(8)} ${r.from} ${bar}${r.current ? "  <- now" : ""}`);
}
```

Output (now = 1 Dec 2026):

```text
Jupiter mahadasha 2014-04-04 -> 2030-04-04
Jupiter  2014-04-04 #######
Saturn   2016-05-22        ########
Mercury  2018-12-04                #######
Ketu     2021-03-10                       ###
Venus    2022-02-14                          ########
Sun      2024-10-15                                  ###
Moon     2025-08-04                                    ####  <- now
Mars     2026-12-04                                         ###
Rahu     2027-11-09                                            ########
```

Antardashas are not equal: within Jupiter's 16 years, Saturn's sub-period is 19/120 of it and Ketu's 7/120, which is why the bars differ. The first mahadasha of a life is the exception - it starts part-way through (`birth_balance`), so draw it from the birth date, not from a computed start.

## The active chain in one call

For a "current period" card you do not need the tree at all. `/v1/dasha/lookup` takes the birth, a UTC instant and a system (`vimshottari`, `yogini` or `char`):

current_dasha.py

```python
# current_dasha.py - the active chain on one date, without walking the tree yourself
import json, os, urllib.request

API = os.environ.get("ASTRONODE_API_URL", "https://api.astronode.dev")
KEY = os.environ["ASTRONODE_API_KEY"]

birth = {"date": "1973-04-24", "time": "17:25:00", "tz_offset_minutes": 330,
         "lat": 19.076, "lng": 72.8777}
body = {"birth_input": birth, "date": "2026-12-01T00:00:00Z", "system": "vimshottari"}
req = urllib.request.Request(API + "/v1/dasha/lookup", data=json.dumps(body).encode(), method="POST",
                             headers={"Authorization": "Bearer " + KEY,
                                      "Content-Type": "application/json"})
with urllib.request.urlopen(req) as r:
    d = json.load(r)["data"]

for level in ["mahadasha", "antardasha", "pratyantar", "sookshma", "pran"]:
    p = d[level]
    print(f"{level:<11} {p['lord']:<8} until {p['end'][:16].replace('T', ' ')} UTC")
```

Output:

```text
mahadasha   Jupiter  until 2030-04-04 13:57 UTC
antardasha  Moon     until 2026-12-04 01:57 UTC
pratyantar  Sun      until 2026-12-04 01:57 UTC
sookshma    Venus    until 2026-12-04 01:57 UTC
pran        Moon     until 2026-12-01 05:46 UTC
```

Three levels end at the same instant - 4 Dec 2026 01:57 UTC - because the Moon antardasha's last pratyantar and sookshma end with it. That is the moment to refresh a cached card. The pran level changes every few hours, so either omit it or compute it on the client from the start and end the lookup returns.

## Display rules worth copying

- All boundaries are UTC instants with milliseconds. Format them in the **user's current** zone for a timeline; the birth zone only mattered for the input.
- Dates differ by a day or two from some software because of the year length (the engine uses 365.25 days) - see [dasha dates shifted](https://astronode.dev/docs/errors/dasha-dates-shifted) before you file it as a bug.
- A birth time uncertain by 10 minutes moves every boundary by up to a few weeks in early life. If birth time is unknown, see [unknown birth time](https://astronode.dev/recipes/unknown-birth-time).
- Cache the tree per person forever (it never changes for a given birth and engine version); cache the lookup until its earliest `end`.

## Questions

**What do I end up with?**

A proportional antardasha bar for the running mahadasha, plus the active chain to five levels. The code is in Node.js and Python.

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

2 endpoints, in this order: Vimshottari Dasha (`POST /v1/dasha/vimshottari`), then Current Dasha Lookup (`POST /v1/dasha/lookup`).

## Endpoints, in call order

- [`POST /v1/dasha/vimshottari`](https://astronode.dev/capabilities/vedic/dasha-vimshottari) - Vimshottari Dasha API
- [`POST /v1/dasha/lookup`](https://astronode.dev/capabilities/vedic/dasha-lookup) - Current Dasha Lookup API
