hijri2greg_date 0.0.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,15 @@
1
+ ---
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ MGJmNzJjNGM1YWMxMDEyNmY3YzM1NDY5ODI2MTgxNGRkMmQ4OTZiZQ==
5
+ data.tar.gz: !binary |-
6
+ NjEzZDExNzg4ZDc2M2FjMGU1ODgzNWExYWU0Nzg1MTBhYmRiZjdlYQ==
7
+ SHA512:
8
+ metadata.gz: !binary |-
9
+ OTI4MzYyYjk4MDkzM2ZjZmQzOGFkNzMyOWVjMzA5ZTg5NjQzOGVjOGM5MDgx
10
+ MmUzNDYwMjRjNTM0ZWRlODdiOTJkYTlkZjI4M2IyNzZmMzlkMDMxZTc4MzA2
11
+ MzZkZGI5MTA5OTY5N2EwMTkwYTQzMjg3MGNmNTk0MDJmZjhkZjA=
12
+ data.tar.gz: !binary |-
13
+ NTkxYTQyNjJkMjBmNjAxOWZiOTE0Y2VhZmY3ZWViYWI1Mzk4YzUyYjI0YWVh
14
+ NDEzMjhmMjFkODYxNjY1ZDQwYjQ4YWVmNDg1YjZlODA2ZjE3ZTkwYTZkM2U0
15
+ OWUzMmQwMjhkNTM5OGMzMGIyY2Y2YWEzZWVjODg5OWM2NGFhZDM=
@@ -0,0 +1,22 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+ *.bundle
19
+ *.so
20
+ *.o
21
+ *.a
22
+ mkmf.log
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in hijri2greg_date.gemspec
4
+ gemspec
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Thaha Muhammed
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,77 @@
1
+ # Hijri2gregDate
2
+
3
+ This is a converter that can convert gregorian dates to hijri dates and similiarly hijri dates to gregorian.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'hijri2greg_date'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install hijri2greg_date
18
+
19
+ If using with ruby instead of rails then:
20
+
21
+ $ gem install hijri2greg_date
22
+ require 'hijri2greg_date'
23
+
24
+ ## Usage
25
+
26
+ There are two methods you can use for conversion
27
+
28
+ 1. to_hijri
29
+
30
+ This is for gregorian to hijri conversion.You can either use a Date object or Time object with this method as shown in following Examples.
31
+
32
+ For example
33
+
34
+ ``` abc=Time.now
35
+ => 2014-09-24 08:48:50 +0530
36
+
37
+ abc.to_hijri
38
+ => 1435-11-29
39
+
40
+ also
41
+
42
+
43
+ abc=Date.today
44
+ => #<Date: 2014-09-24 ((2456925j,0s,0n),+0s,2299161j)>
45
+ abc.to_hijri
46
+ => 1435-11-29
47
+
48
+ ```
49
+
50
+ 2. to_greg
51
+
52
+ This is for hijri to gregorian conversion.You can either use a Date object or Time object with this method as shown in following Examples.
53
+
54
+ For example
55
+ ```
56
+ abc=Time.parse("1435-11-29 08:48:50 +0530")
57
+ => 1435-11-29 09:12:10 +0553```
58
+
59
+ abc.to_greg
60
+ => "2014-9-24"
61
+
62
+ also
63
+
64
+ abc=Date.parse("1435-11-29")
65
+ => #<Date: 1435-11-29 ((2245524j,0s,0n),+0s,2299161j)>
66
+
67
+ abc.to_greg
68
+ => 1435-11-29
69
+ ```
70
+
71
+ ## Contributing
72
+
73
+ 1. Fork it ( https://github.com/stormvirux/hijri2greg_date/fork )
74
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
75
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
76
+ 4. Push to the branch (`git push origin my-new-feature`)
77
+ 5. Create a new Pull Request
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+
@@ -0,0 +1,24 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'hijri2greg_date/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "hijri2greg_date"
8
+ spec.version = Hijri2gregDate::VERSION
9
+ spec.authors = ["Thaha Muhammed"]
10
+ spec.email = ["mthaha1989@gmail.com"]
11
+ spec.summary = %q{Converter:Gregorian to Hijri Date and vice versa}
12
+ spec.description = %q{This is a converter that can convert gregorian
13
+ dates to hijri dates and similiarly hijri dates to gregorian}
14
+ spec.homepage = "https://github.com/stormvirux/hijri2greg_date"
15
+ spec.license = "MIT"
16
+
17
+ spec.files = `git ls-files -z`.split("\x0")
18
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
19
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
20
+ spec.require_paths = ["lib"]
21
+
22
+ spec.add_development_dependency "bundler", "~> 1.6"
23
+ spec.add_development_dependency "rake"
24
+ end
@@ -0,0 +1,100 @@
1
+ #require "hijri2greg_date/version"
2
+ require 'time'
3
+ require 'date'
4
+
5
+ class Time
6
+ def to_hijri
7
+ return Hijri2gregDate.Gregorian2Hijri(self.to_s.split(" ")[0].split("-"))
8
+ end
9
+ def to_greg
10
+ return Hijri2gregDate.Hijri2Gregorian(self.to_s.split(" ")[0].split("-"))
11
+ end
12
+ end
13
+
14
+ class Date
15
+ def to_hijri
16
+ return Hijri2gregDate.Gregorian2Hijri(self.to_s.split("-"))
17
+ end
18
+ def to_greg
19
+ return Hijri2gregDate.Hijri2Gregorian(self.to_s.split("-"))
20
+ end
21
+ end
22
+
23
+
24
+ class Hijri2gregDate
25
+
26
+ def self.intPart(floatNum)
27
+ if floatNum < -0.0000001
28
+ return (floatNum - 0.0000001).ceil
29
+ end
30
+ return (floatNum + 0.0000001).floor
31
+ end
32
+
33
+ def self.Gregorian2Hijri(time)
34
+ yr,mth,day=time[0].to_i,time[1].to_i,time[2].to_i
35
+ if ((yr > 1582) or ((yr == 1582) and (mth > 10)) or
36
+ ((yr == 1582) and (mth == 10) and (day > 14)))
37
+ jd1 = intPart((1461 * (yr + 4800 +
38
+ intPart((mth - 14) / 12.0))) / 4)
39
+ jd2 = intPart((367 * (mth - 2 - 12 *
40
+ (intPart((mth - 14) / 12.0)))) / 12)
41
+ jd3 = intPart((3 * (intPart((yr + 4900 +
42
+ intPart((mth - 14) / 12.0)) / 100))) / 4)
43
+ jd = jd1 + jd2 - jd3 + day - 32075
44
+ else
45
+ jd1 = intPart((7 * (yr + 5001 +
46
+ intPart((mth - 9) / 7.0))) / 4)
47
+ jd2 = intPart((275 * mth) / 9.0)
48
+ jd = 367 * yr - jd1 + jd2 + day + 1729777
49
+ end
50
+
51
+ l = jd - 1948440 + 10632
52
+ n = intPart((l - 1) /10631.0)
53
+ l = l - 10631 * n + 354
54
+ j1 = (intPart((10985 - l) / 5316.0)) * (intPart((50 * l) / 17719.0))
55
+ j2 = (intPart(l / 5670.0)) * (intPart((43 * l) / 15238.0))
56
+ j = j1 + j2
57
+ l1 = (intPart((30 - j) / 15.0)) * (intPart((17719 * j) / 50.0))
58
+ l2 = (intPart(j / 16.0)) * (intPart((15238 * j) / 43.0))
59
+ l = l - l1 - l2 + 29
60
+ m = intPart((24 * l) / 709.0)
61
+ d = l - intPart((709 * m) / 24.0)
62
+ y = 30 * n + j - 30
63
+
64
+ return [y, m, d].join("-")
65
+ end
66
+
67
+ def self.Hijri2Gregorian(time)
68
+ yr,mth,day=time[0].to_i,time[1].to_i,time[2].to_i
69
+ jd1 = intPart((11 * yr + 3) / 30.0)
70
+ jd2 = intPart((mth - 1) / 2.0)
71
+ jd = jd1 + 354 * yr + 30 * mth - jd2 + day + 1948440 - 385
72
+
73
+ if jd > 2299160
74
+ l = jd + 68569
75
+ n = intPart((4 * l) / 146097.0)
76
+ l = l - intPart((146097 * n + 3) / 4.0)
77
+ i = intPart((4000 * (l + 1)) / 1461001.0)
78
+ l = l - intPart((1461 * i) / 4.0) + 31
79
+ j = intPart((80 * l) / 2447.0)
80
+ d = l - intPart((2447 * j) / 80.0)
81
+ l = intPart(j / 11.0)
82
+ m = j + 2 - 12 * l
83
+ y = 100 * (n - 49) + i + l
84
+ else
85
+ j = jd + 1402
86
+ k = intPart((j - 1) / 1461.0)
87
+ l = j - 1461 * k
88
+ n = intPart((l - 1) / 365.0) - intPart(l / 1461.0)
89
+ i = l - 365 * n + 30
90
+ j = intPart((80 * i) / 2447.0)
91
+ d = i - intPart((2447 * j) / 80.0)
92
+ i = intPart(j / 11.0)
93
+ m = j + 2 - 12 * i
94
+ y = 4 * k + n + i - 4716
95
+ end
96
+ return [y, m, d].join("-")
97
+ end
98
+ end
99
+
100
+
@@ -0,0 +1,3 @@
1
+ module Hijri2gregDate
2
+ VERSION = "0.0.4"
3
+ end
metadata ADDED
@@ -0,0 +1,81 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: hijri2greg_date
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.4
5
+ platform: ruby
6
+ authors:
7
+ - Thaha Muhammed
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-09-24 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: '1.6'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '1.6'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ! '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ! '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ description: ! "This is a converter that can convert gregorian\n dates to hijri
42
+ dates and similiarly hijri dates to gregorian"
43
+ email:
44
+ - mthaha1989@gmail.com
45
+ executables: []
46
+ extensions: []
47
+ extra_rdoc_files: []
48
+ files:
49
+ - .gitignore
50
+ - Gemfile
51
+ - LICENSE.txt
52
+ - README.md
53
+ - Rakefile
54
+ - hijri2greg_date.gemspec
55
+ - lib/hijri2greg_date.rb
56
+ - lib/hijri2greg_date/version.rb
57
+ homepage: https://github.com/stormvirux/hijri2greg_date
58
+ licenses:
59
+ - MIT
60
+ metadata: {}
61
+ post_install_message:
62
+ rdoc_options: []
63
+ require_paths:
64
+ - lib
65
+ required_ruby_version: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - ! '>='
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ required_rubygems_version: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - ! '>='
73
+ - !ruby/object:Gem::Version
74
+ version: '0'
75
+ requirements: []
76
+ rubyforge_project:
77
+ rubygems_version: 2.2.2
78
+ signing_key:
79
+ specification_version: 4
80
+ summary: Converter:Gregorian to Hijri Date and vice versa
81
+ test_files: []