Skip to main content

GeoLocation

Struct GeoLocation 

Source
pub struct GeoLocation { /* private fields */ }
Expand description

A struct that contains location information such as latitude and longitude required for astronomical calculations. The elevation field may be ignored by calculations that do not account for elevation.

Construct with GeoLocation::new, which validates the coordinates.

Implementations§

Source§

impl GeoLocation

Source

pub fn new( latitude: f64, longitude: f64, elevation: f64, timezone: TimeZone, ) -> Result<Self, GeoLocationError>

Returns a validated GeoLocation.

latitude is in the World Geodetic System, or degrees North of the Equator, and must be in [-90.0, 90.0]. longitude is in the World Geodetic System, or degrees East of the IERS Reference Meridian, and must be in [-180.0, 180.0]. elevation is in meters above sea level and must be non-negative and finite.

§Errors

Returns a GeoLocationError describing the first invalid parameter.

Examples found in repository?
examples/chiluf_mishmaros.rs (line 11)
7fn main() {
8    let new_york = TimeZone::get("America/New_York").unwrap();
9    // first night of slichos
10    let date = civil::date(2025, 9, 13);
11    let yu = GeoLocation::new(40.8506041, -73.9297205, 0.0, new_york).unwrap();
12
13    // beginning of the night
14    let sunset = zmanim_calculator::shkia(date, &yu, false).unwrap();
15
16    // add a day to calculate sunrise the next day
17    let tomorrow = date.add(Span::new().days(1));
18    // end of the night
19    let sunrise = zmanim_calculator::hanetz(tomorrow, &yu, false).unwrap();
20
21    // each ashmura is 1/3 of the night
22    let ashmura = sunrise.duration_since(&sunset) / 3;
23    // first chiluf mishmaros is one ashmura into the night
24    let chiluf1 = sunset.add(ashmura).strftime("%Y-%m-%d %H:%M:%S %Z");
25    println!("{chiluf1}");
26}
More examples
Hide additional examples
examples/astronomical.rs (line 12)
7fn main() {
8    let jerusalem = TimeZone::get("Asia/Jerusalem").unwrap();
9    let today = Zoned::now().date();
10
11    // your location here
12    let kosel = GeoLocation::new(31.777, 35.234, 700.0, jerusalem).unwrap();
13
14    let dawn = astronomical_calculator::sunrise_offset_by_degrees(
15        today,
16        &kosel,
17        astronomical_calculator::ASTRONOMICAL_ZENITH,
18    )
19    .unwrap();
20    let sunrise = astronomical_calculator::sunrise(today, &kosel).unwrap();
21    let noon = astronomical_calculator::solar_noon(today, &kosel).unwrap();
22
23    // where the sun is right now
24    let now = Zoned::now();
25    let azimuth = astronomical_calculator::solar_azimuth(&now, &kosel);
26    let elevation = astronomical_calculator::solar_elevation(&now, &kosel);
27
28    println!(
29        "
30dawn:     {dawn}
31sunrise:  {sunrise}
32noon:     {noon}
33
34solar azimuth now:   {azimuth:.2} deg
35solar elevation now: {elevation:.2} deg
36"
37    )
38}
examples/zman_registry.rs (line 12)
7fn main() {
8    let jerusalem = TimeZone::get("Asia/Jerusalem").unwrap();
9    let today = Zoned::now().date();
10
11    // your location here
12    let kosel = GeoLocation::new(31.777, 35.234, 700.0, jerusalem).unwrap();
13    let czc = ComplexZmanimCalendar::new(kosel, today, UseElevation::No);
14
15    // look up a single zman by its method name
16    let entry = find_zman("sof_zman_shema_gra").unwrap();
17    if let Some(ZmanValue::Time(time)) = (entry.compute)(&czc) {
18        println!("{}: {}\n", entry.name, time.strftime("%H:%M:%S %Z"));
19    }
20
21    // iterate over every zero-argument zman accessor
22    for entry in ALL_ZMANIM {
23        match (entry.compute)(&czc) {
24            Some(ZmanValue::Time(time)) => {
25                println!("{}: {}", entry.name, time.strftime("%H:%M:%S %Z"));
26            }
27            Some(ZmanValue::Duration(duration)) => println!("{}: {duration:#}", entry.name),
28            None => println!("{}: does not occur today", entry.name),
29        }
30    }
31}
examples/baal_hatanya.rs (line 12)
7fn main() {
8    let jerusalem = TimeZone::get("Asia/Jerusalem").unwrap();
9    let today = Zoned::now().date();
10
11    // your location here
12    let kosel = GeoLocation::new(31.777, 35.234, 700.0, jerusalem).unwrap();
13
14    let czc = ComplexZmanimCalendar::new(kosel, today, UseElevation::No);
15
16    let alos = czc.alos_baal_hatanya().unwrap();
17    let hanetz = czc.hanetz().unwrap();
18    let szks = czc.sof_zman_shema_baal_hatanya().unwrap();
19    let szt = czc.sof_zman_tefila_baal_hatanya().unwrap();
20    let chatzos = czc.chatzos_hayom().unwrap();
21    let mg = czc.mincha_gedola_baal_hatanya().unwrap();
22    let mk = czc.mincha_ketana_baal_hatanya().unwrap();
23    let plag = czc.plag_baal_hatanya().unwrap();
24    let shkia = czc.shkia().unwrap();
25    let tzeis = czc.tzeis_baal_hatanya().unwrap();
26    let shaah = czc.shaah_zmanis_baal_hatanya().unwrap();
27
28    println!(
29        "alos:         {alos}
30hanetz:       {hanetz}
31SZKS:         {szks}
32SZT:          {szt}
33chatzos:      {chatzos}
34MG:           {mg}
35MK:           {mk}
36shkia:        {shkia}
37plag:         {plag}
38tzeis:        {tzeis}
39shaah zmanis: {shaah}"
40    )
41}
examples/mga_10_to_13_degrees.rs (line 12)
8fn main() {
9    let jerusalem = TimeZone::get("Asia/Jerusalem").unwrap();
10    let today = Zoned::now().date();
11
12    let kosel = GeoLocation::new(31.777, 35.234, 700.0, jerusalem).unwrap();
13
14    let alos_10_deg =
15        zmanim_calculator::alos(today, &kosel, false, &ZmanOffset::Degrees(10.0)).unwrap();
16    let tzeis_13_deg =
17        zmanim_calculator::tzeis(today, &kosel, false, &ZmanOffset::Degrees(13.0)).unwrap();
18    let hanetz = zmanim_calculator::hanetz(today, &kosel, true).unwrap();
19    let szks = zmanim_calculator::sof_zman_shema(&alos_10_deg, &tzeis_13_deg);
20    let szt = zmanim_calculator::sof_zman_tefila(&alos_10_deg, &tzeis_13_deg);
21    let chatzos = zmanim_calculator::chatzos_hayom(today, &kosel).unwrap();
22    let mg = zmanim_calculator::mincha_gedola(&alos_10_deg, &tzeis_13_deg);
23    let mk = zmanim_calculator::mincha_ketana(&alos_10_deg, &tzeis_13_deg);
24    let plag = zmanim_calculator::plag_hamincha(&alos_10_deg, &tzeis_13_deg);
25    let shkia = zmanim_calculator::shkia(today, &kosel, true).unwrap();
26    let shaah = zmanim_calculator::shaah_zmanis(&alos_10_deg, &tzeis_13_deg);
27
28    println!(
29        "alos:         {alos_10_deg}
30hanetz:       {hanetz}
31SZKS:         {szks}
32SZT:          {szt}
33chatzos:      {chatzos}
34MG:           {mg}
35MK:           {mk}
36shkia:        {shkia}
37plag:         {plag}
38tzeis:        {tzeis_13_deg}
39shaah zmanis: {shaah}"
40    )
41}
examples/csv.rs (line 9)
6fn main() {
7    let new_york = TimeZone::get("America/New_York").unwrap();
8
9    let yeshiva = GeoLocation::new(40.8506041, -73.9297205, 0.0, new_york).unwrap();
10
11    println!(
12        "Date, Alos 19.8°, Alos 18°, Misheyakir 6.5°, Hanetz, SZKS, SZT, Chatzos, MG, MK, Plag, Shkia, Tzeis 6°"
13    );
14
15    let mut date = civil::date(2027, 1, 1);
16    let end = civil::date(2027, 12, 30);
17    let mut czc = ComplexZmanimCalendar::new(yeshiva, date, UseElevation::No);
18    while date <= end {
19        czc.set_date(date);
20
21        println!(
22            "{}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}",
23            date,
24            czc.alos_19_8_degrees().unwrap().strftime("%H:%M:%S"),
25            czc.alos_18_degrees().unwrap().strftime("%H:%M:%S"),
26            czc.alos(&ZmanOffset::Degrees(6.5))
27                .unwrap()
28                .strftime("%H:%M:%S"),
29            czc.hanetz().unwrap().strftime("%H:%M:%S"),
30            czc.sof_zman_shema_gra().unwrap().strftime("%H:%M:%S"),
31            czc.sof_zman_tefila_gra().unwrap().strftime("%H:%M:%S"),
32            czc.chatzos_hayom().unwrap().strftime("%H:%M:%S"),
33            czc.mincha_gedola_gra().unwrap().strftime("%H:%M:%S"),
34            czc.mincha_ketana_gra().unwrap().strftime("%H:%M:%S"),
35            czc.plag_gra().unwrap().strftime("%H:%M:%S"),
36            czc.shkia().unwrap().strftime("%H:%M:%S"),
37            czc.tzeis_baal_hatanya().unwrap().strftime("%H:%M:%S"),
38        );
39
40        date = date.tomorrow().unwrap();
41    }
42}
Source

