Using Open Data APIs to Find Local Sunset, Sunrise, and Moon Phase

Bill Doerrfeld | December 1, 2020

While on vacation last year I had a little fun writing some basic API use cases. I just wanted some simple landing pages that would show me helpful celestial data. When is sunset in my local timezone? When is the sunrise? What phase is the moon in?


You can view these three websites here: Sunset, Sunrise, Phase. Each should calculate each question correctly based on your local timezone. Below, I explain the process and link to the Github repos. 


sunset 🌇

Github

sunset is a super simple website that uses open data APIs to display the sunset time in your local timezone. Sunset demonstrates how to use HTTP GET calls to open data APIs. First, the code calls the GeoIPLookup.io API to return latitude and longitude coordinates based on the caller's IP address. Next, it passes these coordinates as parameters in a call to the Sunrise-Sunset API. The Sunrise-Sunset API returns the UTC timestamp for the sunset time. Lastly, sunset converts UTC into local time. It uses some JS functions to do that, and some janky slice methods to output what we want to see.


sunrise 🌄

Github

Sunrise is a super simple website that uses open data APIs to display the sunrise time in your local timezone. Sunrise demonstrates how to use HTTP GET calls to open data APIs. First, the code calls the GeoIPLookup.io API to return latitude and longitude coordinates based on the caller's IP address. Next, it uses passes these coordinates as parameters in a call to the Sunrise-Sunset API. The Sunrise-Sunset API returns the UTC timestamp for the sunrise time. Lastly, sunrise converts UTC into local time. It uses some JS functions to do that, and some janky slice methods to output what we want to see.


phase 🌘

Github

The moon is pretty lit. But just how lit is it? This simple one page site visually represents the current phase of the moon. I built it to demo an introductory example of practical API use cases. It's just a phase. phase calls the Farmsense API to display moon data. The Farmsense API is a free-to-use open API that returns useful moon phase and illumination data. After much research, it was the only free service I could find that returned the data I wanted. Given a unix timestamp, Farmsense returns information on the current moon phase, illumination percentage, and colloquial phase name. Depending on what the API returns, the script loads different images to reflect the current moon phase and illumination percentage. I also added a little bit of my own scientific interpretation on how lit the moon is.


🌘🌓🌔🌕🌖🌗🌒


Disclaimer

I built these projects to demo an introductory lesson on practical API use cases. As they are strictly demos they are not that great. Since Sunset and Sunrise depend on the caller's IP address, mobile use may return an incorrect time. Code is not elegant, it's just for sample purposes.


By Bill Doerrfeld December 19, 2025
My latest DirectorPlus column with LeadDev interviews Bedrock Robotics' CTO, Kevin Peterson, on what it takes to develop highly adaptable and safe autonomous machines.
By Bill Doerrfeld December 17, 2025
I explore some tips to help speakers craft solid pitches. The Nordic APIs speaker selection committee looks for these sorts of things, but the tips could apply to any tech event.
By Bill Doerrfeld December 11, 2025
I made 10 predictions on how AI and APIs will converge in 2026. Signs point to AI agents being the next big API consumer.
Brain in a gravitational well, surrounded by concentric circles, with blue lines extending from the brain.
By Bill Doerrfeld December 8, 2025
My latest for InfoWorld breaks down 10 MCP servers powering next-gen devops workflows, from GitHub and Atlassian to AWS and Pulumi.
Man speaking at
By Bill Doerrfeld December 2, 2025
Excited to share my talk from Nordic APIs' Platform Summit 2025. As the opening talk of the event, I wanted to address the elephant in the room head-on: MCP.
Panel discussion on stage with five speakers and audience in front of a blue screen with speaker names.
By Bill Doerrfeld December 1, 2025
Watch all the great API talks, keynotes, and panel discussions from this year's Nordic APIs Platform Summit, now available on YouTube.
Open source flag leaddev directorplus doerrfeld Block
By Bill Doerrfeld November 28, 2025
Block's open source initiative is helping to build brand reputation, attract talent, boost partnerships, guide internal open source best practices, and aid long-term system reliability.
How CIOs are getting a return from AI
By Bill Doerrfeld November 26, 2025
Achieving ROI with AI requires a mix of strong leadership stewardship upfront, shifting the talent framework, and embedding proper monitoring and governance throughout the lifecycle.
Knowledge base for AI agents
By Bill Doerrfeld November 24, 2025
I recently explored what goes into creating a solid AI agent knowledge base — from the types of data it should contain to the retrieval mechanisms and architecture patterns that support reliable agentic behavior.
linkedin ai assistant hiring agent
By Bill Doerrfeld October 31, 2025
I recently spoke with LinkedIn VP of Engineering Prashanthi Padmanabhan about the making of their Hiring Assistant, an agent recruiters are using to optimize the applicant selection process.