hijri_gem 0.4.1

Sign up to get free protection for your applications and to get access to all the features.
data/Manifest ADDED
@@ -0,0 +1,5 @@
1
+ Manifest
2
+ README.markdown
3
+ README.txt
4
+ Rakefile
5
+ lib/hijri.rb
data/README.markdown ADDED
@@ -0,0 +1,27 @@
1
+ How to use
2
+ ==========
3
+
4
+ # currently used for one-way conversion, more features soon
5
+ gregorian = Time.now # => 2011-03-26 00:59:51 -0400
6
+ hijri = gregorian.to_hijri # => 1432-04-22 00:59:51 -04:00
7
+ # "There is a small probability of one day error."
8
+
9
+ How to install
10
+ ==============
11
+
12
+ For ruby, just install the gem and require.
13
+
14
+ $ gem install hijri_gem
15
+ $ irb
16
+ $ irb(main):001:0> require 'rubygems'
17
+ $ irb(main):002:0> require 'hijri_gem'
18
+
19
+ For Rails 3 add the following line to your bundle and install.
20
+
21
+ gem 'hijri_gem'
22
+
23
+ Todo
24
+ ----
25
+
26
+ * Tests
27
+ * Words
data/README.txt ADDED
@@ -0,0 +1,19 @@
1
+ === How to use
2
+ # currently used for one-way conversion, more features soon
3
+ gregorian = Time.now # => 2011-03-26 00:59:51 -0400
4
+ hijri = gregorian.to_hijri # => 1432-04-22 00:59:51 -04:00
5
+ # "There is a small probability of one day error."
6
+
7
+ === How to install
8
+ For ruby, just install the gem and require.
9
+ $ gem install hijri_gem
10
+ $ irb
11
+ $ irb(main):001:0> require 'rubygems'
12
+ $ irb(main):002:0> require 'hijri_gem'
13
+
14
+ For Rails 3 add the following line to your bundle and install.
15
+ gem 'hijri_gem'
16
+
17
+ === Todo
18
+ * Tests
19
+ * Words
data/Rakefile ADDED
@@ -0,0 +1,11 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+ require 'echoe'
4
+
5
+ Echoe.new('hijri_gem', '0.4.1') do |p|
6
+ p.description = "Adds Hijri support to Ruby"
7
+ p.url = "http://rubygems.org/gems/hijri_gem"
8
+ p.author = "Mohammad El-Abid"
9
+ p.email = "mohammad {dot} elabid {at} gmail"
10
+ p.ignore_pattern = []
11
+ end
data/hijri_gem.gemspec ADDED
@@ -0,0 +1,29 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ Gem::Specification.new do |s|
4
+ s.name = %q{hijri_gem}
5
+ s.version = "0.4.1"
6
+
7
+ s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
8
+ s.authors = ["Mohammad El-Abid"]
9
+ s.date = %q{2011-03-26}
10
+ s.description = %q{Adds Hijri support to Ruby}
11
+ s.email = %q{mohammad {dot} elabid {at} gmail}
12
+ s.extra_rdoc_files = ["README.markdown", "README.txt", "lib/hijri.rb"]
13
+ s.files = ["Manifest", "README.markdown", "README.txt", "Rakefile", "lib/hijri.rb", "hijri_gem.gemspec"]
14
+ s.homepage = %q{http://rubygems.org/gems/hijri_gem}
15
+ s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Hijri_gem", "--main", "README.markdown"]
16
+ s.require_paths = ["lib"]
17
+ s.rubyforge_project = %q{hijri_gem}
18
+ s.rubygems_version = %q{1.6.2}
19
+ s.summary = %q{Adds Hijri support to Ruby}
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
data/lib/hijri.rb ADDED
@@ -0,0 +1,58 @@
1
+ class Time
2
+ def to_hijri
3
+ return Hijri.convert_time(self)
4
+ end
5
+ end
6
+
7
+ class Hijri
8
+ attr_accessor :epoch, :second, :minute, :hour, :day, :month, :year, :offset
9
+
10
+ # TODO: names
11
+
12
+ h_days = ['Ahad', 'Ithnain', 'Thulatha', 'Arbiaa', 'Khamees', 'Jumaa', 'Sabt']
13
+ h_days_abbr = ['Ahd', 'Ith', 'Tha', 'Arb', 'Kha', 'Jum', 'Sab']
14
+ h_months = [nil,
15
+ 'Muharram', 'Safar', 'Rabi I', 'Rabi II',
16
+ 'Jumada I', 'Jumada II', 'Rajab', 'Shaaban',
17
+ 'Ramadan', 'Shawwal', 'Thul-Qiaadah', 'Thul-Hijja']
18
+ h_months_abbr = [nil,
19
+ 'Muh', 'Saf', 'Rb1', 'Rb2',
20
+ 'Jm1', 'Jm2', 'Raj', 'Sha',
21
+ 'Ram', 'Sha', 'Qid', 'Hij']
22
+
23
+ def to_s
24
+ off = self.offset / (60*60).to_f
25
+ str = "-04:00"
26
+ str = "#{off > 0 ? '+' : '-'}#{off.to_i.abs.to_s.rjust(2,'0')}:#{((off-off.to_i)*60*10).to_i.to_s.rjust(2,'0')}"
27
+ "#{year}-#{month.to_s.rjust(2,'0')}-#{day.to_s.rjust(2,'0')} #{hour.to_s.rjust(2,'0')}:#{minute.to_s.rjust(2,'0')}:#{second.to_s.rjust(2,'0')} #{str}"
28
+ end
29
+
30
+ def self.convert_time(time)
31
+ h = self.new
32
+
33
+ # following is converted from PHP via http://www.phpclasses.org/browse/download/1/file/2358/name/ICalendar.php
34
+ # which is converted from C++ via http://arabeyes.org
35
+ if(( time.year > 1582 ) || (( time.year == 1582 ) && ( time.month > 10 )) || (( time.year == 1582 ) && ( time.month == 10 ) && ( time.day > 14 )))
36
+ jd = (( 1461 * ( time.year + 4800 + (( time.month - 14 ) / 12 )))/ 4).floor + (( 367 * ( time.month - 2 - 12 * ((( time.month - 14 ) / 12).floor))) / 12).floor - (( 3 * ((( time.year + 4900+ (( time.month - 14) / 12).floor ) / 100).floor)) / 4).floor + time.day - 32075;
37
+ else
38
+ jd = 367 * time.year - (( 7 * ( time.year + 5001 + (( time.month - 9 ) / 7).floor)) / 4).floor + (( 275 * time.month) / 9).floor + time.day + 1729777;
39
+ end
40
+
41
+ l = jd - 1948440 + 10632;
42
+ n = (( l - 1 ) / 10631).floor;
43
+ l = l - 10631 * n + 354;
44
+ j = ((( 10985 - l ) / 5316).floor) * ((( 50 * l) / 17719).floor) + (( l / 5670 ).floor) * ( (( 43 * l ) / 15238 ).floor);
45
+ l = l - ( (( 30 - j ) / 15 ).floor) * ( (( 17719 * j ) / 50).floor) - ( ( j / 16 ).floor) * ( (( 15238 * j ) / 43 ).floor) + 29;
46
+
47
+ h.month = (( 24 * l ) / 709 ).floor;
48
+ h.day = l - (( 709 * h.month ) / 24).floor;
49
+ h.year = 30 * n + j - 30;
50
+
51
+ h.hour = time.hour
52
+ h.minute = time.min
53
+ h.second = time.sec
54
+ h.offset = time.utc_offset
55
+
56
+ return h
57
+ end
58
+ end
metadata ADDED
@@ -0,0 +1,61 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: hijri_gem
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.4.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Mohammad El-Abid
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2011-03-26 00:00:00.000000000 -04:00
13
+ default_executable:
14
+ dependencies: []
15
+ description: Adds Hijri support to Ruby
16
+ email: mohammad {dot} elabid {at} gmail
17
+ executables: []
18
+ extensions: []
19
+ extra_rdoc_files:
20
+ - README.markdown
21
+ - README.txt
22
+ - lib/hijri.rb
23
+ files:
24
+ - Manifest
25
+ - README.markdown
26
+ - README.txt
27
+ - Rakefile
28
+ - lib/hijri.rb
29
+ - hijri_gem.gemspec
30
+ has_rdoc: true
31
+ homepage: http://rubygems.org/gems/hijri_gem
32
+ licenses: []
33
+ post_install_message:
34
+ rdoc_options:
35
+ - --line-numbers
36
+ - --inline-source
37
+ - --title
38
+ - Hijri_gem
39
+ - --main
40
+ - README.markdown
41
+ require_paths:
42
+ - lib
43
+ required_ruby_version: !ruby/object:Gem::Requirement
44
+ none: false
45
+ requirements:
46
+ - - ! '>='
47
+ - !ruby/object:Gem::Version
48
+ version: '0'
49
+ required_rubygems_version: !ruby/object:Gem::Requirement
50
+ none: false
51
+ requirements:
52
+ - - ! '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '1.2'
55
+ requirements: []
56
+ rubyforge_project: hijri_gem
57
+ rubygems_version: 1.6.2
58
+ signing_key:
59
+ specification_version: 3
60
+ summary: Adds Hijri support to Ruby
61
+ test_files: []