Class: BahaiDate::Logic

Inherits:
Object
  • Object
show all
Defined in:
lib/bahai_date/logic.rb

Constant Summary collapse

TEHRAN_LAT =

*** Latitude and longitude for Tehran, Iran *** Source: mynasadata.larc.nasa.gov/latitudelongitude-finder/

Latitude: 35

Converted to decimal using:

http://transition.fcc.gov/mb/audio/bickel/DDDMMSS-decimal.html
BigDecimal.new('35.696111')
TEHRAN_LONG =
BigDecimal.new('51.423056')
AZIMUTH =

*** Azimuth (for determining sunset times) *** Source: www.timeanddate.com/astronomy/about-sun-calculator.html

"Technically, sunrise and sunset are calculated based on the true geocentric position of the Sun at 90°50' from the zenith position (directly above the observer)."

Converted to decimal using:

http://www.satsig.net/degrees-minutes-seconds-calculator.htm
90.833333

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeLogic

Returns a new instance of Logic.



29
30
31
# File 'lib/bahai_date/logic.rb', line 29

def initialize
  @tz = TZInfo::Timezone.get('Asia/Tehran')
end

Class Method Details

.leap?(year_bahai_era) ⇒ Boolean

Returns:

  • (Boolean)


37
38
39
# File 'lib/bahai_date/logic.rb', line 37

def self.leap?(year_bahai_era)
  new.leap? year_bahai_era
end

.nawruz_for(year) ⇒ Object



33
34
35
# File 'lib/bahai_date/logic.rb', line 33

def self.nawruz_for(year)
  new.nawruz_date year
end

.twin_holy_days_date(year_bahai_era) ⇒ Object



41
42
43
# File 'lib/bahai_date/logic.rb', line 41

def self.twin_holy_days_date(year_bahai_era)
  new.twin_holy_days_for year_bahai_era
end

Instance Method Details

#bahai_era_to_gregorian_year(year) ⇒ Object



96
97
98
# File 'lib/bahai_date/logic.rb', line 96

def bahai_era_to_gregorian_year(year)
  1843 + year
end

#eighth_new_moon_for(year) ⇒ Object



72
73
74
75
76
77
# File 'lib/bahai_date/logic.rb', line 72

def eighth_new_moon_for(year)
  nawruz = nawruz_time(year)
  lunation = Astro.first_lunation_of_year(year)
  lunation += 1 while new_moon(lunation) <= nawruz
  new_moon(lunation + 7)
end

#leap?(year_bahai_era) ⇒ Boolean

Returns:

  • (Boolean)


83
84
85
86
87
88
89
90
# File 'lib/bahai_date/logic.rb', line 83

def leap?(year_bahai_era)
  gregorian_year = bahai_era_to_gregorian_year(year_bahai_era)
  if gregorian_year < 2015
    Date.leap? gregorian_year + 1
  else
    leap_bahai_era? gregorian_year
  end
end

#leap_bahai_era?(year) ⇒ Boolean

Returns:

  • (Boolean)


92
93
94
# File 'lib/bahai_date/logic.rb', line 92

def leap_bahai_era?(year)
  (nawruz_date(year + 1) - nawruz_date(year)) == 366
end

#nawruz_date(year) ⇒ Object



45
46
47
48
49
50
51
# File 'lib/bahai_date/logic.rb', line 45

def nawruz_date(year)
  if year < 2015
    Date.new(year, 3, 21)
  else
    spring_equinox_in_tehran(year)
  end
end

#nawruz_time(year) ⇒ Object



53
54
55
# File 'lib/bahai_date/logic.rb', line 53

def nawruz_time(year)
  sunset_time_for(nawruz_date(year))
end

#new_moon(lunation) ⇒ Object



79
80
81
# File 'lib/bahai_date/logic.rb', line 79

def new_moon(lunation)
  localize(Astro.date_of_moon(lunation, Astro::PhaseNew).to_utc)
end

#spring_equinox_in_tehran(year) ⇒ Object



63
64
65
# File 'lib/bahai_date/logic.rb', line 63

def spring_equinox_in_tehran(year)
  increment_if_after_sunset localize(Astro.date_of_vernal_equinox(year).to_utc)
end

#sunset_time_for(date) ⇒ Object



57
58
59
60
61
# File 'lib/bahai_date/logic.rb', line 57

def sunset_time_for(date)
  calc = SolarEventCalculator.new(date, TEHRAN_LAT, TEHRAN_LONG)
  sunset_time = calc.compute_utc_solar_event(AZIMUTH, false)
  localize(sunset_time.utc)
end

#twin_holy_days_for(year_bahai_era) ⇒ Object



67
68
69
70
# File 'lib/bahai_date/logic.rb', line 67

def twin_holy_days_for(year_bahai_era)
  gregorian_year = bahai_era_to_gregorian_year(year_bahai_era)
  increment_if_after_sunset(eighth_new_moon_for(gregorian_year)) + 1
end