SunLight is a C++ class library that calculates various sunrise and sunset phases based on date, latitude, and longitude. Its implementation is based on the NOAA Solar Calculator.
Calculate the exact time for:
- Sunrise: When the upper edge of the Sun appears over the eastern horizon.
- Sunset: When the upper edge of the Sun disappears below the horizon.
- Civil Dawn/Dusk: Sun is 6 degrees below the horizon. Objects are distinguishable.
- Nautical Dawn/Dusk: Sun is 12 degrees below the horizon. Horizon is visible.
- Astronomical Dawn/Dusk: Sun is 18 degrees below the horizon. Sky is no longer completely dark.
- Golden Hour: Soft, warm light when the sun is close to the horizon.
You can include SunLight in your project using CMake.
- Clone the repository or add it as a submodule.
- Add the following to your
CMakeLists.txt:
add_subdirectory(SunLight)
target_link_libraries(YourTarget PRIVATE SunLight)Here is a simple example of how to use the SunLight library:
#include <iostream>
#include <ctime>
#include "SunLight.h"
int main() {
// Stockholm, Sweden
double latitude = 59.370272;
double longitude = 18.000767;
time_t now = time(NULL);
SunLight sunLight(Date(now), latitude, longitude);
time_t sunrise = sunLight.sunrise();
time_t sunset = sunLight.sunset();
std::cout << "Sunrise: " << asctime(gmtime(&sunrise));
std::cout << "Sunset: " << asctime(gmtime(&sunset));
return 0;
}sudo apt-get install libgtest-dev
cd /usr/src/gtest
sudo cmake .
sudo make
sudo cp lib/*.a /usr/lib- Build with tests enabled:
cd build
cmake -DCMAKE_BUILD_TYPE=Release -Dmake_tests=ON ..
make- Run the tests:
./Tests/SunLight_testsThis library is strongly influenced by the JavaScript library solar-calc.
This project is licensed under the MIT License - see the LICENSE file for details.