pub fn latitude(&self) -> f64

The latitude in the World Geodetic System, or degrees North of the Equator

Source

pub fn longitude(&self) -> f64

The longitude in the World Geodetic System, or degrees East of the IERS Reference Meridian

Source

pub fn elevation(&self) -> f64

The elevation in meters above sea level

Source

pub fn timezone(&self) -> &TimeZone

The location’s time zone

Source

pub fn local_mean_time_offset(&self) -> f64

Returns the location’s local mean time offset from UTC in hours. The globe is split into 360°, with 15° per hour of the day. For a location that is at a longitude evenly divisible by 15 (longitude % 15 == 0), at solar noon (with adjustment for the equation of time) the sun should be directly overhead, so a user who is 1° west of this will have noon at 4 minutes after standard time noon, and conversely, a user who is 1° east of the 15° longitude will have noon at 11:56 AM. Lakewood, N.J., whose longitude is -74.222, is 0.778 away from the closest multiple of 15 at -75°. This is multiplied by 4 to yield 3 minutes and 7 seconds earlier than standard time. The offset returned does not account for the daylight saving time offset since this struct is unaware of dates.

Trait Implementations§

Source§

impl Clone for GeoLocation

Source§

fn clone(&self) -> GeoLocation

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for GeoLocation

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl PartialEq for GeoLocation

Source§

fn eq(&self, other: &GeoLocation) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for GeoLocation

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.