bahai_date 1.4.0 → 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,253 @@
1
+ require "date"
2
+ require "bahai_date/astro/tables"
3
+
4
+ module BahaiDate
5
+ # Astronomical algorithms from Jean Meeus, _Astronomical Algorithms_, 2nd
6
+ # English Edition, Willmann-Bell, Inc., Richmond, Virginia, 1999.
7
+ #
8
+ # This started life as the astro-algo gem. It is now a plain module: it used
9
+ # to reopen Numeric, Array and DateTime on load, which is not acceptable for
10
+ # a gem that gets pulled into other applications.
11
+ module Astro
12
+ PHASE_NEW = 0
13
+ PHASE_FIRST_QUARTER = 1
14
+ PHASE_FULL = 2
15
+ PHASE_LAST_QUARTER = 3
16
+
17
+ # Difference between dynamical time and UTC, in seconds.
18
+ # Good from -1999 to +3000.
19
+ def self.delta_T(date)
20
+ year = date.year.to_f
21
+ y = year + (date.month.to_f - 0.5) / 12.0
22
+
23
+ if year < -500.0
24
+ u = (year - 1820.0) / 100.0
25
+ -20.0 + 32.0 * u * u
26
+ elsif year < 500.0
27
+ poly_eval([0.0090316521, 0.022174192, -0.1798452, -5.952053, 33.78311, -1014.41, 10583.6], y / 100.0)
28
+ elsif year < 1600.0
29
+ poly_eval([0.0083572073, -0.005050998, -0.8503463, 0.319781, 71.23472, -556.01, 1574.2], (y - 1000.0) / 100.0)
30
+ elsif year < 1700.0
31
+ poly_eval([1.0 / 7129.0, -0.01532, -0.9808, 120.0], y - 1600.0)
32
+ elsif year < 1800.0
33
+ poly_eval([-1.0 / 1174000.0, 0.00013336, -0.0059285, 0.1603, 8.83], y - 1700.0)
34
+ elsif year < 1860.0
35
+ poly_eval([0.000000000875, -0.0000001699, 0.0000121272, -0.00037436, 0.0041116, 0.0068612, -0.332447, 13.72], y - 1800.0)
36
+ elsif year < 1900.0
37
+ poly_eval([1.0 / 233174.0, -0.0004473624, 0.01680668, -0.251754, 0.5737, 7.62], y - 1860.0)
38
+ elsif year < 1920.0
39
+ poly_eval([-0.000197, 0.0061966, -0.0598939, 1.494119, -2.79], y - 1900.0)
40
+ elsif year < 1941.0
41
+ poly_eval([0.0020936, -0.076100, 0.84493, 21.20], y - 1920.0)
42
+ elsif year < 1961.0
43
+ poly_eval([1.0 / 2547.0, -1.0 / 233.0, 0.407, 29.07], y - 1950.0)
44
+ elsif year < 1986.0
45
+ poly_eval([-1.0 / 718.0, -1.0 / 260.0, 1.067, 45.45], y - 1975.0)
46
+ elsif year < 2005.0
47
+ poly_eval([0.00002373599, 0.000651814, 0.0017275, -0.060374, 0.3345, 63.86], y - 2000.0)
48
+ elsif year < 2050.0
49
+ poly_eval([0.005589, 0.32217, 62.92], y - 2000.0)
50
+ elsif year < 2150.0
51
+ -20.0 + 32.0 * ((y - 1820.0) / 100.0)**2 - 0.5628 * (2150.0 - y)
52
+ else
53
+ u = (year - 1820.0) / 100.0
54
+ -20.0 + 32.0 * u * u
55
+ end
56
+ end
57
+
58
+ # Converts a DateTime in dynamical time to UTC. Returns a DateTime.
59
+ def self.utc(date)
60
+ date - delta_T(date).to_r / 86400
61
+ end
62
+
63
+ # Date and time of the given phase of the Moon. k is the lunation number,
64
+ # counted from the first new Moon of the year 2000.
65
+ def self.date_of_moon(k, phase)
66
+ k += phase / 4.0
67
+
68
+ # Julian centuries
69
+ t = k / 1236.85
70
+
71
+ # Julian ephemeris days
72
+ jde = 2_451_550.097_66 +
73
+ 29.530_588_861 * k +
74
+ poly_eval([0.000_000_000_73, -0.000_000_150, 0.000_154_37, 0.0, 0.0], t)
75
+
76
+ # Eccentricity of the Earth's orbit
77
+ e = poly_eval([-0.000_0074, -0.002_516, 1.0], t)
78
+
79
+ # Sun's mean anomaly
80
+ m = 2.5534 +
81
+ 29.105_356_70 * k +
82
+ poly_eval([-0.000_000_11, -0.000_0014, 0.0, 0.0], t)
83
+
84
+ # Moon's mean anomaly
85
+ m_lun = 201.5643 +
86
+ 385.816_935_28 * k +
87
+ poly_eval([-0.000_000_058, 0.000_012_38, 0.010_7582, 0.0, 0.0], t)
88
+
89
+ # Moon's argument of latitude
90
+ f = 160.7108 +
91
+ 390.670_502_84 * k +
92
+ poly_eval([0.000_000_011, -0.000_002_27, -0.001_6118, 0.0, 0.0], t)
93
+
94
+ # Longitude of the ascending node of the lunar orbit
95
+ o = 124.7746 -
96
+ 1.563_755_88 * k +
97
+ poly_eval([0.000_002_15, 0.002_0672, 0.0, 0.0], t)
98
+
99
+ if phase == PHASE_NEW || phase == PHASE_FULL
100
+ column = (phase == PHASE_NEW) ? 0 : 1
101
+ jde += TABLE_49B.inject(0.0) do |sum, term|
102
+ coefficient = term[column]
103
+ term[2].times { coefficient *= e }
104
+ angle = term[3] * f + term[4] * m + term[5] * m_lun + term[6] * o
105
+ sum + coefficient * Math.sin(radians(angle % 360.0))
106
+ end
107
+ else
108
+ jde += TABLE_49C.inject(0.0) do |sum, term|
109
+ coefficient = term[0]
110
+ term[1].times { coefficient *= e }
111
+ angle = term[2] * f + term[3] * m + term[4] * m_lun + term[5] * o
112
+ sum + coefficient * Math.sin(radians(angle % 360.0))
113
+ end
114
+
115
+ w = 0.00002 * Math.cos(radians(2.0 * f)) +
116
+ 0.00002 * Math.cos(radians(m_lun + m)) -
117
+ 0.00002 * Math.cos(radians(m_lun - m)) +
118
+ 0.00026 * Math.cos(radians(m_lun)) -
119
+ 0.00038 * e * Math.cos(radians(m)) +
120
+ 0.00306
121
+
122
+ jde += (phase == PHASE_FIRST_QUARTER) ? w : -w
123
+ end
124
+
125
+ # Correction for all phases
126
+ t_squared = t * t
127
+ jde += TABLE_49A.inject(0.0) do |sum, term|
128
+ a = term[0] + term[1] * k + term[3] * t_squared
129
+ sum + Math.sin(radians(a % 360.0)) * term[2]
130
+ end
131
+
132
+ DateTime.jd(jde.to_r) + 0.5
133
+ end
134
+
135
+ # Number of the first lunation (new Moon) of the given year. Lunation 0 is
136
+ # the first new Moon of the year 2000.
137
+ def self.first_lunation_of_year(year)
138
+ k = ((year - 2000) * 12.3685).floor
139
+ k += 1 while date_of_moon(k, PHASE_NEW).year < year
140
+ k
141
+ end
142
+
143
+ # Date and time of the vernal equinox, from the lower accuracy algorithm of
144
+ # chapter 27. Good from about -1000 to +3000.
145
+ def self.date_of_vernal_equinox_low_accuracy(year)
146
+ if year >= 1000
147
+ y = (year - 2000.0) / 1000.0
148
+ jdme = poly_eval([-0.000_57, -0.004_11, 0.051_69, 365_242.374_04, 2_451_623.809_84], y)
149
+ else
150
+ y = year / 1000.0
151
+ jdme = poly_eval([-0.000_71, 0.001_11, 0.061_34, 365_242.137_40, 1_721_139.291_89], y)
152
+ end
153
+
154
+ # Julian centuries from 2000
155
+ t = (jdme - 2_451_545.0) / 36525.0
156
+
157
+ w = radians(35_999.373 * t - 2.47)
158
+ lambda = 1.0 + 0.0334 * Math.cos(w) + 0.0007 * Math.cos(2.0 * w)
159
+ # Unlike the Earth tables below, this one takes its argument in degrees.
160
+ s = TABLE_27C.inject(0.0) { |accum, (a, b, c)| accum + a * Math.cos(radians(b + c * t)) }
161
+
162
+ DateTime.jd((jdme + 0.000_01 * s / lambda).to_r) + 0.5
163
+ end
164
+
165
+ # Date and time of the vernal equinox, from the higher accuracy algorithm of
166
+ # chapter 27. Returns a DateTime in dynamical time.
167
+ def self.date_of_vernal_equinox(year)
168
+ est_date = date_of_vernal_equinox_low_accuracy(year)
169
+
170
+ 5.times do
171
+ sol_long = solar_longitude(est_date)
172
+ sol_long -= 360.0 if sol_long > 180.0
173
+ break if sol_long.abs < 0.000001
174
+ est_date += (58 * Math.sin(radians(-sol_long))).to_r
175
+ end
176
+
177
+ est_date
178
+ end
179
+
180
+ # Nutation in longitude of the Earth's pole for the given DateTime, in
181
+ # degrees. Chapter 22.
182
+ def self.nutation_in_longitude(date)
183
+ # Julian centuries from the epoch J2000.0
184
+ t = (date.ajd.to_f - 2451545.0) / 36525.0
185
+
186
+ # Mean elongation of the Moon from the Sun
187
+ d = poly_eval([1.0 / 189_474.0, -0.001_9142, 445_267.111_480, 297.85036], t) % 360.0
188
+
189
+ # Mean anomaly of the Sun (Earth)
190
+ m = poly_eval([-1.0 / 300_000.0, -0.000_1603, 35_999.050_340, 357.52772], t) % 360.0
191
+
192
+ # Mean anomaly of the Moon
193
+ m_lun = poly_eval([1.0 / 56_250.0, 0.008_6972, 477_198.867_398, 134.96298], t) % 360.0
194
+
195
+ # Moon's argument of latitude
196
+ f = poly_eval([1.0 / 327_270.0, -0.003_6825, 483_202.017_538, 93.27191], t) % 360.0
197
+
198
+ # Longitude of the ascending node of the Moon's mean orbit on the ecliptic
199
+ omega = poly_eval([1.0 / 450_000.0, 0.002_0708, -1934.136_261, 125.04452], t) % 360.0
200
+
201
+ TABLE_22A.inject(0.0) do |nutation, term|
202
+ angle = term[0] * d + term[1] * m + term[2] * m_lun + term[3] * f + term[4] * omega
203
+ nutation + (term[5] + term[6] * t) * Math.sin(radians(angle)) / 36_000_000.0
204
+ end
205
+ end
206
+
207
+ # Longitude of the Sun for the given DateTime, in degrees. The higher
208
+ # accuracy algorithm of chapter 25: within 1" between -2000 and +6000.
209
+ def self.solar_longitude(date)
210
+ # Julian millennia from the epoch J2000.0 (2000 January 1.5 TD)
211
+ t = (date.ajd.to_f - 2451545.0) / 365250.0
212
+
213
+ l0 = sum_terms(EARTH_L0, t)
214
+ l1 = sum_terms(EARTH_L1, t)
215
+ l2 = sum_terms(EARTH_L2, t)
216
+ l3 = sum_terms(EARTH_L3, t)
217
+ l4 = sum_terms(EARTH_L4, t)
218
+ l5 = sum_terms(EARTH_L5, t)
219
+ long = poly_eval([l5, l4, l3, l2, l1, l0], t) * 1e-8 * 180.0 / Math::PI % 360.0
220
+
221
+ r0 = sum_terms(EARTH_R0, t)
222
+ r1 = sum_terms(EARTH_R1, t)
223
+ r2 = sum_terms(EARTH_R2, t)
224
+ r3 = sum_terms(EARTH_R3, t)
225
+ r4 = sum_terms(EARTH_R4, t)
226
+ radius = poly_eval([r4, r3, r2, r1, r0], t) * 1e-8
227
+
228
+ long -= 180.0 # switch to the Earth's perspective
229
+ long += -2.509167e-5 # convert to the FK5 system
230
+ long += nutation_in_longitude(date)
231
+ long += -0.0056916111 / radius # correct for aberration
232
+ long % 360.0
233
+ end
234
+
235
+ # Sum of the periodic terms of a Meeus table of [A, B, C] rows:
236
+ # sum(A * cos(B + C*t)). B is already an angle for the Earth tables; the
237
+ # ones that need degrees converted (TABLE_27C) sum themselves.
238
+ def self.sum_terms(table, t)
239
+ table.inject(0.0) { |accumulator, (a, b, c)| accumulator + a * Math.cos(b + c * t) }
240
+ end
241
+
242
+ # Degrees to radians.
243
+ def self.radians(degrees)
244
+ degrees * Math::PI / 180.0
245
+ end
246
+
247
+ # Horner's method. The coefficients run from the highest order term down to
248
+ # the constant term, as printed in the book.
249
+ def self.poly_eval(coefficients, x)
250
+ coefficients.inject(0.0) { |accumulator, coefficient| accumulator * x + coefficient }
251
+ end
252
+ end
253
+ end
@@ -4,21 +4,21 @@ module BahaiDate
4
4
 
