Skip to main content

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