Class: Date

Inherits:
Object
  • Object
show all
Defined in:
lib/hijri/gregorian.rb

Instance Method Summary collapse

Instance Method Details

#last_day_of_gregorian_month(month) ⇒ Object



6
7
8
9
10
11
12
# File 'lib/hijri/gregorian.rb', line 6

def last_day_of_gregorian_month(month)
  # Compute the last date of the month for the Gregorian calendar.
  if month == 2
    return 29 if (self.year % 4 == 0 && self.year % 100 != 0) || (self.year % 400 == 0)
  end
  return [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31][month - 1]
end

#to_absObject



14
15
16
17
18
19
20
21
# File 'lib/hijri/gregorian.rb', line 14

def to_abs
  @d = self.day
  @m = self.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_hijriObject



2
3
4
# File 'lib/hijri/gregorian.rb', line 2

def to_hijri
  Hijri::Date.new *Hijri::Converter.greo_to_hijri(self)
end