5
5
  attr_reader :weekday, :day, :month, :year, :gregorian_date
6
6
 
7
- def initialize(params)
8
- if params[:date]
9
- @gregorian_date = params[:date]
7
+ def initialize(date: nil, year: nil, month: nil, day: nil)
8
+ if date
9
+ @gregorian_date = to_date(date)
10
10
  year, month, day = from_gregorian
11
11
  @year = Year.new(year)
12
12
  @month = Month.new(month)
13
13
  @day = Day.new(day)
14
- elsif params[:year] && params[:month] && params[:day]
15
- @year = Year.new(params[:year])
16
- @month = Month.new(params[:month])
17
- @day = Day.new(params[:day])
14
+ elsif year && month && day
15
+ @year = Year.new(year)
16
+ @month = Month.new(month)
17
+ @day = Day.new(day)
18
18
  validate_ayyam_i_ha
19
19
  @gregorian_date = to_gregorian
20
20
  else
21
- fail ArgumentError, 'Invalid arguments. Use a hash with :date or with :year, :month, and :day.'
21
+ fail ArgumentError, "Invalid arguments. Use :date or :year, :month, and :day."
22
22
  end
23
23
  @weekday = Weekday.new(weekday_from_gregorian)
24
24
  end
@@ -39,16 +39,22 @@ module BahaiDate
39
39
  "#{@day.number} #{@month} #{@year.bahai_era}"
