rust_zmanim/util/
geolocation.rs

1//! Geolocation struct, with some math for [local mean
2//! time](crate::astronomical_calculator::local_mean_time)
3use crate::util::math_helper::*;
4
5#[derive(Debug)]
6/// A struct that contains location information such as latitude and longitude
7/// required for astronomical calculations. The elevation field may not be used
8/// by some calculations and would be ignored if set
9pub struct GeoLocation {
10    /// The latitude in the World Geodetic System, or degrees North of the
11    /// Equator
12    pub latitude: f64,
13    /// The longitude in the World Geodetic System, or degrees East of the IERS
14    /// Reference Meridian
15    pub longitude: f64,
16    /// The elevation in meters above sea level
17    pub elevation: f64,
18    /// The location's time zone, from [chrono_tz]
19    pub timezone: chrono_tz::Tz,
20}
21impl GeoLocation {
22    /// Returns the location's local mean time offset from UTC in hours. The
23    /// globe is split into 360°, with 15° per hour of the day. For a
24    /// local that is at a longitude that is evenly divisible by 15 (`longitude
25    /// % 15 == 0`), at solar noon (with adjustment for the equation of time)
26    /// the sun should be directly overhead, so a user who is 1° west of
27    /// this will have noon at 4 minutes after standard time noon, and
28    /// conversely, a user who is 1° east of the 15° longitude will have
29    /// noon at 11:56 AM. Lakewood, N.J., whose longitude is -74.222, is 0.778
30    /// away from the closest multiple of 15 at -75°. This is multiplied by
31    /// 4 to yield 3 minutes and 10 seconds earlier than standard time. The
32    /// offset returned does not account for the Daylight saving time offset
33    /// since this struct is unaware of dates.
34    pub fn local_mean_time_offset(&self) -> f64 {
35        (self.longitude * 4.0) / HOUR_MINUTES
36    }
37}