Function sun_times::sun_times

source ·
pub fn sun_times(
    date: NaiveDate,
    latitude: f64,
    longitude: f64,
    elevation: f64
) -> Option<(DateTime<Utc>, DateTime<Utc>)>
Expand description

Calculates the approximate sunset and sunrise times at a given latitude, longitude, and altitude

Note that elevation is used to correct for atmospheric refraction, so negative elevations are treated as being at sea level due to having minimal difference in refraction to being at sea level

Arguments

  • date - The date on which to calculate the sunset and sunrise, in UTC
  • latitude - The latitude at which to calculate the times. Expressed as degrees
  • longitude - The longitude at which to calculate the times. Expressed as degrees
  • elevation - The elevation at which to calculate the times. Expressed as meters above sea level. Negative values will be ignored

Return value

Returns

  • None if the date is not representable in chrono (~5M years from now), or sunsets/rises cannot be calculated due to long arctic/antarctic day/night (outside ~±67° of latitude)
  • Some((sunrise,sunset)) otherwise

Examples

//Calculate the sunset and sunrise times today at Sheffield university's new computer science building
let times = sun_times(Utc::today(),53.38,-1.48,100.0);
println!("Sunrise: {}, Sunset: {}",times.0,times.1);