Store what the user said
| Column | Example | Why |
|---|---|---|
date | 1943-03-10 | As entered, local calendar date |
time | 06:30 | As entered, local wall-clock time; nullable if unknown |
zone | Asia/Kolkata | IANA zone from your place picker - the source of every offset |
lat, lng | 22.5726, 88.3639 | The place, not the zone's capital |
tz_offset_minutes | 390 | Derived; what you send to the API |
tzdb | 2026b | Which time-zone database derived it |
Keeping the inputs lets you re-derive the offset if a time-zone database release corrects history (they do, a few times a year) or if a user edits the place. Keeping the derived offset lets you reproduce any chart you have already shown.
Derive the offset at the birth instant
The offset must be the one in force at that local time on that date. The function below is the two-pass Intl method the UTC offset finder uses, plus a round-trip check: a wall time skipped by a spring-forward change does not survive conversion and back, so the user can be asked again instead of silently shifted an hour:
birth-record.mjs
// birth-record.mjs - store what the user said; derive the offset; never store only the offset
const partsAt = (ms, zone) => Object.fromEntries(new Intl.DateTimeFormat("en-US", {
timeZone: zone, hourCycle: "h23", year: "numeric", month: "2-digit", day: "2-digit",
hour: "2-digit", minute: "2-digit", second: "2-digit",
}).formatToParts(ms).map((x) => [x.type, x.value]));
const zoneOffset = (ms, zone) => {
const p = partsAt(ms, zone);
return Math.round((Date.UTC(p.year, p.month - 1, p.day, p.hour, p.minute, p.second) - ms) / 60000);
};
// Offset (east-positive minutes) the zone observed at a LOCAL wall-clock time. Two passes,
// so a time just after a clock change lands on the right side of it.
const offsetAt = (date, time, zone) => {
const wall = Date.parse(`${date}T${time}:00Z`);
const offset = zoneOffset(wall - zoneOffset(wall, zone) * 60000, zone);
// Round-trip: a wall time skipped by a spring-forward change does not come back.
const p = partsAt(wall - offset * 60000, zone);
const exists = `${p.hour}:${p.minute}` === time;
return { offset, exists };
};
// What you persist: the user's own words plus place, and the derived offset next to them.
const record = (date, time, zone, lat, lng) => {
const { offset, exists } = offsetAt(date, time, zone);
return { date, time, zone, lat, lng, tz_offset_minutes: offset, exists, tzdb: process.versions.tz };
};
const TODAY_RULE = { "Asia/Kolkata": 330, "America/New_York": -300, "Europe/London": 0 };
for (const r of [
record("1943-03-10", "06:30", "Asia/Kolkata", 22.5726, 88.3639), // wartime IST + 1h
record("1974-01-15", "09:00", "America/New_York", 40.7128, -74.006), // US winter DST, 1974
record("1970-01-01", "12:00", "Europe/London", 51.5074, -0.1278), // British Standard Time
record("2026-03-29", "01:30", "Europe/London", 51.5074, -0.1278), // clocks jump 01:00 -> 02:00
]) {
console.log(`${r.date} ${r.time} ${r.zone.padEnd(17)} ${String(r.tz_offset_minutes).padStart(4)}`,
`(standard: ${TODAY_RULE[r.zone]})`, r.exists ? "" : "<- no such local time: ask the user", `tzdb ${r.tzdb}`);
}Output (Node 24):
1943-03-10 06:30 Asia/Kolkata 390 (standard: 330) tzdb 2026b 1974-01-15 09:00 America/New_York -240 (standard: -300) tzdb 2026b 1970-01-01 12:00 Europe/London 60 (standard: 0) tzdb 2026b 2026-03-29 01:30 Europe/London 0 (standard: 0) <- no such local time: ask the user tzdb 2026b
Three of four births have an offset that today's rule for the zone would get wrong: India ran one hour ahead during the Second World War, the United States kept daylight time through the winter of 1974, and Britain stayed on GMT+1 all year from 1968 to 1971. The fourth is a time that never existed on the clock. The birth time and time zones guide has more of these.
What the wrong offset does to a chart
Same wall-clock birth, same place, two offsets - the historical one from Python's zoneinfo, and the one a form that assumes "India = IST" would send:
what_the_offset_changes.py
# what_the_offset_changes.py - the same wall-clock birth, sent with two offsets
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"]
stored = {"date": "1943-03-10", "time": "06:30", "zone": "Asia/Kolkata",
"lat": 22.5726, "lng": 88.3639} # Kolkata, during wartime IST + 1h
local = datetime.fromisoformat(f"{stored['date']}T{stored['time']}").replace(tzinfo=ZoneInfo(stored["zone"]))
historical = int(local.utcoffset().total_seconds() // 60)
def birth_details(offset):
body = {"date": stored["date"], "time": stored["time"], "tz_offset_minutes": offset,
"lat": stored["lat"], "lng": stored["lng"]}
req = urllib.request.Request(API + "/v1/birth-details", data=json.dumps(body).encode(),
method="POST", headers={"Authorization": "Bearer " + KEY,
"Content-Type": "application/json"})
with urllib.request.urlopen(req) as r:
return json.load(r)["data"]
for label, offset in [("historical (zoneinfo)", historical), ("today's IST", 330)]:
d = birth_details(offset)
print(f"{label:<22} {offset:>4} lagna {d['ascendant']['sign']:<8} {d['ascendant']['degree']:5.2f} "
f"moon {d['moon_sign']}, {d['nakshatra']} pada {d['nakshatra_pada']}")Output:
historical (zoneinfo) 390 lagna Aquarius 17.39 moon Aries, Ashwini pada 4 today's IST 330 lagna Pisces 7.20 moon Aries, Ashwini pada 4
An hour of offset moves the lagna from Aquarius to Pisces, which moves every house. The Moon's sign and nakshatra survive this time, which is why the error is easy to miss in testing: the answers that look stable are right, and the house-based ones are silently wrong.
Rules for the form and the database
- Ask for a place, resolve it to coordinates and a zone; never ask users for an offset.
- Never compute the offset with "now":
new Date().getTimezoneOffset()is the browser's offset today, in the opposite sign convention. The API's offsets are east-positive (IST = 330). - Ambiguous fall-back times (01:30 happens twice) resolve to the first occurrence with the method above; if it matters to your users, ask.
- Run the derivation server-side, where you control the time-zone database version, and record that version.
- If you are fixing records stored with the wrong offset, recompute and re-cache; with engine-versioned cache keys the old entries are not reused because the input changed.
Questions
- What do I end up with?
- A birth-record schema, a historical offset function, and the chart difference it makes. The code is in Node.js and Python.
- Which endpoints does this recipe call, and in what order?
- 1 endpoint, in this order: Birth Details (Rashi, Nakshatra, Lagna) (
POST /v1/birth-details).