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.


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.
How to fail at platfom engineering
By Bill Doerrfeld October 22, 2025
How do you fail at platform engineering? Make it 100% UI-first. Don't market it. Survey no one. Measure success by who's onboarded. And just copy what others are doing.
Platform summit conference nordic apis stockholm bill doerrfeld
By Bill Doerrfeld October 21, 2025
This year's Platform Summit felt reinvigorated, with many new motivations and areas to discuss. Of course, AI agents and MCP stole the show.
Colorful hot air balloons against a bright blue sky.
By Bill Doerrfeld September 26, 2025
For my latest DirectorPlus edition, I interviewed Thomas Johnson, co-founder and CTO of Multiplayer, about lessons learned releasing their MCP server.
Abstract blue web-like structure, possibly fabric, with a shimmering effect.
By Bill Doerrfeld September 23, 2025
Explore whether vector native databases outperform traditional DBs with vector add-ons for AI. Learn use cases, tradeoffs, and expert insights.
Man presenting at the Nordic APIs conference, standing in front of a screen, with audience.
By Bill Doerrfeld September 17, 2025
Join me in Stockholm for Platform Summit 2025 and the API Security UnConference, October 13–15. Exciting talks, networking, and more.
A grey articulated figure kneeling, arranging small white objects in a clear plastic container. White background.
By Bill Doerrfeld September 11, 2025
MCP shines for indeterministic workflows, novel integrations, and giving AI coding agents context on the fly. But for more predictable automation it may be overengineeering.