40
40
  end
41
41
 
42
- def +(val)
43
- self.class.new(date: @gregorian_date + val)
42
+ def +(other)
43
+ self.class.new(date: @gregorian_date + other)
44
44
  end
45
45
 
46
- def -(val)
47
- self.class.new(date: @gregorian_date - val)
46
+ def -(other)
47
+ self.class.new(date: @gregorian_date - other)
48
48
  end
49
49
 
50
50
  private
51
51
 
52
+ def to_date(date)
53
+ fail ArgumentError, "date must be a Date, or respond to to_date (such as a Time or DateTime)" unless date.respond_to?(:to_date)
54
+
55
+ date.to_date.tap { |converted| Logic.check_gregorian_year(converted.year) }
56
+ end
57
+
52
58
  def validate_ayyam_i_ha
53
59
  fail ArgumentError, "'#{@day.number}' is not a valid day for Ayyam-i-Ha in the year #{@year.bahai_era}" if @month.number == AYYAM_I_HA && @day.number > ayyam_i_ha_days
54
60
  end
@@ -84,7 +90,7 @@ module BahaiDate
84
90
  day = days - (342 + ayyam_i_ha_days(year))
85
91
  end
86
92
  else
87
- month, day = (days).divmod(19)
93
+ month, day = days.divmod(19)
88
94
  month += 1
