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 February 18, 2026
My latest on InfoWorld reviews MCP servers from 5 major cloud providers
By Bill Doerrfeld February 18, 2026
How are organizations actually using agentic knowledge bases in practice? My article for The New Stack looks at six emerging patterns.
eBPF in Production Report
By Bill Doerrfeld February 12, 2026
My report for the eBPF Foundation explores enterprise eBPF case studies, production deployments, and real business outcomes across cloud-native environments.
Close-up of whole bean coffee Bottomless
By Bill Doerrfeld February 10, 2026
Longtime Bottomless user sharing why I love automated coffee delivery triggered by a smart scale, plus a referral link for a free first bag.
By Bill Doerrfeld February 5, 2026
MCP servers can quickly drain context windows without guardrails. Thankfully, there are ways around this, say the experts.
By Bill Doerrfeld February 4, 2026
It may seem like AI agents are suddenly doing everything across industries. But in reality, the pace of agentic AI is moving carefully, and very deliberately, in highly regulated environments like finance and banking.
By Bill Doerrfeld February 3, 2026
My latest feature for InfoWorld explores when it makes sense to scrape public web sources, and when official API integrations are the better choice for external data.
By Bill Doerrfeld January 30, 2026
What does it mean to go nano with your software updates — to "carve with a scalpel" instead of swinging a hammer? For my latest DirectorPlus piece, I caught up with Chainguard VP Dustin Kirkland to dig into that idea.
By Bill Doerrfeld January 27, 2026
I recently moderated a webinar that brought together three luminaries in the API community to discuss the importance of API standards in agentic AI development.
By Bill Doerrfeld January 26, 2026
The more folks use MCP servers in development, the more they’re realizing it can lead to runaway token usage, unpredictable response sizes, and flooded context windows.