class BahaiDate::Logic

Constants

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
TEHRAN_LAT

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

Latitude: 35° 41' 45.9996", Longitude: 51° 25' 23.0016"

Converted to decimal using:

http://transition.fcc.gov/mb/audio/bickel/DDDMMSS-decimal.html
TEHRAN_LONG

Public Class Methods

leap?(year_bahai_era) click to toggle source
# File lib/bahai_date/logic.rb, line 37
def self.leap?(year_bahai_era)
  new.leap? year_bahai_era
end
nawruz_for(year) click to toggle source
# File lib/bahai_date/logic.rb, line 33
def self.nawruz_for(year)
  new.nawruz_date year
end
new() click to toggle source
# File lib/bahai_date/logic.rb, line 29
def initialize
  @tz = TZInfo::Timezone.get('Asia/Tehran')
end
twin_holy_days_date(year_bahai_era) click to toggle source
# 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

Public Instance Methods

bahai_era_to_gregorian_year(year) click to toggle source
# File lib/bahai_date/logic.rb, line 96
def bahai_era_to_gregorian_year(year)
  1843 + year
end
eighth_new_moon_for(year) click to toggle source
# 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) click to toggle source
# 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) click to toggle source
# 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) click to toggle source
# 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) click to toggle source
# File lib/bahai_date/logic.rb, line 53
def nawruz_time(year)
  sunset_time_for(nawruz_date(year))
end
new_moon(lunation) click to toggle source
# 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) click to toggle source
# 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) click to toggle source
# 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) click to toggle source
# 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

Private Instance Methods

increment_if_after_sunset(time) click to toggle source
# File lib/bahai_date/logic.rb, line 106
def increment_if_after_sunset(time)
  date = time.to_date
  if time > sunset_time_for(date)
    date += 1
  end
  date
end
localize(time) click to toggle source
# File lib/bahai_date/logic.rb, line 102
def localize(time)
  (@tz.utc_to_local(time)).to_time
end