89
95
  end
90
96
  day += 1
@@ -93,7 +99,7 @@ module BahaiDate
93
99
 
94
100
  def weekday_from_gregorian
95
101
  # saturday (6 in ruby) is the first day of the week
96
- @gregorian_date.wday == 6 ? 1 : @gregorian_date.wday + 2
102
+ (@gregorian_date.wday == 6) ? 1 : @gregorian_date.wday + 2
97
103
  end
98
104
 
99
105
  def days_from_nawruz
@@ -1,8 +1,8 @@
1
1
  module BahaiDate
2
2
  class Day
3
- TITLES = %w(Baha Jalal Jamal Azamat Nur Rahmat Kalimat Kamal Asma Izzat Mashiyyat Ilm Qudrat Qawl Masail Sharaf Sultan Mulk Ala)
4
- TITLES_HTML = %w(Bahá Jalál Jamál ‘Aẓamat Núr Raḥmat Kalimát Kamál Asmá’ ‘Izzat Ma<u>sh</u>íyyat ‘Ilm Qudrat Qawl Masá’il <u>Sh</u>araf Sulṭán Mulk ‘Alá’)
5
- TITLES_EN = %w(Splendour Glory Beauty Grandeur Light Mercy Words Perfection Names Might Will Knowledge Power Speech Questions Honour Sovereignty Dominion Loftiness)
3
+ TITLES = %w[Baha Jalal Jamal Azamat Nur Rahmat Kalimat Kamal Asma Izzat Mashiyyat Ilm Qudrat Qawl Masail Sharaf Sultan Mulk Ala]
4
+ TITLES_HTML = %w[Bahá Jalál Jamál ‘Aẓamat Núr Raḥmat Kalimát Kamál Asmá’ ‘Izzat Ma<u>sh</u>íyyat ‘Ilm Qudrat Qawl Masá’il <u>Sh</u>araf Sulṭán Mulk ‘Alá’]
5
+ TITLES_EN = %w[Splendour Glory Beauty Grandeur Light Mercy Words Perfection Names Might Will Knowledge Power Speech Questions Honour Sovereignty Dominion Loftiness]
6
6
 
