Sunset
|
#include <sunset.h>
Public Member Functions | |
SunSet () | |
SunSet (double, double, int) | |
SunSet (double, double, double) | |
~SunSet () | |
void | setPosition (double, double, int) |
void | setPosition (double, double, double) |
void | setTZOffset (int) |
void | setTZOffset (double) |
double | setCurrentDate (int, int, int) |
double | calcNauticalSunrise () const |
double | calcNauticalSunset () const |
double | calcCivilSunrise () const |
double | calcCivilSunset () const |
double | calcAstronomicalSunrise () const |
double | calcAstronomicalSunset () const |
double | calcCustomSunrise (double) const |
double | calcCustomSunset (double) const |
double | calcSunriseUTC () |
double | calcSunsetUTC () |
double | calcSunrise () const |
double | calcSunset () const |
int | moonPhase (int) const |
int | moonPhase () const |
Static Public Attributes | |
static constexpr double | SUNSET_OFFICIAL = 90.833 |
static constexpr double | SUNSET_NAUTICAL = 102.0 |
static constexpr double | SUNSET_CIVIL = 96.0 |
static constexpr double | SUNSET_ASTONOMICAL = 108.0 |
This class controls all aspects of the operations. The math is done in private functions, and the public API's allow for returning a sunrise/sunset value for the given coordinates and timezone.
The resulting calculations are relative to midnight of the day you set in the setCurrentDate() function. It does not return a time_t value for delta from the current epoch as that would not make sense as the sunrise/sunset can be calculated thousands of years in the past. The library acts on a day timeframe, and doesn't try to assume anything about any other unit of measurement other than the current set day.
You can instantiate this class a few different ways, depending on your needs. It's possible to set your location one time and forget about doing that again if you don't plan to move. Then you only need to change the date and timezone to get correct data. Or, you can simply create an object with no location or time data and then do that later. This is a good mechanism for the setup()/loop() construct.
The most important thing to remember is to make sure the library knows the exact date and timezone for the sunrise/sunset you are trying to calculate. Not doing so means you are going to have very odd results. It's reasonably easy to know when you've forgotten one or the other by looking at the time the sun would rise and noticing that it is X hours earlier or later. That is, if you get a return of 128 minutes (2:08 AM) past midnight when the sun should rise at 308 (6:08 AM), then you probably forgot to set your EST timezone.
The library also has no idea about daylight savings time. If your timezone changes during the year to account for savings time, you must update your timezone accordingly.
SunSet::SunSet | ( | ) |
Default constructor taking no arguments. It will default all values to zero. It is possible to call calcSunrise() on this type of initialization and it will not fail, but it is unlikely you are at 0,0, TZ=0. This also will not include an initialized date to work from.
SunSet::SunSet | ( | double | lat, |
double | lon, | ||
int | tz | ||
) |
lat | Double Latitude for this object |
lon | Double Longitude for this object |
tz | Integer based timezone for this object |
This will create an object for a location with an integer based timezone value. This constructor is a relic of the original design. It is not deprecated, as this is a valid construction, but the double is preferred for correctness.
SunSet::SunSet | ( | double | lat, |
double | lon, | ||
double | tz | ||
) |
lat | Double Latitude for this object |
lon | Double Longitude for this object |
tz | Double based timezone for this object |
This will create an object for a location with a double based timezone value.
SunSet::~SunSet | ( | ) |
The constructor has no value and does nothing.
double SunSet::calcAstronomicalSunrise | ( | ) | const |
This function will return the Astronomical sunrise in local time for your location
double SunSet::calcAstronomicalSunset | ( | ) | const |
This function will return the Astronomical sunset in local time for your location
double SunSet::calcCivilSunrise | ( | ) | const |
This function will return the Civil sunrise in local time for your location
double SunSet::calcCivilSunset | ( | ) | const |
This function will return the Civil sunset in local time for your location
double SunSet::calcCustomSunrise | ( | double | angle | ) | const |
angle | The angle in degrees over the horizon at which to calculate the sunset time |
This function will return the sunrise in local time for your location for any angle over the horizon, where < 90 would be above the horizon, and > 90 would be at or below.
double SunSet::calcCustomSunset | ( | double | angle | ) | const |
angle | The angle in degrees over the horizon at which to calculate the sunset time |
This function will return the sunset in local time for your location for any angle over the horizon, where < 90 would be above the horizon, and > 90 would be at or below.
double SunSet::calcNauticalSunrise | ( | ) | const |
This function will return the Nautical sunrise in local time for your location
double SunSet::calcNauticalSunset | ( | ) | const |
This function will return the Nautical sunset in local time for your location
double SunSet::calcSunrise | ( | ) | const |
This function will return the Official sunrise in local time for your location
double SunSet::calcSunriseUTC | ( | ) |
This is a holdover from the original implementation and to me doesn't seem to be very useful, it's just confusing. This function is deprecated but won't be removed unless that becomes necessary.
double SunSet::calcSunset | ( | ) | const |
This function will return the Official sunset in local time for your location
double SunSet::calcSunsetUTC | ( | ) |
This is a holdover from the original implementation and to me doesn't seem to be very useful, it's just confusing. This function is deprecated but won't be removed unless that becomes necessary.
int SunSet::moonPhase | ( | ) | const |
Overload to set the moonphase for right now
int SunSet::moonPhase | ( | int | fromepoch | ) | const |
fromepoch | time_t seconds from epoch to calculate the moonphase for |
This is a simple calculation to tell us roughly what the moon phase is locally. It does not give position. It's roughly accurate, but not great.
The return value is 0 to 29, with 0 and 29 being hidden and 14 being full.
double SunSet::setCurrentDate | ( | int | y, |
int | m, | ||
int | d | ||
) |
double SunSet::setCurrentDate(int y, int m, int d)
y | Integer year, must be 4 digits |
m | Integer month, not zero based (Jan = 1) |
d | Integer day of month, not zero based (month starts on day 1) |
Since these calculations are done based on the Julian Calendar, we must convert our year month day into Julian before we use it. You get the Julian value for free if you want it.
void SunSet::setPosition | ( | double | lat, |
double | lon, | ||
double | tz | ||
) |
lat | Double Latitude value |
lon | Double Longitude value |
tz | Double Timezone offset |
This will set the location the library uses for it's math. The timezone is included in this as it's not valid to call any of the calc functions until you have set a timezone. It is possible to simply call setPosition one time, with a timezone and not use the setTZOffset() function ever, if you never change timezone values.
void SunSet::setPosition | ( | double | lat, |
double | lon, | ||
int | tz | ||
) |
lat | Double Latitude value |
lon | Double Longitude value |
tz | Integer Timezone offset |
This will set the location the library uses for it's math. The timezone is included in this as it's not valid to call any of the calc functions until you have set a timezone. It is possible to simply call setPosition one time, with a timezone and not use the setTZOffset() function ever, if you never change timezone values.
This is the old version of the setPosition using an integer timezone, and will not be deprecated. However, it is preferred to use the double version going forward.
void SunSet::setTZOffset | ( | double | tz | ) |
tz | Double timezone, may be positive or negative |
Critical to set your timezone so results are accurate for your time and date. This function is critical to make sure the system works correctly. If you do not set the timezone correctly, the return value will not be correct for your location. Forgetting this will result in return values that may actually be negative in some cases.
void SunSet::setTZOffset | ( | int | tz | ) |
tz | Integer timezone, may be positive or negative |
Critical to set your timezone so results are accurate for your time and date. This function is critical to make sure the system works correctly. If you do not set the timezone correctly, the return value will not be correct for your location. Forgetting this will result in return values that may actually be negative in some cases.
This function is a holdover from the previous design using an integer timezone and will not be deprecated. It is preferred to use the setTZOffset(doubble).
|
staticconstexpr |
Astronomical sun angle for sunset
|
staticconstexpr |
Civil sun angle for sunset
|
staticconstexpr |
Nautical sun angle for sunset
|
staticconstexpr |
Standard sun angle for sunset