How It Works
When you run Ramadan CLI for the first time without specifying a city, it attempts to detect your location using your IP address. The system tries three different geolocation providers in sequence until one succeeds.Provider Fallback Chain
The location detection follows a priority-based fallback system:Primary: ip-api.com
The first provider attempted is Returns city, country, latitude, longitude, and timezone data.
ip-api.com, which queries:Secondary: ipapi.co
If the primary provider fails, the system tries Provides the same location data with a different API structure.
ipapi.co:Location Data Structure
Each provider returns the following information:| Field | Type | Description |
|---|---|---|
city | string | Your city name (e.g., “San Francisco”) |
country | string | Your country name (e.g., “United States”) |
latitude | number | Geographic latitude coordinate |
longitude | number | Geographic longitude coordinate |
timezone | string | IANA timezone identifier (e.g., “America/Los_Angeles”) |
Implementation Details
The geolocation system is implemented insrc/geo.ts with the following key features:
Error Handling
Each provider attempt is wrapped in error handling:Schema Validation
All provider responses are validated using Zod schemas to ensure data integrity:- ip-api.com: Validates
city,country,lat,lon, and optionaltimezone - ipapi.co: Validates
city,country_name,latitude,longitude, and optionaltimezone - ipwho.is: Validates
success,city,country,latitude,longitude, and nestedtimezone.id
The timezone field is optional across all providers. If not provided, it defaults to an empty string and falls back to stored settings or manual configuration.
Main Detection Function
TheguessLocation() function orchestrates the fallback chain:
City/Country Geocoding
For manual city input, Ramadan CLI uses the Open-Meteo Geocoding API to resolve location details:When Detection Fails
If all three IP providers fail and no saved configuration exists, you’ll see this error:Location detection happens automatically only when:
- No saved configuration exists
- No city argument is provided
- Not using
--jsonor--statusflags (which skip interactive setup)
Auto-Save Behavior
When location detection succeeds, the data is automatically saved to your configuration:- City name
- Country name
- Latitude and longitude coordinates
- Timezone (if available)
- Country-specific recommended prayer calculation method
- Country-specific recommended juristic school
Testing Location Detection
To test location detection, clear your saved configuration first:Privacy Considerations
If you prefer not to use automatic detection:- Use the interactive setup to manually enter your city
- Pass a city as an argument:
roza "Lahore" - Use the config command:
roza config --city "Dubai" --country "UAE"
Related Features
- Custom First Roza - Override automatic Ramadan date detection
- Output Modes - Different ways to view prayer times
- Ramadan Calendar - View the full month schedule