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.


Other Blog Posts

KubeCon + CloudNativeCon North America 2026 graphic: November 9-12, Salt Lake City, Utah
By Bill Doerrfeld • November 6, 2026
I'll be at KubeCon + CloudNativeCon NA 2026 in Salt Lake City, Nov 9–12, scouting stories on agentic AI, cloud native and APIs. Reach out if you'd like to connect!
AI Pen-Testing Conference graphic from AI Security University
By Bill Doerrfeld • November 4, 2026
Another virtual conference is in the bag, and the community really showed up to talk AI penetration testing.
By Bill Doerrfeld • October 30, 2026
My eight-part Road to KubeCon column with The New Stack is done. Here are some of the key takeaways.
How AI Agents Change API Interaction opening slide doerrfeld bill 2026 nordic apis
By Bill Doerrfeld • October 18, 2026
Here are my slides from my opening keynote at Nordic APIs Summit 2026, exploring how AI agents are changing API interaction patterns.
By Bill Doerrfeld • October 17, 2026
My latest research for AI Security University looks at AI tools and resources for pen-testers, red teamers, and bug bounty hunters.
By Bill Doerrfeld • October 16, 2026
My commissioned feature for Arthur D. Little's PRISM publication analyzes the big shifts underway now that generating code is becoming trivial.
By Bill Doerrfeld • October 11, 2026
Was happy to participate as a speaker and moderator at SecureMaine on October 8th, 2026.
By Bill Doerrfeld • October 5, 2026
My latest for LeadDev interviews a Meta engineer who built an agentic system to optimize their capacity planning, leading to real power use savings.
By Bill Doerrfeld • September 30, 2026
I set out expecting to write an article about how every enterprise was jumping on trendy alternative or "neo" clouds. That ended up not being the case.
By Bill Doerrfeld • September 28, 2026
Join the virtual AI Pen-Testing Conference to explore how AI is changing penetration testing, red teaming, and the security testing of AI systems.