Accurate sunrise, sunset, and twilight times for any date and time at supported locations.
Daily Rotation is a free, no auth, user-friendly API library that provides accurate sunrise, sunset, and twilight times for any timezone mixed with any supported location worldwide. This project is designed for anyone from photographers and hikers to astronomers and general enthusiasts who wants to plan activities around natural light.
Each release provides two configuations of the project.
- The bundled, minified format known as "production".
- The unbundled, unminified format known as "development".
https://github.com/LewisRandles/Daily-Rotation/releases
// Using the unbundled version needs to be kept with the internal files.
import dailyRotation from './scripts/dailyRotation_unbundled.js';
// Using the bundled version is standalone and has no internal files.
import dailyRotation from './dailyRotation_bundled.js';Providing no parameters will result in the default information being set.
await dailyRotation();The first parameter is providing the desired date. The format is case-insensitive.
| First Parameter | Type | Description |
|---|---|---|
date |
string |
Supported date formats include DD-MM-YYYY, YYYY-MM-DD, today, tomorrow and yesterday. |
| Usage | Type | Description |
|---|---|---|
date |
string |
date is in ISO8601 format. |
// Argument object.
await dailyRotation({"date": "2025-01-01"});// External object.
const apiConfig = {
"date": "2025-01-01"
}
await dailyRotation(apiConfig);The second parameter is providing the desired address within the supported locations. The format is case-insensitive.
| Second Parameter | Type | Description |
|---|---|---|
address |
string |
Supports a valid address string from the supported locations list. |
| Usage | Type | Description |
|---|---|---|
address |
string |
address decides which address is selected. |
// Argument object.
await dailyRotation({"date": "2025-01-01", "address": "london, united kingdom"});// External object.
const apiConfig = {
"date": "2025-01-01",
"address": "london, united kingdom"
}
await dailyRotation(apiConfig);The third parameter is providing the desired timezone. The format is case-insensitive.
| Third Parameter | Type | Description |
|---|---|---|
timezone |
string |
Supported timezone formats include local and any valid IANA timezone. |
| Usage | Type | Description |
|---|---|---|
timezone |
string |
timezone decides which timezone is selected. |
// Argument object.
await dailyRotation({"date": "2025-01-01", "address": "london, united kingdom", "timezone": "Europe/London"});// External object.
const apiConfig = {
"date": "2025-01-01",
"address": "london, united kingdom",
"timezone": "Europe/London"
}
await dailyRotation(apiConfig);The current list of supported locations
| Supported Location Strings | ||||
|---|---|---|---|---|
| Tokyo, Japan | New York, United States | Oslo, Norway | Copenhagen, Denmark | Seoul, South Korea |
| Los Angeles, United States | London, United Kingdom | Paris, France | Toronto, Canada | Stockholm, Sweden |
| Helsinki, Finland | Berlin, Germany | Sydney, Australia | Auckland, New Zealand | Abchorage, Alaska |
During normalization, raw API fields such as latitude and longitude are combined into "address": { "lat": 40.7127281, "lon": -74.0060152 }, timestamps are split into "datetime", "utc_datetime", and "utc_offset", solar times are grouped under "rotation", administrative fields are simplified into "displayName". Objects provide more reliable and consistent access than arrays while enabling easier manipulation and processing of nested data structures. Nested objects are flattened, redundant metadata and overlapping identifiers are removed, empty or missing fields are normalized, boolean and encoded values are standardized, and all data is organized into a uniform, consistent key-value JSON structure to produce a clean and predictable final result.
During sanitization, instead of leaving object values as null or undefined, missing or empty fields are filled with a placeholder such as "no value" to ensure that every key in the final result has a valid string; this prevents errors in downstream processing, makes the dataset fully predictable, and allows client applications to safely read and display all values without additional null checks.
This JSON serves as a configuration layer that lets you enable or disable individual parent and child fields and rename them through altName, giving you full control over which properties appear in the final output. Some values from the raw API return are intentionally omitted because they are considered unnecessary or not useful.
The parents group defines the top-level fields that can be enabled, disabled, or renamed, allowing you to control which main object properties appear in the output.
"parents": {
"item1": {
"name": {
"original": "defaultName",
"altName": "customName"
},
"used": true
},
...
}The children group manages the nested fields within those parent objects, giving similar control over which sub-properties are included and how they are labeled.
"children": {
"item1": {
"name": {
"original": "defaultName",
"altName": "customName"
},
"used": true,
"validate": "checkRotation"
},
...
}Try the hosted demo via GitHub Pages Demo
- For solar activity, the Sunrise API
- For address information, the OpenStreetMap Nominatim API
- For country code information, the Big Data Cloud API
- For timezone information, the World Time API
