Class: Zmanim::Util::GeoLocation
- Inherits:
-
Object
- Object
- Zmanim::Util::GeoLocation
- Defined in:
- lib/zmanim/util/geo_location.rb
Instance Attribute Summary collapse
-
#elevation ⇒ Object
Returns the value of attribute elevation.
-
#latitude ⇒ Object
Returns the value of attribute latitude.
-
#location_name ⇒ Object
Returns the value of attribute location_name.
-
#longitude ⇒ Object
Returns the value of attribute longitude.
-
#time_zone ⇒ Object
Returns the value of attribute time_zone.
Class Method Summary collapse
Instance Method Summary collapse
-
#antimeridian_adjustment ⇒ Object
Number of Days to adjust due to antimeridian crossover.
- #clone ⇒ Object
-
#initialize(name, latitude, longitude, time_zone, elevation: nil) ⇒ GeoLocation
constructor
A new instance of GeoLocation.
-
#local_mean_time_offset ⇒ Object
Local Mean Time offset for the expected time zone (in ms).
-
#standard_time_offset ⇒ Object
Standard Time offset from UTC based on the provided Time Zone (in ms).
-
#time_zone_offset_at(utc_time) ⇒ Object
Time Zone offset from UTC at a given point in time (in ms).
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
#elevation ⇒ Object
Returns the value of attribute elevation.
3 4 5 |
# File 'lib/zmanim/util/geo_location.rb', line 3 def elevation @elevation end |
#latitude ⇒ Object
Returns the value of attribute latitude.
3 4 5 |
# File 'lib/zmanim/util/geo_location.rb', line 3 def latitude @latitude end |
#location_name ⇒ Object
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 |
#longitude ⇒ Object
Returns the value of attribute longitude.
3 4 5 |
# File 'lib/zmanim/util/geo_location.rb', line 3 def longitude @longitude end |
#time_zone ⇒ Object
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
.GMT ⇒ Object
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_adjustment ⇒ Object
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 |
#clone ⇒ Object
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_offset ⇒ Object
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_offset ⇒ Object
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 |