Sun Times

Sunrise and sunset times are important to know when walking, how early can you start, when do you need to finish by within daylight? What time does the sky become golden for stunning sunset photos?

To show the current sun times for each walk on BeyondTracks we use:

suncalc will, given a date and latitude/longitude return a set of sun times, we choose the show the sunrise, sunset, dawn and golden times.

BeyondTracks suntimes

However there’s a few caveats, you see suncalc will calculate sun times in the local time zone, which is not what we want. If I’m looking at a walk at Uluṟu, I want to know the sunset time in the local time zone, not in Sydney’s time zone.

That’s where Luxon and tz-lookup come into play, so




// obtain the time zone of Location B
const tzB = tzLookup(, B.lng)

// what time is it now, in time zone B
const currentTimeAtB = DateTime.fromISO(new Date().toISOString(), { zone: tzB })

// suntimes at B in time zone A
const suntimesAtB_in_tzA = SunCalc.getTimes(new Date(currentTimeAtB),, B.lng)

// suntimes at B in time zone B
const sunriseAtB_in_tzB = DateTime.fromISO(suntimesAtB_in_tzA.sunrise.toISOString(), { zone: tzB })

This is how we ensure that we always show sun times in the walk’s local time zone, regardless of where the user is.