7
7
  attr_reader :number
8
8
  attr_accessor :occasions, :weekday
@@ -36,7 +36,7 @@ module BahaiDate
36
36
 
37
37
  def validate(number_arg)
38
38
  number = number_arg.to_i
39
- return if (1..19).include? number
39
+ return if (1..19).cover? number
40
40
  fail ArgumentError, "'#{number}' is not a valid day. Please use 1 to 19."
41
41
  end
42
42
  end
@@ -1,7 +1,6 @@
1
- require 'bundler/setup'
2
- require 'tzinfo'
3
- require 'solareventcalculator'
4
- require 'astro-algo'
1
+ require "date"
2
+ require "bahai_date/astro"
3
+ require "bahai_date/sunset"
5
4
 
6
5
  module BahaiDate
7
6
  class Logic
@@ -16,32 +15,81 @@ module BahaiDate
16
15
  # Latitude: 35° 41' 45.9996", Longitude: 51° 25' 23.0016"
17
16
  # Converted to decimal using:
18
17
  # http://transition.fcc.gov/mb/audio/bickel/DDDMMSS-decimal.html
19
- TEHRAN_LAT = BigDecimal.new('35.696111')
20
- TEHRAN_LONG = BigDecimal.new('51.423056')
18
+ TEHRAN_LAT = 35.696111
19
+ TEHRAN_LONG = 51.423056
21
20
 
22
- # *** Azimuth (for determining sunset times) ***
21
+ # *** Zenith angle of the Sun at sunset (named azimuth here historically) ***
23
22
  # Source: http://www.timeanddate.com/astronomy/about-sun-calculator.html
24
23
  # "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)."
