Skip to content

time.sky

when the sun rises and sets and how long the day is anywhere, and the phase of the moon

When the sun rises and sets anywhere on Earth, and the phase of the moon.

A place is given as a city or country (a country means its capital), as a map with lat and lon, or as latitude and longitude, two numbers in degrees, north and east positive. The day defaults to today.

Times come back in the time zone of the date you pass in, which is your own zone unless you converted it. To get a sunset in the place’s own local time, pass a date in that zone, like date(2026, 6, 21) to "Oslo". With no date, a named city or country uses today in its own zone, and coordinates use today in yours. Near the poles, some days have no sunrise or sunset at all.

Tags: time

  • sunrise when the sun rises at a place on a day, or nil if it doesn’t rise or doesn’t set that day
  • sunset when the sun sets at a place on a day, or nil if it doesn’t rise or doesn’t set that day
  • day_length how long the sun is up at a place on a day: 0 h if it never rises, 24 h if it never sets
  • moon_phase the moon’s phase on a day (today without one), like “full moon”, and how much of it is lit
sunrise(lat: num, lon: num, day?: date) -> date|nil / sunrise(place: str|map, day?: date) -> date|nil

when the sun rises at a place on a day, or nil if it doesn’t rise or doesn’t set that day

1
sunrise(40.71, -74.01, date(2026, 3, 20))2026-03-20 05:59:37 -05:00
2
sunrise({lat: 64.15, lon: -21.94}).hour3
Example outputCtrl+Enter to run

See also sunset, day_length

sunset(lat: num, lon: num, day?: date) -> date|nil / sunset(place: str|map, day?: date) -> date|nil

when the sun sets at a place on a day, or nil if it doesn’t rise or doesn’t set that day

1
sunset(51.5, -0.13, date(2026, 12, 21))2026-12-21 09:53:16 -06:00
2
sunset({lat: 59.91, lon: 10.75}, date(2026, 6, 21))2026-06-21 15:43:40 -05:00
Example outputCtrl+Enter to run

See also sunrise, day_length

day_length(lat: num, lon: num, day?: date) -> quantity / day_length(place: str|map, day?: date) -> quantity

how long the sun is up at a place on a day: 0 h if it never rises, 24 h if it never sets

1
day_length(0, 0, date(2026, 3, 20)) to h min"12 h 6.66405 min"
2
day_length(70, 25, date(2026, 6, 21))24 h
Example outputCtrl+Enter to run

See also sunrise, sunset

moon_phase(day?: date) -> str

the moon’s phase on a day (today without one), like “full moon”, and how much of it is lit

1
moon_phase()"🌘 waning crescent, 27% lit"
2
moon_phase(date(2026, 1, 3))"🌕 full moon, 100% lit"
Example outputCtrl+Enter to run

See also sunrise

1
# sunset in Paris on the longest day, in Paris time
2
sunset(48.86, 2.35, date("2026-06-21T12:00+02:00") to "Europe/Paris")2026-06-21 21:57:44 +02:00
3
# the longest day in Oslo
4
day_length(59.91, 10.75, date(2026, 6, 21)) to h min"18 h 49.9557 min"
5
# no sunrise at the pole in winter
6
sunrise(89, 0, date(2026, 12, 21))nil
7
# the moon on Christmas 2026
8
moon_phase(date(2026, 12, 25))"🌕 full moon, 99% lit"
Example outputCtrl+Enter to run

Example results generated on 2026-11-04. Ones using now, today or randomness will differ when you run them.