ethiopic_calendar 0.1.7

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,5 @@
1
+ README.rdoc
2
+ Rakefile
3
+ ethiopic_calendar.gemspec
4
+ lib/ethiopic_calendar.rb
5
+ Manifest
@@ -0,0 +1,22 @@
1
+ = Ethiopic Calendar
2
+ This is a Ruby implementation of the EthiopicCalendar based on the algorithm found on
3
+ http://ethiopic.org/Calendars/
4
+ = Install
5
+ gem install ethiopic_calendar
6
+ = Usage
7
+ 1. Include it in your Gemfile
8
+ gem 'ethiopic_calendar'
9
+ 2. Add the require and include statements in config/application.rb
10
+ # ...
11
+ # This will include the ethiopic_calendar file
12
+ require 'ethiopic_calendar'
13
+ # This will enable you to use the methods inside EthiopicCalendar module without
14
+ # the qualified name, i.e EthiopicCalendar.fromGregorianToEthiopic
15
+ # instead you can simply say fromGregorianToEthiopic
16
+ include EthiopicCalendar
17
+ = License
18
+ This product is licensed under GPL-version 3 as defined in this site http://www.gnu.org/copyleft/gpl.html
19
+ = Authors
20
+ Gebreyohannes Zenebe, gebreyohannes@gemhalo.org
21
+ Yared Getachew , yared@gemhalo.org
22
+
@@ -0,0 +1,12 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+ require 'echoe'
4
+ Echoe.new('ethiopic_calendar','0.1.7') do |p|
5
+ p.description = "A simple Ethiopic to Gregorian calendar changer"
6
+ p.url = "http://github.com/vedtechpro/ethiopic_calendar"
7
+ p.author = ["Gebreyohannes Zenebe", "Yared Getachew Tessema"]
8
+ p.email = ["gebreyohannes@gemhalo.org","yared@gemhalo.org"]
9
+ p.ignore_pattern = ["tmp/*","script/*"]
10
+ p.development_dependencies = []
11
+ end
12
+ Dir["#{File.dirname(__FILE__)}/tasks/*.rake"].sort.each { |ext| load ext }
@@ -0,0 +1,29 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ Gem::Specification.new do |s|
4
+ s.name = "ethiopic_calendar"
5
+ s.version = "0.1.7"
6
+
7
+ s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
8
+ s.authors = ["Gebreyohannes Zenebe, Yared Getachew Tessema"]
9
+ s.date = "2012-02-23"
10
+ s.description = "A simple Ethiopic to Gregorian calendar changer"
11
+ s.email = ["gebreyohannes@gemhalo.org", "yared@gemhalo.org"]
12
+ s.extra_rdoc_files = ["README.rdoc", "lib/ethiopic_calendar.rb"]
13
+ s.files = ["README.rdoc", "Rakefile", "ethiopic_calendar.gemspec", "lib/ethiopic_calendar.rb", "Manifest"]
14
+ s.homepage = "http://github.com/vedtechpro/ethiopic_calendar"
15
+ s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Ethiopic_calendar", "--main", "README.rdoc"]
16
+ s.require_paths = ["lib"]
17
+ s.rubyforge_project = "ethiopic_calendar"
18
+ s.rubygems_version = "1.8.10"
19
+ s.summary = "A simple Ethiopic to Gregorian calendar changer"
20
+
21
+ if s.respond_to? :specification_version then
22
+ s.specification_version = 3
23
+
24
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
25
+ else
26
+ end
27
+ else
28
+ end
29
+ end
@@ -0,0 +1,118 @@
1
+ # encoding: utf-8
2
+ module EthiopicCalendar
3
+ # A Ruby implementation of Ethiopic Calendar based on the Mathematical algorithm
4
+ # from http://ethiopic.org/Calendars/
5
+
6
+ # Constants used
7
+ public
8
+ #Ethiopic: Julian date offset
9
+ JD_EPOCH_OFFSET_AMETE_MIHRET = 1723856 # ዓ/ም
10
+
11
+ #Coptic : Julian date offset
12
+ JD_EPOCH_OFFSET_COPTIC = 1824665
13
+
14
+ JD_EPOCH_OFFSET_GREGORIAN = 1721426
15
+ JD_EPOCH_OFFSET_AMETE_ALEM = -285019 # ዓ/ዓ
16
+
17
+
18
+ #Changes from in_date:EthiopicDate to GregorianDate
19
+ #
20
+ #@api public
21
+ #@param in_date always must be year,month, day in that order
22
+ #@return GregorianDate is returned
23
+ #@example fromEthiopicToGregorian('2004/5/21')
24
+
25
+ def fromEthiopicToGregorian(year,month,day)
26
+ #TODO : Handle Exceptions when there is a wrong input
27
+ gregorian_date = {:year => -1, :month => -1, :day => -1}
28
+ jdn = jdn_from_ethiopic(year,month,day)
29
+ if year <= 0
30
+ era = JD_EPOCH_OFFSET_AMETE_ALEM
31
+ else
32
+ era = JD_EPOCH_OFFSET_AMETE_MIHRET
33
+ end
34
+ r = (jdn - era).modulo(1461)
35
+ n = (r.modulo(365) ) + (365 * (r/1460 ))
36
+ gregorian_date[:year] = 4 * ((jdn - era)/1461) + r/365 - r/1460
37
+ gregorian_date[:month] = (n/30) + 1
38
+ gregorian_date[:day] = (n.modulo(30)) + 1
39
+ return [gregorian_date[:year],gregorian_date[:month],gregorian_date[:day]].join("-").to_s
40
+ end
41
+
42
+ #Changes from in_date:GregorianDate to EthiopicDate
43
+ #
44
+ #@api public
45
+ #@param in_date always must be an aray containing year,month, day in that order
46
+ #@return EthiopicDate is returned
47
+ #@example fromEthiopicToGregorian('2012/5/21')
48
+ def fromGregorianToEthiopic(year,month,day)
49
+ #TODO : Handle Exceptions when there is a wrong input
50
+ ethiopic_date = {:year=>-1,:month=>-1,:day => -1 }
51
+ jdn = jdn_from_gregorian(year,month,day)
52
+ if jdn >=JD_EPOCH_OFFSET_AMETE_MIHRET + 365
53
+ era= JD_EPOCH_OFFSET_AMETE_MIHRET
54
+ else
55
+ era= JD_EPOCH_OFFSET_AMETE_ALEM
56
+ end
57
+ r = (jdn - era).modulo(1461)
58
+ n = (r.modulo(365) ) + (365 * (r/1460 ))
59
+ ethiopic_date[:year] =4 * ((jdn - era)/1461) + r/365 - r/1460
60
+ ethiopic_date[:month] =(n/30) + 1
61
+ ethiopic_date[:day] =(n.modulo(30)) + 1
62
+ return [ethiopic_date[:year],ethiopic_date[:month],ethiopic_date[:day]].join("-").to_s
63
+ end
64
+
65
+
66
+ #Date format for Ethiopic date
67
+ #
68
+ #@api public
69
+ #@return a formated Ethiopic date string
70
+ #@example ethiopic_date_format(2004-5-21,"y-m-d") will be ጥር 21 ቀን 2004ዓ/ም
71
+ def ethiopic_date_format(in_date)
72
+ date_string=in_date.split("-")
73
+ year=date_string[0].to_i
74
+ month=date_string[1].to_i
75
+ day=date_string[2].to_i
76
+ month_name =""
77
+ case month
78
+ when 1 then month_name=" መስከረም "
79
+ when 2 then month_name=" ጥቅምት "
80
+ when 3 then month_name=" ህዳር "
81
+ when 4 then month_name=" ታህሳስ "
82
+ when 5 then month_name=" ጥር "
83
+ when 6 then month_name=" የካቲት "
84
+ when 7 then month_name=" መጋቢት "
85
+ when 8 then month_name=" ሚያዝያ "
86
+ when 9 then month_name=" ግንቦት "
87
+ when 10 then month_name=" ሰኔ "
88
+ when 11 then month_name=" ሐምሌ "
89
+ when 12 then month_name=" ነሃሴ "
90
+ when 13 then month_name=" ጳጉሜን "
91
+ end
92
+ date="#{month_name} #{day} ቀን #{year} ዓ/ም"
93
+ end
94
+
95
+ private
96
+ #Calculates the jdn from given Gregorian calendar
97
+ #
98
+ #@api private
99
+ #@return jdn
100
+ def jdn_from_gregorian(year,month,day)
101
+ s = ( year/4 ) - ( year - 1)/4 - ( year/100 ) + ( year - 1)/100 + ( year/ 400 ) - ( year - 1)/400
102
+ t = ( 14 - month)/12
103
+ n = 31 * t * (month - 1) + (1 - t) * (59 + s + 30 * (month - 3) + ( (3*month - 7)/ 5) ) + day - 1
104
+ j = JD_EPOCH_OFFSET_GREGORIAN + 365 * (year - 1) + ( year - 1)/4 - ( year - 1)/100 + ( year - 1)/400 + n
105
+ return j
106
+ end
107
+ #Calculates the jdn from given Ethiopic calendar
108
+ #
109
+ #@api private
110
+ #@return jdn
111
+ def jdn_from_ethiopic(year,month,day)
112
+ #TODO : to be implemented
113
+ jdn = 0
114
+ return jdn
115
+ end
116
+
117
+
118
+ end
metadata ADDED
@@ -0,0 +1,59 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ethiopic_calendar
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.7
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Gebreyohannes Zenebe, Yared Getachew Tessema
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-02-23 00:00:00.000000000Z
13
+ dependencies: []
14
+ description: A simple Ethiopic to Gregorian calendar changer
15
+ email:
16
+ - gebreyohannes@gemhalo.org
17
+ - yared@gemhalo.org
18
+ executables: []
19
+ extensions: []
20
+ extra_rdoc_files:
21
+ - README.rdoc
22
+ - lib/ethiopic_calendar.rb
23
+ files:
24
+ - README.rdoc
25
+ - Rakefile
26
+ - ethiopic_calendar.gemspec
27
+ - lib/ethiopic_calendar.rb
28
+ - Manifest
29
+ homepage: http://github.com/vedtechpro/ethiopic_calendar
30
+ licenses: []
31
+ post_install_message:
32
+ rdoc_options:
33
+ - --line-numbers
34
+ - --inline-source
35
+ - --title
36
+ - Ethiopic_calendar
37
+ - --main
38
+ - README.rdoc
39
+ require_paths:
40
+ - lib
41
+ required_ruby_version: !ruby/object:Gem::Requirement
42
+ none: false
43
+ requirements:
44
+ - - ! '>='
45
+ - !ruby/object:Gem::Version
46
+ version: '0'
47
+ required_rubygems_version: !ruby/object:Gem::Requirement
48
+ none: false
49
+ requirements:
50
+ - - ! '>='
51
+ - !ruby/object:Gem::Version
52
+ version: '1.2'
53
+ requirements: []
54
+ rubyforge_project: ethiopic_calendar
55
+ rubygems_version: 1.8.10
56
+ signing_key:
57
+ specification_version: 3
58
+ summary: A simple Ethiopic to Gregorian calendar changer
59
+ test_files: []