A calendar that calculates astronomical time calculations such as sunrise and sunset times. This class contains a Calendar and can therefore use the standard Calendar functionality to change dates etc. The calculation engine used to calculate the astronomical times can be changed to a different implementation by implementing the AstronomicalCalculator and setting it with the AstronomicalCalculator. A number of different implementations are included in the util package
Note: There are times when the algorithms can't calculate proper values for sunrise, sunset and twilight. This is usually caused by trying to calculate times for areas either very far North or South, where sunrise / sunset never happen on that date. This is common when calculating twilight with a deep dip below the horizon for locations as south of the North Pole as London in the northern hemisphere. The sun never reaches this dip at certain times of the year. When the calculations encounter this condition a null will be returned when a DateTime is expected and long.MinValue when a long is expected. The reason that Exception
s are not thrown in these cases is because the lack of a rise/set or twilight is not an exception, but expected in many parts of the world. Here is a simple example of how to use the API to calculate sunrise:
First create the Calendar for the location you would like to calculate:
string locationName = "Lakewood, NJ" double latitude = 40.0828; //Lakewood, NJ double longitude = -74.2094; //Lakewood, NJ double elevation = 20; // optional elevation correction in Meters ITimeZone timeZone = new JavaTimeZone("America/New_York"); GeoLocation location = new GeoLocation(locationName, latitude, longitude, elevation, timeZone); AstronomicalCalendar ac = new AstronomicalCalendar(location);
You can set the Date and Location on the constructor (or else it will default the the current day).
AstronomicalCalendar ac = new AstronomicalCalendar(new DateTime(2010, 2, 8), location);
Or you can set the DateTime by calling.
ac.DateWithLocation.Date = new DateTime(2010, 2, 8);
To get the time of sunrise
Date sunrise = ac.getSunrise();
Public Member Functions | |
AstronomicalCalendar () | |
AstronomicalCalendar (IGeoLocation geoLocation) | |
AstronomicalCalendar (DateTime dateTime, IGeoLocation geoLocation) | |
virtual object | Clone () |
Creates a new object that is a copy of the current instance. Note: If the
in the cloned GeoLocation will be changed from the original, it is critical that DateWithLocation. TimeZone be set in order for the AstronomicalCalendar to output times in the expected offset after being cloned. | |
virtual DateTime | GetSunrise () |
The getSunrise method Returns a DateTime representing the sunrise time. The zenith used for the calculation uses
geometric zenithof 90°. This is adjusted by the
that adds approximately 50/60 of a degree to account for 34 archminutes of refraction and 16 archminutes for the sun's radius for a total of 90.83333°. See documentation for the specific implementation of the
| |
virtual DateTime | GetSeaLevelSunrise () |
Method that returns the sunrise without correction for elevation. Non-sunrise and sunset calculations such as dawn and dusk, depend on the amount of visible light, something that is not affected by elevation. This method returns sunrise calculated at sea level. This forms the base for dawn calculations that are calculated as a dip below the horizon before sunrise. | |
virtual DateTime | GetBeginCivilTwilight () |
A method to return the the beginning of civil twilight (dawn) using a zenith of
| |
virtual DateTime | GetBeginNauticalTwilight () |
virtual DateTime | GetBeginAstronomicalTwilight () |
virtual DateTime | GetSunset () |
The getSunset method Returns a DateTime representing the sunset time. The zenith used for the calculation uses geometric zenith of 90°. This is adjusted by the AstronomicalCalculator that adds approximately 50/60 of a degree to account for 34 archminutes of refraction and 16 archminutes for the sun's radius for a total of 90.83333°. See documentation for the specific implementation of the AstronomicalCalculator that you are using. Note: In certain cases the calculates sunset will occur before sunrise. This will typically happen when a timezone other than the local timezone is used (calculating Los Angeles sunset using a GMT timezone for example). In this case the sunset date will be incremented to the following date. | |
virtual DateTime | GetSeaLevelSunset () |
Method that returns the sunset without correction for elevation. Non-sunrise and sunset calculations such as dawn and dusk, depend on the amount of visible light, something that is not affected by elevation. This method returns sunset calculated at sea level. This forms the base for dusk calculations that are calculated as a dip below the horizon after sunset. | |
virtual DateTime | GetEndCivilTwilight () |
A method to return the the end of civil twilight using a zenith of 96°. | |
virtual DateTime | GetEndNauticalTwilight () |
A method to return the the end of nautical twilight using a zenith of 102°. | |
virtual DateTime | GetEndAstronomicalTwilight () |
A method to return the the end of astronomical twilight using a zenith of 108°. | |
virtual DateTime | GetTimeOffset (DateTime time, double offset) |
Utility method that returns a date offset by the offset time passed in. This method casts the offset as a
long
| |
virtual DateTime | GetTimeOffset (DateTime time, long offset) |
A utility method to return a date offset by the offset time passed in. | |
virtual DateTime | GetSunriseOffsetByDegrees (double offsetZenith) |
A utility method to return the time of an offset by degrees below or above the horizon of sunrise. | |
virtual DateTime | GetSunsetOffsetByDegrees (double offsetZenith) |
virtual double | GetUtcSunrise (double zenith) |
Method that returns the sunrise in UTC time without correction for time zone offset from GMT and without using daylight savings time. | |
virtual double | GetUtcSeaLevelSunrise (double zenith) |
Method that returns the sunrise in UTC time without correction for time zone offset from GMT and without using daylight savings time. Non-sunrise and sunset calculations such as dawn and dusk, depend on the amount of visible light, something that is not affected by elevation. This method returns UTC sunrise calculated at sea level. This forms the base for dawn calculations that are calculated as a dip below the horizon before sunrise. | |
virtual double | GetUtcSunset (double zenith) |
Method that returns the sunset in UTC time without correction for time zone offset from GMT and without using daylight savings time. | |
virtual double | GetUtcSeaLevelSunset (double zenith) |
Method that returns the sunset in UTC time without correction for elevation, time zone offset from GMT and without using daylight savings time. Non-sunrise and sunset calculations such as dawn and dusk, depend on the amount of visible light, something that is not affected by elevation. This method returns UTC sunset calculated at sea level. This forms the base for dusk calculations that are calculated as a dip below the horizon after sunset. | |
virtual long | GetTemporalHour () |
Method to return a temporal (solar) hour. The day from sunrise to sunset is split into 12 equal parts with each one being a temporal hour. | |
virtual long | GetTemporalHour (DateTime sunrise, DateTime sunset) |
Utility method that will allow the calculation of a temporal (solar) hour based on the sunrise and sunset passed to this method. | |
virtual DateTime | GetSunTransit () |
virtual double | GetSunriseSolarDipFromOffset (double minutes) |
Will return the dip below the horizon before sunrise that matches the offset minutes on passed in. For example passing in 72 minutes for a calendar set to the equinox in Jerusalem returns a value close to 16.1° Please note that this method is very slow and inefficient and should NEVER be used in a loop. TODO: Improve efficiency. | |
virtual double | GetSunsetSolarDipFromOffset (double minutes) |
Will return the dip below the horizon after sunset that matches the offset minutes on passed in. For example passing in 72 minutes for a calendar set to the equinox in Jerusalem returns a value close to 16.1° Please note that this method is very slow and inefficient and should NEVER be used in a loop. TODO: Improve efficiency. | |
override string | ToString () |
override bool | Equals (object obj) |
Determines whether the specified System.Object is equal to this instance. | |
override int | GetHashCode () |
Returns a hash code for this instance. | |
Public Attributes | |
const double | GEOMETRIC_ZENITH = 90 |
90° below the vertical. Used for certain calculations. Note : it is important to note the distinction between this zenith and the adjusted zenith used for some solar calculations. This 90 zenith is only used because some calculations in some subclasses are historically calculated as an offset in reference to 90. /summary> | |
const double | CIVIL_ZENITH = 96 |
Sun's zenith at civil twilight (96°). | |
const double | NAUTICAL_ZENITH = 102 |
Sun's zenith at nautical twilight (102°). | |
const double | ASTRONOMICAL_ZENITH = 108 |
Sun's zenith at astronomical twilight (108°). | |
Protected Member Functions | |
virtual DateTime | GetTimeOffset (DateTime?time, double offset) |
virtual DateTime | GetTimeOffset (DateTime?time, long offset) |
virtual long | GetTemporalHour (DateTime?sunrise, DateTime?sunset) |
virtual internal DateTime | GetDateFromTime (double time) |
Properties | |
virtual IAstronomicalCalculator | AstronomicalCalculator [get, set] |
Gets or Sets the current AstronomicalCalculator set. | |
virtual IDateWithLocation | DateWithLocation [get, set] |
Gets or Sets the Date and Location to be used in the calculations. |
A calendar that calculates astronomical time calculations such as sunrise and sunset times. This class contains a Calendar and can therefore use the standard Calendar functionality to change dates etc. The calculation engine used to calculate the astronomical times can be changed to a different implementation by implementing the AstronomicalCalculator and setting it with the AstronomicalCalculator. A number of different implementations are included in the util package
Note: There are times when the algorithms can't calculate proper values for sunrise, sunset and twilight. This is usually caused by trying to calculate times for areas either very far North or South, where sunrise / sunset never happen on that date. This is common when calculating twilight with a deep dip below the horizon for locations as south of the North Pole as London in the northern hemisphere. The sun never reaches this dip at certain times of the year. When the calculations encounter this condition a null will be returned when a DateTime is expected and long.MinValue when a long is expected. The reason that Exception
s are not thrown in these cases is because the lack of a rise/set or twilight is not an exception, but expected in many parts of the world. Here is a simple example of how to use the API to calculate sunrise:
First create the Calendar for the location you would like to calculate:
string locationName = "Lakewood, NJ" double latitude = 40.0828; //Lakewood, NJ double longitude = -74.2094; //Lakewood, NJ double elevation = 20; // optional elevation correction in Meters ITimeZone timeZone = new JavaTimeZone("America/New_York"); GeoLocation location = new GeoLocation(locationName, latitude, longitude, elevation, timeZone); AstronomicalCalendar ac = new AstronomicalCalendar(location);
You can set the Date and Location on the constructor (or else it will default the the current day).
AstronomicalCalendar ac = new AstronomicalCalendar(new DateTime(2010, 2, 8), location);
Or you can set the DateTime by calling.
ac.DateWithLocation.Date = new DateTime(2010, 2, 8);
To get the time of sunrise
Date sunrise = ac.getSunrise();
<author>Eliyahu Hershfeld</author>
Zmanim.AstronomicalCalendar.AstronomicalCalendar | ( | ) |
summary> A constructor that takes in as a parameter geolocation information /summary> param name = "geoLocation"> The location information used for astronomical calculating sun times.
Zmanim.AstronomicalCalendar.AstronomicalCalendar | ( | IGeoLocation | geoLocation | ) |
summary> A constructor that takes in as a parameter geolocation information /summary> param name="dateTime">The DateTime
param name = "geoLocation"> The location information used for astronomical calculating sun times.
virtual object Zmanim.AstronomicalCalendar.Clone | ( | ) | [virtual] |
Creates a new object that is a copy of the current instance. Note: If the
in the cloned GeoLocation will be changed from the original, it is critical that DateWithLocation. TimeZone be set in order for the AstronomicalCalendar to output times in the expected offset after being cloned.
override bool Zmanim.AstronomicalCalendar.Equals | ( | object | obj | ) |
Determines whether the specified System.Object is equal to this instance.
obj | The System.Object to compare with this instance. |
true
if the specified System.Object is equal to this instance; otherwise, false
. T:System.NullReferenceException | The obj parameter is null. |
Reimplemented in Zmanim.ZmanimCalendar.
virtual DateTime Zmanim.AstronomicalCalendar.GetBeginCivilTwilight | ( | ) | [virtual] |
A method to return the the beginning of civil twilight (dawn) using a zenith of
96°.
DateTime
of the beginning of civil twilight using a zenith of 96°. If the calculation can't be computed (see explanation on top of the page), null will be returned. summary> A method to return the the beginning of nautical twilight using a zenith of 102°. /summary> returns> The DateTime
of the beginning of nautical twilight using a zenith of 102°. If the calculation can't be computed (see explanation on top of the page), null will be returned.
seealso cref = "NAUTICAL_ZENITH" />
virtual DateTime Zmanim.AstronomicalCalendar.GetBeginNauticalTwilight | ( | ) | [virtual] |
summary> A method that returns the the beginning of astronomical twilight using a zenith of 108°. /summary> returns> The DateTime
of the beginning of astronomical twilight using a zenith of 108°. If the calculation can't be computed (see explanation on top of thepage), null will be returned.
seealso cref = "ASTRONOMICAL_ZENITH" />
virtual DateTime Zmanim.AstronomicalCalendar.GetEndAstronomicalTwilight | ( | ) | [virtual] |
A method to return the the end of astronomical twilight using a zenith of 108°.
DateTime
of the end of astronomical twilight using a zenith of 108°. If the calculation can't be computed (see explanation on top of thepage), null will be returned. virtual DateTime Zmanim.AstronomicalCalendar.GetEndCivilTwilight | ( | ) | [virtual] |
A method to return the the end of civil twilight using a zenith of 96°.
DateTime
of the end of civil twilight using a zenith of . If the calculation can't be computed (see explanation on top of thepage), null will be returned.
virtual DateTime Zmanim.AstronomicalCalendar.GetEndNauticalTwilight | ( | ) | [virtual] |
A method to return the the end of nautical twilight using a zenith of 102°.
DateTime
of the end of nautical twilight using a zenith of . If the calculation can't be computed (see explanation on top of thepage), null will be returned.
override int Zmanim.AstronomicalCalendar.GetHashCode | ( | ) |
Returns a hash code for this instance.
Reimplemented in Zmanim.ComplexZmanimCalendar, and Zmanim.ZmanimCalendar.
virtual DateTime Zmanim.AstronomicalCalendar.GetSeaLevelSunrise | ( | ) | [virtual] |
Method that returns the sunrise without correction for elevation. Non-sunrise and sunset calculations such as dawn and dusk, depend on the amount of visible light, something that is not affected by elevation. This method returns sunrise calculated at sea level. This forms the base for dawn calculations that are calculated as a dip below the horizon before sunrise.
DateTime
representing the exact sea-level sunrise time. If the calculation can't be computed such as in the Arctic Circle where there is at least one day a year where the sun does not rise, and one where it does not set, a null will be returned. See detailed explanation on top of the page. virtual DateTime Zmanim.AstronomicalCalendar.GetSeaLevelSunset | ( | ) | [virtual] |
Method that returns the sunset without correction for elevation. Non-sunrise and sunset calculations such as dawn and dusk, depend on the amount of visible light, something that is not affected by elevation. This method returns sunset calculated at sea level. This forms the base for dusk calculations that are calculated as a dip below the horizon after sunset.
DateTime
representing the exact sea-level sunset time. If the calculation can't be computed such as in the Arctic Circle where there is at least one day a year where the sun does not rise, and one where it does not set, a null will be returned. See detailed explanation on top of the page. virtual DateTime Zmanim.AstronomicalCalendar.GetSunrise | ( | ) | [virtual] |
The getSunrise method Returns a DateTime
representing the sunrise time. The zenith used for the calculation uses
geometric zenithof 90°. This is adjusted by the
that adds approximately 50/60 of a degree to account for 34 archminutes of refraction and 16 archminutes for the sun's radius for a total of 90.83333°. See documentation for the specific implementation of the
that you are using.
DateTime
representing the exact sunrise time. If the calculation can't be computed such as in the Arctic Circle where there is at least one day a year where the sun does not rise, and one where it does not set, a null will be returned. See detailed explanation on top of the page. Implements Zmanim.IAstronomicalCalendar.
virtual DateTime Zmanim.AstronomicalCalendar.GetSunriseOffsetByDegrees | ( | double | offsetZenith | ) | [virtual] |
A utility method to return the time of an offset by degrees below or above the horizon of sunrise.
offsetZenith | the degrees before GetSunrise to use in the calculation. For time after sunrise use negative numbers. |
summary> A utility method to return the time of an offset by degrees below or above the horizon of sunset. /summary> param name = "offsetZenith"> the degrees after GetSunset to use in the calculation. For time before sunset use negative numbers.
returns> The
of the offset after (or before) GetSunset. If the calculation can't be computed such as in the Arctic Circle where there is at least one day a year where the sun does not rise, and one where it does not set, Double.NaN will be returned. See detailed explanation on top of the page.
virtual double Zmanim.AstronomicalCalendar.GetSunriseSolarDipFromOffset | ( | double | minutes | ) | [virtual] |
Will return the dip below the horizon before sunrise that matches the offset minutes on passed in. For example passing in 72 minutes for a calendar set to the equinox in Jerusalem returns a value close to 16.1° Please note that this method is very slow and inefficient and should NEVER be used in a loop. TODO: Improve efficiency.
minutes | offset |
virtual DateTime Zmanim.AstronomicalCalendar.GetSunset | ( | ) | [virtual] |
The getSunset method Returns a DateTime
representing the sunset time. The zenith used for the calculation uses geometric zenith of 90°. This is adjusted by the AstronomicalCalculator that adds approximately 50/60 of a degree to account for 34 archminutes of refraction and 16 archminutes for the sun's radius for a total of 90.83333°. See documentation for the specific implementation of the AstronomicalCalculator that you are using. Note: In certain cases the calculates sunset will occur before sunrise. This will typically happen when a timezone other than the local timezone is used (calculating Los Angeles sunset using a GMT timezone for example). In this case the sunset date will be incremented to the following date.
DateTime
representing the exact sunset time. If the calculation can't be computed such as in the Arctic Circle where there is at least one day a year where the sun does not rise, and one where it does not set, a null will be returned. See detailed explanation on top of the page. Implements Zmanim.IAstronomicalCalendar.
virtual double Zmanim.AstronomicalCalendar.GetSunsetSolarDipFromOffset | ( | double | minutes | ) | [virtual] |
Will return the dip below the horizon after sunset that matches the offset minutes on passed in. For example passing in 72 minutes for a calendar set to the equinox in Jerusalem returns a value close to 16.1° Please note that this method is very slow and inefficient and should NEVER be used in a loop. TODO: Improve efficiency.
minutes | offset |
returns> an XML formatted representation of the class. It returns the default output of the toXML method.
seealso cref = "ZmanimFormatter.ToXml" />
virtual DateTime Zmanim.AstronomicalCalendar.GetSunTransit | ( | ) | [virtual] |
summary> A method that returns a DateTime
from the time passed in /summary> param name = "time"> The time to be set as the time for the DateTime
. The time expected is in the format: 18.75 for 6:45:00 PM
returns> The Date.
virtual long Zmanim.AstronomicalCalendar.GetTemporalHour | ( | DateTime? | sunrise, | |
DateTime? | sunset | |||
) | [protected, virtual] |
summary> A method that returns sundial or solar noon. It occurs when the Sun is transitting the celestial meridian. In this class it is calculated as halfway between sunrise and sunset, which can be slightly off the real transit time due to the lengthening or shortening day. /summary> returns> the DateTime
representing Sun's transit. If the calculation can't be computed such as in the Arctic Circle where there is at least one day a year where the sun does not rise, and one where it does not set, a null will be returned. See detailed explanation on top of the page.
virtual long Zmanim.AstronomicalCalendar.GetTemporalHour | ( | DateTime | sunrise, | |
DateTime | sunset | |||
) | [virtual] |
Utility method that will allow the calculation of a temporal (solar) hour based on the sunrise and sunset passed to this method.
sunrise | The start of the day. | |
sunset | The end of the day. |
long
virtual long Zmanim.AstronomicalCalendar.GetTemporalHour | ( | ) | [virtual] |
Method to return a temporal (solar) hour. The day from sunrise to sunset is split into 12 equal parts with each one being a temporal hour.
long
millisecond length of a temporal hour. If the calculation can't be computed (see explanation on top of the page) long.MinValue will be returned. virtual DateTime Zmanim.AstronomicalCalendar.GetTimeOffset | ( | DateTime | time, | |
long | offset | |||
) | [virtual] |
A utility method to return a date offset by the offset time passed in.
time | the start time | |
offset | the offset in milliseconds to add to the time. |
virtual DateTime Zmanim.AstronomicalCalendar.GetTimeOffset | ( | DateTime | time, | |
double | offset | |||
) | [virtual] |
Utility method that returns a date offset by the offset time passed in. This method casts the offset as a
long
and calls GetTimeOffset(System.DateTime,long).
time | the start time | |
offset | the offset in milliseconds to add to the time |
virtual double Zmanim.AstronomicalCalendar.GetUtcSeaLevelSunrise | ( | double | zenith | ) | [virtual] |
Method that returns the sunrise in UTC time without correction for time zone offset from GMT and without using daylight savings time. Non-sunrise and sunset calculations such as dawn and dusk, depend on the amount of visible light, something that is not affected by elevation. This method returns UTC sunrise calculated at sea level. This forms the base for dawn calculations that are calculated as a dip below the horizon before sunrise.
zenith | the degrees below the horizon. For time after sunrise use negative numbers. |
virtual double Zmanim.AstronomicalCalendar.GetUtcSeaLevelSunset | ( | double | zenith | ) | [virtual] |
Method that returns the sunset in UTC time without correction for elevation, time zone offset from GMT and without using daylight savings time. Non-sunrise and sunset calculations such as dawn and dusk, depend on the amount of visible light, something that is not affected by elevation. This method returns UTC sunset calculated at sea level. This forms the base for dusk calculations that are calculated as a dip below the horizon after sunset.
zenith | the degrees below the horizon. For time before sunset use negative numbers. |
summary> A method that adds time zone offset and daylight savings time to the raw UTC time. /summary> param name = "time"> The UTC time to be adjusted.
returns> The time adjusted for the time zone offset and daylight savings time.
virtual double Zmanim.AstronomicalCalendar.GetUtcSunrise | ( | double | zenith | ) | [virtual] |
Method that returns the sunrise in UTC time without correction for time zone offset from GMT and without using daylight savings time.
zenith | the degrees below the horizon. For time after sunrise use negative numbers. |
virtual double Zmanim.AstronomicalCalendar.GetUtcSunset | ( | double | zenith | ) | [virtual] |
Method that returns the sunset in UTC time without correction for time zone offset from GMT and without using daylight savings time.
zenith | the degrees below the horizon. For time after before sunset use negative numbers. |
const double Zmanim.AstronomicalCalendar.ASTRONOMICAL_ZENITH = 108 |
Sun's zenith at astronomical twilight (108°).
const double Zmanim.AstronomicalCalendar.CIVIL_ZENITH = 96 |
Sun's zenith at civil twilight (96°).
const double Zmanim.AstronomicalCalendar.NAUTICAL_ZENITH = 102 |
Sun's zenith at nautical twilight (102°).
virtual IAstronomicalCalculator Zmanim.AstronomicalCalendar.AstronomicalCalculator [get, set] |
Gets or Sets the current AstronomicalCalculator set.
Returns the astronimicalCalculator.
Implements Zmanim.IAstronomicalCalendar.
virtual IDateWithLocation Zmanim.AstronomicalCalendar.DateWithLocation [get, set] |
Gets or Sets the Date and Location to be used in the calculations.
The calendar to set.
Implements Zmanim.IAstronomicalCalendar.