Method: Hijri::Converter.absolute_to_hijri

Defined in:
lib/hijri/converter.rb

.absolute_to_hijri(abs) ⇒ Object



96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
# File 'lib/hijri/converter.rb', line 96

def absolute_to_hijri(abs)
  # Computes the Islamic date from the absolute date.
  if abs <= ISLAMIC_EPOCH
    # Date is pre-Islamic
    month = 0
    day = 0
    year = 0
  elsif

    # Search forward year by year from approximate year
    year = ((abs - ISLAMIC_EPOCH) / 355.0).to_i
    while abs >= hijri_to_absolute(year+1, 1, 1)
      year += 1
    end

    # Search forward month by month from Muharram
    month = 1
    while abs > hijri_to_absolute(year, month, last_day_of_islamic_month(month, year))
      month += 1
    end

    day = abs - hijri_to_absolute(year, month, 1) + 1
  end

  return [year, month, day]
end