Class: Hijri::Date
- Inherits:
-
Object
- Object
- Hijri::Date
- Defined in:
- lib/hijri/date.rb
Direct Known Subclasses
Constant Summary collapse
- MONTHNAMES_EN =
%w(Muharram Safar Rabia-Awwal Rabia-Thani Jumaada-Awal Jumaada-Thani Rajab Sha'ban Ramadan Shawwal Dhul-Qi'dah Dhul-Hijjah)
- DAYNAMES =
%w(as-Sabt al-Ahad al-Ithnayn ath-Thalaathaa al-Arba'aa' al-Khamis al-Jumu'ah)
Instance Attribute Summary collapse
-
#day ⇒ Object
Returns the value of attribute day.
-
#month ⇒ Object
Returns the value of attribute month.
-
#year ⇒ Object
Returns the value of attribute year.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(year = 1, month = 1, day = 1) ⇒ Date
constructor
A new instance of Date.
- #islamic_leap_year? ⇒ Boolean
- #last_day_of_islamic_month ⇒ Object
- #to_abs ⇒ Object
- #to_greo ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(year = 1, month = 1, day = 1) ⇒ Date
Returns a new instance of Date.
8 9 10 |
# File 'lib/hijri/date.rb', line 8 def initialize(year=1, month=1, day=1) @year, @month, @day = year, month, day end |
Instance Attribute Details
#day ⇒ Object
Returns the value of attribute day.
4 5 6 |
# File 'lib/hijri/date.rb', line 4 def day @day end |
#month ⇒ Object
Returns the value of attribute month.
4 5 6 |
# File 'lib/hijri/date.rb', line 4 def month @month end |
#year ⇒ Object
Returns the value of attribute year.
4 5 6 |
# File 'lib/hijri/date.rb', line 4 def year @year end |
Class Method Details
.today ⇒ Object
39 40 41 42 |
# File 'lib/hijri/date.rb', line 39 def today date = ::Date.today date.to_hijri end |
Instance Method Details
#islamic_leap_year? ⇒ Boolean
12 13 14 |
# File 'lib/hijri/date.rb', line 12 def islamic_leap_year? return (((((11 * self.year) + 14) % 30) < 11) ? true : false) end |
#last_day_of_islamic_month ⇒ Object
16 17 18 19 |
# File 'lib/hijri/date.rb', line 16 def last_day_of_islamic_month # Last day in month during year on the Islamic calendar. return ((self.month % 2 == 1) || (self.month == 12 && islamic_leap_year?) ? 30 : 29) end |
#to_abs ⇒ Object
25 26 27 28 29 30 31 32 |
# File 'lib/hijri/date.rb', line 25 def to_abs month_days = 29 * (month - 1) # days on this year nonleap_year_days = 354 * (year - 1) leap_year_days = (3 + (11 * year)) / 30.0 this_year = (month / 2.0).to_i return (day + month_days + this_year + nonleap_year_days + leap_year_days + Hijri::ISLAMIC_EPOCH).to_i end |
#to_greo ⇒ Object
34 35 36 |
# File 'lib/hijri/date.rb', line 34 def to_greo ::Date.new *Converter.hijri_to_greo(self) end |
#to_s ⇒ Object
21 22 23 |
# File 'lib/hijri/date.rb', line 21 def to_s "#{@year}-#{sprintf('%02d', @month)}-#{sprintf('%02d', @day)}" end |