ethiopic_date 0.0.7 → 0.0.8
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/ethiopic_date/version.rb +1 -1
- data/lib/ethiopic_date.rb +20 -19
- metadata +2 -2
data/lib/ethiopic_date.rb
CHANGED
@@ -9,6 +9,9 @@ module EthiopicDate
|
|
9
9
|
public
|
10
10
|
Nmonths = 12
|
11
11
|
MonthDays = [0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
|
12
|
+
Ethiopic_month_names={:1=>"መስከረም",:2=>"ጥቅምት",:3=>"ህዳር",:4=>"ታህሳስ",5=>"ጥር",
|
13
|
+
:6=>"የካቲት",:7=>"መጋቢት",:8=>"ሚያዝያ",:9=>"ግንቦት",:10=>"ሰኔ",:11=>"ሐምሌ",:12=>"ነሃሴ",:13=>"ጳጉሜን"}
|
14
|
+
|
12
15
|
#Ethiopic: Julian date offset
|
13
16
|
JD_EPOCH_OFFSET_AMETE_MIHRET = 1723856 # ዓ/ም
|
14
17
|
|
@@ -26,11 +29,11 @@ module EthiopicDate
|
|
26
29
|
#@return GregorianDate is returned
|
27
30
|
#@example fromEthiopicToGregorian(2004,5,21)
|
28
31
|
|
29
|
-
def fromEthiopicToGregorian(
|
32
|
+
def fromEthiopicToGregorian(ethiopic_date)
|
30
33
|
#TODO : Handle Exceptions when there is a wrong input
|
31
|
-
year=
|
32
|
-
month=
|
33
|
-
day=
|
34
|
+
year=ethiopic_date[:year]
|
35
|
+
month=ethiopic_date[:month]
|
36
|
+
day=ethiopic_date[:day]
|
34
37
|
if (year <=0)
|
35
38
|
era=JD_EPOCH_OFFSET_AMETE_ALEM
|
36
39
|
else
|
@@ -46,12 +49,12 @@ module EthiopicDate
|
|
46
49
|
#@param year,month, day in that order
|
47
50
|
#@return EthiopicDate is returned
|
48
51
|
#@example fromEthiopicToGregorian(2012,5,21)
|
49
|
-
def fromGregorianToEthiopic(
|
52
|
+
def fromGregorianToEthiopic(gregorian_date)
|
50
53
|
#TODO : Handle Exceptions when there is a wrong input
|
51
|
-
year=
|
52
|
-
month=
|
53
|
-
day=
|
54
|
-
|
54
|
+
year=gregorian_date.year
|
55
|
+
month=gregorian_date.month
|
56
|
+
day=gregorian_date.day
|
57
|
+
ethiopic_date = {:year=>-1,:month=>-1,:day => -1 }
|
55
58
|
jdn = jdn_from_gregorian(year,month,day)
|
56
59
|
if jdn >=JD_EPOCH_OFFSET_AMETE_MIHRET + 365
|
57
60
|
era= JD_EPOCH_OFFSET_AMETE_MIHRET
|
@@ -60,12 +63,11 @@ module EthiopicDate
|
|
60
63
|
end
|
61
64
|
r = (jdn - era).modulo(1461)
|
62
65
|
n = (r.modulo(365) ) + (365 * (r/1460 ))
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
+
ethiopic_date[:year] =4 * ((jdn - era)/1461) + r/365 - r/1460
|
67
|
+
ethiopic_date[:month] =(n/30) + 1
|
68
|
+
ethiopic_date[:day] =(n.modulo(30)) + 1
|
66
69
|
|
67
|
-
|
68
|
-
return ethiopic_date_format(ethiopic_date)
|
70
|
+
return "#{Ethiopic_month_names[:ethiopic_date[:month]]} #{ethiopic_date[:day]} ቀን #{ethiopic_date[:year]}ዓ/ም "
|
69
71
|
end
|
70
72
|
|
71
73
|
|
@@ -74,11 +76,10 @@ module EthiopicDate
|
|
74
76
|
#@api public
|
75
77
|
#@return a formated Ethiopic date string
|
76
78
|
#@example ethiopic_date_format('2004-5-21') will be ጥር 21 ቀን 2004ዓ/ም
|
77
|
-
def ethiopic_date_format(
|
78
|
-
year=
|
79
|
-
month=
|
80
|
-
day=
|
81
|
-
month_name =""
|
79
|
+
def ethiopic_date_format(ethiopic_date)
|
80
|
+
year=ethiopic_date[:year]
|
81
|
+
month=ethiopic_date[:month]
|
82
|
+
day=ethiopic_date[:day]
|
82
83
|
case month
|
83
84
|
when 1 then month_name=" መስከረም "
|
84
85
|
when 2 then month_name=" ጥቅምት "
|
metadata
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
name: ethiopic_date
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: 0.0.
|
5
|
+
version: 0.0.8
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- G/yohannes Zenebe
|
@@ -10,7 +10,7 @@ autorequire:
|
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
12
|
|
13
|
-
date: 2012-11-
|
13
|
+
date: 2012-11-22 00:00:00 Z
|
14
14
|
dependencies: []
|
15
15
|
|
16
16
|
description: Simple gem to convert between Ethiopian and Gregorian dates
|