TheRare Visuals

Golden hour, calculated

The free shoot planner at /golden-hour: the sun's altitude from a few lines of astronomy, a day sampled minute by minute instead of solved, times in the place's time zone, and the studio's experience turned into data.

TheRare Engineering30 October 20265 min readBeginner

A question we answer every week

"What time should we start the pre-wedding shoot?" Photographers answer it with one word, golden hour, and then have to work out when that is for a hilltop in Coorg on the 14th of February. So we built a free planner at /golden-hour: pick a place, a date and a kind of shoot, and it gives a recommended slot, an alternative, and tips.

It needed no API, no server and no cost per visit. The sun's position is maths that has been known for a long time, and this post walks through the small amount of it we needed.

How high is the sun?

Everything in the planner comes from one number: the sun's altitude, its angle above the horizon in degrees. Negative means it's below the horizon. Photographers already describe light this way:

TypeScript
export function bandFor(alt: number): LightBand {
  if (alt < -6) return "night";
  if (alt < -4) return "blue";    // blue hour
  if (alt < 6) return "golden";   // golden hour
  if (alt < 40) return "soft";
  return "harsh";                 // overhead: shadows under the eyes
}

Golden hour isn't really an hour. It's the time the sun spends between about 4 degrees below the horizon and 6 degrees above it. Near the equator the sun climbs steeply, so it passes through that band quickly; far north it climbs at a shallow angle, so golden hour lasts much longer. That's why a fixed "the hour before sunset" rule is wrong, and why it's worth calculating.

The formula, in plain words

sunAltitude(date, lat, lng) uses the standard low-precision solar formulas, the same ones behind NOAA's sunrise calculator and the SunCalc library. They're accurate to about a minute for sunrise and sunset, which is far tighter than a shoot plan needs. In order, it works out:

  1. Days since a reference date (1 January 2000, noon), because every angle below changes at a steady rate per day.
  2. Where Earth is in its orbit (the "mean anomaly"), plus a small correction because the orbit is an ellipse, not a circle. Together these give the sun's position along its yearly path across the sky.
  3. The sun's declination: how far north or south of the equator it is today. This is where the 23.44 degree tilt of Earth's axis comes in, and it's what makes June different from December.
  4. The hour angle: how far Earth has turned since the sun was due south, which depends on the time and your longitude.
  5. Finally, the altitude from your latitude, the declination and the hour angle:
TypeScript
return Math.asin(Math.sin(phi) * Math.sin(dec) + Math.cos(phi) * Math.cos(dec) * Math.cos(h)) / RAD;

That last line is the core of it: latitude, the sun's declination, and how far round the Earth has turned give the sun's height. The rest is bookkeeping to get those three numbers right.

A day, minute by minute

There's a neat closed-form formula for sunrise. We didn't use it. Instead, sunDay simply computes the altitude for every minute of the day, 1,441 samples from midnight to midnight, and looks for the minutes where it crosses each threshold:

TypeScript
const mGold = crossing(samples, 0, noon, up(-4));      // morning golden hour starts
const rise = crossing(samples, 0, noon, up(-0.833));   // sunrise
const mSoft = crossing(samples, 0, noon, up(6));       // golden hour ends
const eGold = crossing(samples, noon, n, down(6));     // evening golden hour starts
const set = crossing(samples, noon, n, down(-0.833));  // sunset

1,441 small calculations take well under a millisecond on any phone, and this approach has real advantages:

  • One method for every threshold. Sunrise, golden hour, blue hour and "harsh light starts" are all the same search with a different angle.
  • Edge cases fall out naturally. If the sun never climbs above 40 degrees (a winter day further north), there's simply no crossing, and harsh is null. The planner then says midday light is workable instead of printing a nonsense time.
  • The samples double as the chart. The "light through the day" graph on the page draws the same array.

Why -0.833 degrees for sunrise instead of 0? The sun is a disc, not a point (half its width is about 0.27 degrees), and the atmosphere bends its light so we see it slightly before it's geometrically above the horizon (about 0.57 degrees). Sunrise is officially the moment the top edge appears, which is when the centre is at -0.833 degrees.

Time zones

The listed places are all in India, so their times are shown in IST, whatever time zone the visitor's device is set to. A family in Dubai planning a Mysuru shoot should see Mysuru times. The day starts at midnight IST, written explicitly:

TypeScript
new Date(`${iso}T00:00:00+05:30`)

"Use my location" is the exception: it uses the device's own time zone, because then the visitor really is where the shoot is.

From sun times to a plan

The sun times are the easy half. The useful half is the studio's experience, in shootPlan.ts, one entry per kind of shoot:

  • Pre-wedding: start 75 minutes before evening golden hour, so there's time to settle in, and finish with blue-hour silhouettes. The alternative is a sunrise session for empty locations.
  • Wedding day: the muhurtham is fixed by the priest, so the plan protects a portrait window instead: 45 minutes before golden hour until it ends.
  • Haldi: bright morning light makes the yellow glow, starting 30 minutes after sunrise.
  • Reception: the 20 minutes of blue hour, when the sky turns deep blue as the stage lights come on.

Each recommendation carries a "why" sentence, so the planner explains itself instead of just printing times. The places list is a fixed set of coordinates on the page (no Maps API), so the whole tool costs nothing to run.

Takeaways

  • Some problems are just maths. No API, no key, no per-request cost, and it works offline.
  • Pick the accuracy you need. Low-precision formulas, accurate to about a minute, are more than enough for planning a shoot.
  • Brute force is fine when it's small. Sampling every minute is simpler than solving for each event, handles the edge cases, and feeds the chart.
  • Show times in the place's time zone, not the device's, when the place is what matters.
  • Turn experience into data. The studio's rules of thumb live in one file, each with its reason.

Found this useful?

Built something with what you learned here, or spotted a better way? Tell us. We work with freelance developers on Shootlo.