25
- # Converted to decimal using:
26
- # http://www.satsig.net/degrees-minutes-seconds-calculator.htm
27
- AZIMUTH = 90.833333
28
-
29
- def initialize
30
- @tz = TZInfo::Timezone.get('Asia/Tehran')
31
- end
24
+ AZIMUTH = Sunset::OFFICIAL_ZENITH
25
+
26
+ # Iran Standard Time. Tehran has kept this offset all year since it dropped
27
+ # daylight saving in 2022, and before that daylight saving only ran from
28
+ # late March to late September, so neither Naw-Ruz nor the new moons of the
29
+ # Twin Holy Days ever fell in it. The offset only decides which calendar
30
+ # date a moment is labelled with before it is compared with that date's
31
+ # sunset, so any offset within a few hours gives the same answers; this one
32
+ # matches the zoneinfo answers for every year from 2015 to 3001.
33
+ TEHRAN_UTC_OFFSET = "+03:30"
34
+
35
+ # *** Why dates stop at the Gregorian year 3000 ***
36
+ #
37
+ # From 172 B.E. (2015) Naw-Ruz is the day on which the vernal equinox
38
+ # falls in Tehran, counting days from sunset to sunset, and the Twin Holy
39
+ # Days follow the eighth new moon after it. So the date of Naw-Ruz turns on
40
+ # which side of a Tehran sunset the equinox falls, and in some years the two
41
+ # are minutes apart: within 10 minutes in 2026 and 2059, and within half a
42
+ # minute in 2418.
43
+ #
44
+ # The positions of the Sun and Moon are not the weak point: Meeus's methods
45
+ # (Astro) give the equinox and new moons in Terrestrial Time, a uniform
46
+ # time scale, closely enough to match an ephemeris-based library on every
47
+ # year to 2351 (below). The weak point is turning that into clock time. Clocks follow the Earth's rotation, which is slowing (tidal
48
+ # friction from the Moon) and also speeds up and slows down irregularly
49
+ # (the core, ice and sea level), so the difference between the two, Delta T,
50
+ # can only be measured, not predicted. Astro.delta_T extrapolates it with
51
+ # NASA's polynomials, which run to the year 3000 and no further. By then
52
+ # Delta T is about 74 minutes, and NASA puts the standard error of the
53
+ # prediction at about 10 minutes in 2500 and 31 minutes in 3000
54
+ # (https://eclipse.gsfc.nasa.gov/SEhelp/uncertainty2004.html). Between
55
+ # 2501 and 3001 there are 21 years in which the equinox falls within 30
56
+ # minutes of sunset, so in some of those years this gem's Naw-Ruz will be a
57
+ # day out. The sunset formula (Sunset) is an approximation too.
58
+ #
59
+ # For comparison, bahai.org publishes dates to 221 B.E. (2064), and the
60
+ # badiDate JavaScript library stops after 2351 because Naw-Ruz 2352 may be
61
+ # wrong; this gem agrees with both for every year they cover (see
62
+ # spec/bahai_date/published_calendar_spec.rb and badidate_spec.rb). Past
63
+ # 2351, treat the dates as the best estimate the algorithms give, not as
64
+ # certain.
65
+ #
66
+ # The last Baha'i year that begins by 3000 is 1157, which ends in March 3001.
67
+ MAX_GREGORIAN_YEAR = 3001
32
68
 
33
69
  def self.nawruz_for(year)
34
- new.nawruz_date year
70
+ check_gregorian_year(year)
71
+ # Memoised: every conversion asks for this once or twice per date, and the
72
+ # answer for a given year cannot change within a process.
73
+ @nawruz_dates ||= {}
74
+ @nawruz_dates[year] ||= new.nawruz_date(year)
35
75
  end
36
76
 
37
77
  def self.leap?(year_bahai_era)
78
+ Year.check(year_bahai_era)
38
79
  new.leap? year_bahai_era
39
80
  end
40
81
 
41
82
  def self.twin_holy_days_date(year_bahai_era)
83
+ Year.check(year_bahai_era)
42
84
  new.twin_holy_days_for year_bahai_era
43
85
  end
44
86
 
87
+ def self.check_gregorian_year(year)
88
+ return if year.is_a?(Integer) && year <= MAX_GREGORIAN_YEAR
89
+
90
+ fail ArgumentError, "'#{year}' is outside the supported range. Dates up to the end of the year #{Year::MAX} B.E. (March #{MAX_GREGORIAN_YEAR}) are supported."
91
+ end
92
+
45
93
  def nawruz_date(year)
46
94
  if year < 2015
47
95
  Date.new(year, 3, 21)
@@ -55,13 +103,11 @@ module BahaiDate
55
103
  end
56
104
 
57
105
  def sunset_time_for(date)
58
- calc = SolarEventCalculator.new(date, TEHRAN_LAT, TEHRAN_LONG)
59
- sunset_time = calc.compute_utc_solar_event(AZIMUTH, false)
60
- localize(sunset_time.utc)
106
+ localize(Sunset.utc(date, TEHRAN_LAT, TEHRAN_LONG, AZIMUTH))
61
107
  end
62
108
 
63
109
  def spring_equinox_in_tehran(year)
64
- increment_if_after_sunset localize(Astro.date_of_vernal_equinox(year).to_utc)
110
+ increment_if_after_sunset localize(Astro.utc(Astro.date_of_vernal_equinox(year)))
65
111
  end
66
112
 
67
113
  def twin_holy_days_for(year_bahai_era)
