Class: Hijri::Absolute
- Inherits:
-
Object
- Object
- Hijri::Absolute
- Defined in:
- lib/hijri/absolute.rb
Instance Attribute Summary collapse
-
#absolute ⇒ Object
Returns the value of attribute absolute.
Instance Method Summary collapse
- #gregorian2absolute(day, month, year) ⇒ Object
-
#initialize(abs) ⇒ Absolute
constructor
A new instance of Absolute.
- #to_greo ⇒ Object
-
#to_hijri ⇒ Object
TODO.
Constructor Details
#initialize(abs) ⇒ Absolute
Returns a new instance of Absolute.
5 6 7 |
# File 'lib/hijri/absolute.rb', line 5 def initialize abs self.absolute = abs end |
Instance Attribute Details
#absolute ⇒ Object
Returns the value of attribute absolute.
3 4 5 |
# File 'lib/hijri/absolute.rb', line 3 def absolute @absolute end |
Instance Method Details
#gregorian2absolute(day, month, year) ⇒ Object
def greo_to_hijri(date)
hijri = absolute2islamic(gregorian2absolute(date.day, date.month, date.year))
Hijri.new hijri[0], hijri[1], hijri[2]
end
def hijri_to_greo(date)
greo = absolute2gregorian(islamic2absolute(date.day,date.month,date.year))
Date.new greo[0], greo[1], greo[2]
end
19 20 21 22 23 24 25 26 27 |
# File 'lib/hijri/absolute.rb', line 19 def gregorian2absolute(day, month, year) # # Computes the absolute date from the Gregorian date. @d = day @m = month - 1 @m.downto(1) do |m| @d += last_day_of_gregorian_month(@m, year) end return (@d + 365 * (year - 1) + (year -1) / 4.0 - (year - 1) / 100.0 + (year - 1) / 400.0).to_i end |
#to_greo ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/hijri/absolute.rb', line 29 def to_greo # Computes the Gregorian date from the absolute date. # Search forward year by year from approximate year puts self.absolute year = (self.absolute / 366.0 + 0.5).to_i while (self.absolute >= gregorian2absolute(1, 1, year + 1)) year += 1 end # Search forward month by month from January month = 1 while (self.absolute > gregorian2absolute(last_day_of_gregorian_month(month, year), month, year)) month += 1 end day = self.absolute - gregorian2absolute(1, month, year) + 1 return [year, month, day] end |
#to_hijri ⇒ Object
TODO
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/hijri/absolute.rb', line 47 def to_hijri # Computes the Islamic date from the absolute date. # puts "abs #{abs} and islamicEpoch #{IslamicEpoch}" if (absolute <= Hijri::ISLAMIC_EPOCH) # Date is pre-Islamic month = 0 day = 0 year = 0 elsif # Search forward year by year from approximate year year = ((absolute - Hijri::ISLAMIC_EPOCH) / 355.0).to_i while (absolute >= islamic2absolute(1,1,year+1)) year += 1 end # Search forward month by month from Muharram month = 1 while (absolute > islamic2absolute(last_day_of_islamic_month(month,year), month, year)) month += 1 end day = absolute - islamic2absolute(1, month, year) + 1 end return [year, month, day] end |