Class: Zmanim::Util::GeoLocation

Inherits:
Object
  • Object
show all
Defined in:
lib/zmanim/util/geo_location.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, latitude, longitude, time_zone, elevation: nil) ⇒ GeoLocation

Returns a new instance of GeoLocation.



9
10
11
12
13
14
15
# File 'lib/zmanim/util/geo_location.rb', line 9

def initialize(name, latitude, longitude, time_zone, elevation:nil)
  self.location_name = name
  self.latitude = latitude
  self.longitude = longitude
  self.time_zone = time_zone
  self.elevation = elevation
end

Instance Attribute Details

#elevationObject

Returns the value of attribute elevation.



3
4
5
# File 'lib/zmanim/util/geo_location.rb', line 3

def elevation
  @elevation
end

#latitudeObject

Returns the value of attribute latitude.



3
4
5
# File 'lib/zmanim/util/geo_location.rb', line 3

def latitude
  @latitude
end

#location_nameObject

Returns the value of attribute location_name.



3
4
5
# File 'lib/zmanim/util/geo_location.rb', line 3

def location_name
  @location_name
end

#longitudeObject

Returns the value of attribute longitude.



3
4
5
# File 'lib/zmanim/util/geo_location.rb', line 3

def longitude
  @longitude
end

#time_zoneObject

Returns the value of attribute time_zone.



3
4
5
# File 'lib/zmanim/util/geo_location.rb', line 3

def time_zone
  @time_zone
end

Class Method Details

.GMTObject



17
18
19
# File 'lib/zmanim/util/geo_location.rb', line 17

def self.GMT
  new('Greenwich, England', 51.4772, 0, 'GMT')
end

Instance Method Details

#antimeridian_adjustmentObject

Number of Days to adjust due to antimeridian crossover

The actual Time Zone offset may deviate from the expected offset based on the longitude But since the ‘absolute time’ calculations are always based on longitudinal offset from UTC for a given date, the date is presumed to only increase East of the Prime Meridian, and to only decrease West of it. For Time Zones that cross the antimeridian, the date will be artificially adjusted before calculation to conform with this presumption.

For example, Samoa (located around 172W) uses a local offset of 14:00. When asking to calculate for 2017-03-15, the calculator should operate using 2017-03-14 since the expected zone is -11. After determining the UTC time, the local offset of 14:00 should be applied to bring the date back to 2017-03-15.



77
78
79
80
81
82
83
84
85
86
# File 'lib/zmanim/util/geo_location.rb', line 77

def antimeridian_adjustment
  local_hours_offset = local_mean_time_offset / Zmanim::AstronomicalCalendar::HOUR_MILLIS.to_f
  if local_hours_offset >= 20
    1
  elsif local_hours_offset <= -20
    -1
  else
    0
  end
end

#cloneObject



111
112
113
# File 'lib/zmanim/util/geo_location.rb', line 111

def clone
  self.class.new(location_name.dup, latitude, longitude, time_zone.dup, elevation: elevation)
end

#local_mean_time_offsetObject

Local Mean Time offset for the expected time zone (in ms).

The offset is the difference between Local Mean Time at the given longitude and Standard Time in effect for the given time zone.



92
93
94
# File 'lib/zmanim/util/geo_location.rb', line 92

def local_mean_time_offset
  (longitude * 4 * Zmanim::AstronomicalCalendar::MINUTE_MILLIS) - standard_time_offset
end

#standard_time_offsetObject

Standard Time offset from UTC based on the provided Time Zone (in ms).

This will ignore DST transformations.



99
100
101
# File 'lib/zmanim/util/geo_location.rb', line 99

def standard_time_offset
  time_zone.current_period.utc_offset * 1000
end

#time_zone_offset_at(utc_time) ⇒ Object

Time Zone offset from UTC at a given point in time (in ms).

This will take into account any DST transformation in effect for the given Time Zone at the given time



107
108
109
# File 'lib/zmanim/util/geo_location.rb', line 107

def time_zone_offset_at(utc_time)
  time_zone.period_for_utc(utc_time).utc_total_offset * 1000
end