ethiopic_date 0.0.4 → 0.0.5

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,3 +1,3 @@
1
1
  module EthiopicDate
2
- VERSION = "0.0.4"
2
+ VERSION = "0.0.5"
3
3
  end
data/lib/ethiopic_date.rb CHANGED
@@ -1,6 +1,7 @@
1
1
  # encoding: utf-8
2
2
  require "ethiopic_date/version"
3
- module EthiopicDate
3
+ require "date"
4
+ class EthiopicDate
4
5
  # A Ruby implementation of Ethiopic Calendar based on the Mathematical algorithm
5
6
  # from http://ethiopic.org/Calendars/
6
7
 
@@ -44,7 +45,7 @@ module EthiopicDate
44
45
  #@example fromEthiopicToGregorian(2012,5,21)
45
46
  def fromGregorianToEthiopic(year,month,day)
46
47
  #TODO : Handle Exceptions when there is a wrong input
47
- ethiopic_date = {:year=>-1,:month=>-1,:day => -1 }
48
+ date = {:year=>-1,:month=>-1,:day => -1 }
48
49
  jdn = jdn_from_gregorian(year,month,day)
49
50
  if jdn >=JD_EPOCH_OFFSET_AMETE_MIHRET + 365
50
51
  era= JD_EPOCH_OFFSET_AMETE_MIHRET
@@ -53,10 +54,12 @@ module EthiopicDate
53
54
  end
54
55
  r = (jdn - era).modulo(1461)
55
56
  n = (r.modulo(365) ) + (365 * (r/1460 ))
56
- ethiopic_date[:year] =4 * ((jdn - era)/1461) + r/365 - r/1460
57
- ethiopic_date[:month] =(n/30) + 1
58
- ethiopic_date[:day] =(n.modulo(30)) + 1
59
- return [ethiopic_date[:year],ethiopic_date[:month],ethiopic_date[:day]].join("-").to_s
57
+ date[:year] =4 * ((jdn - era)/1461) + r/365 - r/1460
58
+ date[:month] =(n/30) + 1
59
+ date[:day] =(n.modulo(30)) + 1
60
+
61
+ ethiopic_date=Date.new(date[:year],date[:month],date[:day])
62
+ return ethiopic_date_format(ethiopic_date)
60
63
  end
61
64
 
62
65
 
@@ -66,10 +69,9 @@ module EthiopicDate
66
69
  #@return a formated Ethiopic date string
67
70
  #@example ethiopic_date_format('2004-5-21') will be ጥር 21 ቀን 2004ዓ/ም
68
71
  def ethiopic_date_format(in_date)
69
- date_string=in_date.split("-")
70
- year=date_string[0].to_i
71
- month=date_string[1].to_i
72
- day=date_string[2].to_i
72
+ year=in_date.year
73
+ month=in_date.month
74
+ day=in_date.day
73
75
  month_name =""
74
76
  case month
75
77
  when 1 then month_name=" መስከረም "
@@ -86,7 +88,7 @@ module EthiopicDate
86
88
  when 12 then month_name=" ነሃሴ "
87
89
  when 13 then month_name=" ጳጉሜን "
88
90
  end
89
- date="#{month_name} #{day} ቀን #{year}ዓ/ም"
91
+ return "#{month_name} #{day} ቀን #{year}ዓ/ም"
90
92
  end
91
93
 
92
94
  private
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.4
5
+ version: 0.0.5
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-09 00:00:00 Z
13
+ date: 2012-11-10 00:00:00 Z
14
14
  dependencies: []
15
15
 
16
16
  description: Simple gem to convert between Ethiopian and Gregorian dates