@@ -77,7 +123,7 @@ module BahaiDate
77
123
  end
78
124
 
79
125
  def new_moon(lunation)
80
- localize(Astro.date_of_moon(lunation, Astro::PhaseNew).to_utc)
126
+ localize(Astro.utc(Astro.date_of_moon(lunation, Astro::PHASE_NEW)))
81
127
  end
82
128
 
83
129
  def leap?(year_bahai_era)
@@ -90,7 +136,7 @@ module BahaiDate
90
136
  end
91
137
 
92
138
  def leap_bahai_era?(year)
93
- (nawruz_date(year + 1) - nawruz_date(year)) == 366
139
+ (self.class.nawruz_for(year + 1) - self.class.nawruz_for(year)) == 366
94
140
  end
95
141
 
96
142
  def bahai_era_to_gregorian_year(year)
@@ -100,7 +146,7 @@ module BahaiDate
100
146
  private
101
147
 
102
148
  def localize(time)
103
- (@tz.utc_to_local(time)).to_time
149
+ time.to_time.getlocal(TEHRAN_UTC_OFFSET)
104
150
  end
105
151
 
106
152
  def increment_if_after_sunset(time)
@@ -1,8 +1,8 @@
1
1
  module BahaiDate
2
2
  class Month
3
- TITLES = %w(Baha Jalal Jamal Azamat Nur Rahmat Kalimat Kamal Asma Izzat Mashiyyat Ilm Qudrat Qawl Masail Sharaf Sultan Mulk Ala Ayyam-i-Ha)
4
- TITLES_HTML = %w(Bahá Jalál Jamál ‘Aẓamat Núr Raḥmat Kalimát Kamál Asmá’ ‘Izzat Ma<u>sh</u>íyyat ‘Ilm Qudrat Qawl Masá’il <u>Sh</u>araf Sulṭán Mulk ‘Alá’ Ayyám-i-Há)
5
- TITLES_EN = %w(Splendour Glory Beauty Grandeur Light Mercy Words Perfection Names Might Will Knowledge Power Speech Questions Honour Sovereignty Dominion Loftiness Ayyam-i-Ha)
3
+ TITLES = %w[Baha Jalal Jamal Azamat Nur Rahmat Kalimat Kamal Asma Izzat Mashiyyat Ilm Qudrat Qawl Masail Sharaf Sultan Mulk Ala Ayyam-i-Ha]
4
+ TITLES_HTML = %w[Bahá Jalál Jamál ‘Aẓamat Núr Raḥmat Kalimát Kamál Asmá’ ‘Izzat Ma<u>sh</u>íyyat ‘Ilm Qudrat Qawl Masá’il <u>Sh</u>araf Sulṭán Mulk ‘Alá’ Ayyám-i-Há]
5
+ TITLES_EN = %w[Splendour Glory Beauty Grandeur Light Mercy Words Perfection Names Might Will Knowledge Power Speech Questions Honour Sovereignty Dominion Loftiness Ayyam-i-Ha]
6
6
 
7
7
  attr_reader :number, :days
8
8
 
@@ -29,8 +29,7 @@ module BahaiDate
29
29
  end
30
30
 
31
31
  def add_day(day_number)
32
- return if @days[day_number]
33
- @days[day_number] = Day.new(day_number)
32
+ @days[day_number] ||= Day.new(day_number)
34
33
  end
35
34
 
36
35
  private
@@ -45,7 +44,7 @@ module BahaiDate
45
44
 
46
45
  def validate(number_arg)
47
46
  number = number_arg.to_i
48
- return if (1..19).include?(number) || number == -1
47
+ return if (1..19).cover?(number) || number == -1
49
48
  fail ArgumentError, "'#{number}' is not a valid month. Please use 1 to 19 or -1 for Ayyam-i-Ha."
50
49
  end
51
50
  end
@@ -1,11 +1,11 @@
1
1
  module BahaiDate
2
2
  class Occasion
3
3
  attr_reader :type,
4
- :work_suspended,
5
- :title,
6
- :short_title,
7
- :title_html,
8
- :short_title_html
4
+ :work_suspended,
5
+ :title,
6
+ :short_title,
7
+ :title_html,
8
+ :short_title_html
9
9
  alias_method :work_suspended?, :work_suspended
10
10
 
11
11
  def initialize(opts = {})