How these times are calculated
Every time on this site comes from the same short chain: a pair of coordinates, an astronomical position formula, and the city’s own time zone. Nothing is looked up in a table and nothing is estimated beyond the tolerance stated below.
The calculation
Solar and lunar positions are computed with SunCalc, an open source JavaScript library by Vladimir Agafonkin. SunCalc implements the standard low-precision formulas for solar position and lunar position and distance, the same family of algorithms published by Jean Meeus in Astronomical Algorithms and used by the NOAA solar calculator. The library runs in your browser and on this site’s build, never against a paid data feed.
Sunrise and sunset are the moments the centre of the sun crosses an altitude of minus 0.833 degrees, which is the standard convention: it accounts for the sun’s apparent radius and for average atmospheric refraction near the horizon. The twilight bands use the conventional solar altitudes of minus 6 degrees (civil), minus 12 degrees (nautical) and minus 18 degrees (astronomical). Golden hour runs from a solar altitude of 6 degrees down to minus 0.833 degrees, blue hour from minus 0.833 down to minus 6 degrees.
Moon phase boundaries
The moon phase is a number between 0 and 1: 0 is new moon, 0.25 first quarter, 0.5 full moon, 0.75 last quarter. Naming a phase means putting boundaries on that number, and there is no single convention. This site uses narrow bands around the four principal phases, roughly one day of the 29.53-day cycle each, and wide bands for the four intermediate phases. That is why a moon that is 68 percent lit is called waning gibbous here and not last quarter: last quarter is 50 percent lit by definition.
| Phase value | Name |
|---|---|
| 0 to 0.0169 and 0.9831 to 1 | New Moon |
| 0.0169 to 0.2331 | Waxing Crescent |
| 0.2331 to 0.2669 | First Quarter |
| 0.2669 to 0.4831 | Waxing Gibbous |
| 0.4831 to 0.5169 | Full Moon |
| 0.5169 to 0.7331 | Waning Gibbous |
| 0.7331 to 0.7669 | Last Quarter |
| 0.7669 to 0.9831 | Waning Crescent |
Moon values are computed for local midnight at the start of the city’s own calendar day, so every page for the same city on the same day agrees to the percentage point.
City coordinates
The curated core of major world cities carries hand-checked centre coordinates. The rest comes from the GeoNames cities15000 dataset, licensed CC BY 4.0, filtered to places above 500,000 inhabitants. Coordinates are city-centre approximations: moving a few kilometres within a city shifts sunrise by seconds, so the approximation is well inside the stated accuracy.
Accuracy and known limits
- Roughly one minute for a flat, unobstructed horizon at sea level.
- Terrain matters more than the algorithm does. A mountain to the east can delay a visible sunrise by many minutes, and no coordinate-based calculation knows about it.
- Atmospheric refraction varies with temperature and pressure. The standard minus 0.833 degree convention assumes average conditions; a cold, dense morning can lift the sun into view a minute or so early.
- Altitude extends the day. The formulas here assume sea level, so a city on a plateau sees the sun slightly earlier and later than stated.
- Above the Arctic Circle and below the Antarctic Circle there are days with no sunrise or no sunset at all. Those days are labelled in words rather than shown as a missing time.
Time zones
Every time is rendered in the city’s own IANA time zone, not yours, using the time zone database built into the runtime. Daylight saving transitions are therefore handled automatically, including the days on which a clock change makes the apparent day length jump by an hour.
Frequently asked questions
How accurate are the sunrise and sunset times?
About a minute for a flat, unobstructed horizon at sea level. Terrain, tall buildings, altitude and atmospheric conditions can shift the moment the sun is actually visible by several minutes, and that shift is larger the further you are from the equator.
Which library computes the positions?
SunCalc, an open source JavaScript library by Vladimir Agafonkin, which implements the standard low-precision solar and lunar position formulas from Astronomy Answers and Jean Meeus's Astronomical Algorithms.
Where do the city coordinates come from?
A curated core of major world cities with hand-checked coordinates, extended with the GeoNames cities15000 dataset for places above 500,000 inhabitants. Coordinates are city-centre approximations. A few kilometres of position shifts sunrise by seconds, not minutes.
Which moment of the day is the moon phase calculated for?
Local midnight at the start of the city's own calendar day, so a city page and its moon page always agree. The moon moves about twelve degrees a day, so illumination can differ by a percentage point or two from a figure computed later that same day.
Do the times account for daylight saving time?
Yes. Every time is rendered in the city's IANA time zone using the browser and runtime time zone database, so summer time transitions are handled automatically.
Who is responsible for this
SunAndMoon is built and maintained by FusionStudios. If a time looks wrong, tell us and we will check it: contact. The raw numbers are available without a key through the JSON API, so you can verify any figure on this site against your own calculation.