Module: EthiopianDate
- Defined in:
- lib/ethiopian_date.rb,
lib/ethiopian_date/version.rb
Defined Under Namespace
Classes: Error
Constant Summary collapse
- Nmonths =
12- MonthDays =
[0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
- AmharicMonths =
{ '1' => 'መስከረም', '2' => 'ጥቅምት', '3' => 'ህዳር', '4' => 'ታህሳስ', '5' => 'ጥር', '6' => 'የካቲት', '7' => 'መጋቢት', '8' => 'ሚያዝያ', '9' => 'ግንቦት', '10' => 'ሰኔ', '11' => 'ሐምሌ', '12' => 'ነሃሴ', '13' => 'ጳጉሜ' }
- AmharicDays =
{ :Sunday => 'እሁድ', :Monday => 'ሰኞ', :Tuesday => 'ማክሰኞ', :Wednesday => 'ሮብ', :Thursday => 'ሓሙስ', :Friday => 'ኣርብ', :Saturday => 'ቅዳሜ' }
- JD_EPOCH_OFFSET_AMETE_MIHRET =
Ethiopic: Julian date offset
1723856- JD_EPOCH_OFFSET_COPTIC =
Coptic : Julian date offset
1824665- JD_EPOCH_OFFSET_GREGORIAN =
1721426- JD_EPOCH_OFFSET_AMETE_ALEM =
ዓ/ዓ
-285019 # ዓ/ዓ
- VERSION =
"2.3.1"
Instance Method Summary collapse
-
#ethiopic_date_format(ethiopic_date) ⇒ Object
Date format for Ethiopic date.
-
#fromEthiopicToGregorian(year, month, day) ⇒ Object
Changes from in_date:EthiopicDate to GregorianDate.
-
#fromGregorianToEthiopic(year, month, day) ⇒ Object
Changes from in_date:GregorianDate to EthiopicDate.
- #to_gregorian(d) ⇒ Object
Instance Method Details
#ethiopic_date_format(ethiopic_date) ⇒ Object
Date format for Ethiopic date
86 87 88 89 90 91 92 93 |
# File 'lib/ethiopian_date.rb', line 86 def ethiopic_date_format(ethiopic_date) d = ethiopic_date.split('-') year = d[0] month = d[1] day = d[2] day = day.to_s.length < 2 ? '0' << day.to_s : day return "#{AmharicMonths[month.to_s]} #{day}, #{year}" end |
#fromEthiopicToGregorian(year, month, day) ⇒ Object
Changes from in_date:EthiopicDate to GregorianDate
36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/ethiopian_date.rb', line 36 def fromEthiopicToGregorian(year, month, day) #TODO : Handle Exceptions when there is a wrong input year = year month = month day = day if (year <= 0) era = JD_EPOCH_OFFSET_AMETE_ALEM else era = JD_EPOCH_OFFSET_AMETE_MIHRET end jdn = jdn_from_ethiopic(year, month, day, era) return gregorian_from_jdn(jdn) end |
#fromGregorianToEthiopic(year, month, day) ⇒ Object
Changes from in_date:GregorianDate to EthiopicDate
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/ethiopian_date.rb', line 65 def fromGregorianToEthiopic(year, month, day) jdn = jdn_from_gregorian(year, month, day) if jdn >= JD_EPOCH_OFFSET_AMETE_MIHRET + 365 era = JD_EPOCH_OFFSET_AMETE_MIHRET else era = JD_EPOCH_OFFSET_AMETE_ALEM end r = (jdn - era).modulo(1461) n = (r.modulo(365)) + (365 * (r / 1460)) eyear = 4 * ((jdn - era) / 1461) + r / 365 - r / 1460 emonth = (n / 30) + 1 eday = (n.modulo(30)) + 1 return "#{eyear}-#{emonth}-#{eday}" end |
#to_gregorian(d) ⇒ Object
50 51 52 53 54 55 56 57 58 |
# File 'lib/ethiopian_date.rb', line 50 def to_gregorian(d) #dt=d.to_s(:db) if d.present? a = d.to_s.split("/") return fromEthiopicToGregorian(a[2].to_i, a[1].to_i, a[0].to_i) else return nil end end |