Daylight CLI Tool Calculates Sunrise and Sunset Times Locally After IP-Based Location Lookup

BigGo Editorial Team
Daylight CLI Tool Calculates Sunrise and Sunset Times Locally After IP-Based Location Lookup

The changing patterns of daylight hours affect our daily rhythms and moods, particularly for those living in northern latitudes. A new command-line tool called daylight has emerged to help users track sunrise, sunset, and daylight duration from their terminal, sparking interesting discussions about its implementation and alternatives.

Local Calculation After IP-Based Location Detection

The daylight tool combines online and offline functionality in an interesting way. While many users initially wondered about its data source, the developer clarified that the application only uses an online service (ipinfo.io) to determine the user's location based on their IP address. Once it has the latitude and longitude coordinates, all sunrise and sunset calculations are performed locally using geometric algorithms.

It gets your latitude/longitude from an IP lookup service, then does a geometric calculation locally

The calculation method relies on the go-sunrise library, which implements the sunrise equation from Wikipedia for astronomical calculations. This approach ensures accurate results without requiring continuous internet connectivity for every calculation.

Manual Location Configuration Options

For users concerned about privacy or those using VPNs that might report incorrect locations, the tool offers command-line options to manually specify coordinates and timezone. This flexibility has been well-received by the community, with users appreciating the ability to override the automatic detection with commands like --loc=12.34,56.78 and --timezone=America/New_York.

The developer's consideration for these use cases demonstrates an understanding of the diverse needs of command-line tool users, who often prioritize control and customization.

Usage Examples

 Today's data for your IP location
daylight

 Override the IP location and timezone
daylight --loc="-33.92,18.42" --timezone="Africa/Johannesburg"

 Short summary of the data
daylight --short

 Data for another date
daylight --date="2025-12-31"

 Disable the colour output
NO_COLOR=true daylight

Installation Methods

  • Homebrew (MacOS and Linux):
    brew tap jbreckmckye/formulae
    brew install daylight
    
  • Manual installation: Download executable from releases page
  • Windows: Binary available but less tested

Alternative Approaches and Ecosystem Integration

The community discussion revealed several alternative methods for accessing the same information. One user pointed out that Emacs users can get similar functionality by setting their coordinates and using the built-in M-x sunrise-sunset command. This sparked some lighthearted banter about the extensibility of text editors, with references to the classic XKCD comic about text editors.

These exchanges highlight how command-line tools often exist within a rich ecosystem of alternatives, with users gravitating toward solutions that integrate with their existing workflows.

Technical Implementation and Learning Experience

The developer created daylight as a learning project for Go programming, which resonated with many in the community who appreciate open-source tools built as learning exercises. The codebase uses the lipgloss terminal UI library to create an attractive interface with color adaptation based on terminal background.

Some users noted formatting quirks, such as the tool showing 24-hour time but still appending AM/PM when certain timezone flags are used. These observations point to the iterative nature of command-line tool development, where community feedback often drives refinement.

The daylight tool serves as both a practical utility for those who, like its creator, love the sunlight and dread the long, dark winter evenings, and as an example of how learning projects can produce genuinely useful applications. Its combination of online location detection and offline calculation strikes a balance between convenience and privacy that many command-line users appreciate.

Reference: daylight: a command-line program for tracking sunrise and sunset times