hijri 0.2.0 → 0.2.5
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.
- checksums.yaml +4 -4
- data/.travis.yml +5 -2
- data/CHANGELOG +4 -0
- data/README.md +11 -7
- data/hijri.gemspec +1 -1
- data/lib/hijri/date.rb +26 -7
- data/lib/{format.rb → hijri/format.rb} +10 -10
- data/lib/hijri/gregorian.rb +5 -5
- data/lib/hijri/version.rb +1 -1
- data/test/test_hijri.rb +6 -1
- metadata +4 -4
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 8a57a98c55f59a921c16661f2dde825a5600d32d
|
|
4
|
+
data.tar.gz: d1f368e87d525735c9e01afc3a4841e3ce2d1052
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 6d9061ec1e355f146a8be9b1ca1b58a2fe6c111078929fcb88b5aecc7d9edbf9dcaf5453ba120b899c5bdab8107c8b9c516e8adceea22ce40980cf974bb9ef35
|
|
7
|
+
data.tar.gz: 83e0d0511d673e93479a75520d9401f05aa5a6d6e3a7fb9911e508354e31aa8edf6b33e25438eeb59f31e9ea311bfb38e0fa55172e8480ab0824beaf8ea8401d
|
data/.travis.yml
CHANGED
data/CHANGELOG
CHANGED
data/README.md
CHANGED
|
@@ -27,12 +27,12 @@ Or install it yourself as:
|
|
|
27
27
|
$ gem install hijri
|
|
28
28
|
|
|
29
29
|
###hijri tested and worked in:
|
|
30
|
-
- Ruby MRI:
|
|
31
|
-
-
|
|
32
|
-
-
|
|
33
|
-
-
|
|
34
|
-
-
|
|
35
|
-
-
|
|
30
|
+
- Ruby MRI:
|
|
31
|
+
- 1.8.7
|
|
32
|
+
- 1.9.2
|
|
33
|
+
- 1.9.3
|
|
34
|
+
- 2.0.0
|
|
35
|
+
- 2.1
|
|
36
36
|
- JRuby 1.7.16.1
|
|
37
37
|
- jruby-18mode
|
|
38
38
|
- jruby-19mode
|
|
@@ -45,12 +45,16 @@ require 'hijri'
|
|
|
45
45
|
|
|
46
46
|
# you can create hijri date from stdlib Date class.
|
|
47
47
|
h = Date.today.to_hijri # => #<Hijri::Date:0x007f875e8c84e8 @year=1436, @month=2, @day=16>
|
|
48
|
+
|
|
48
49
|
# or you can initialize new one.
|
|
49
50
|
hijri = Hijri::Date.new 1430, 1, 3 # => #<Hijri::Date:0x007f875e8dbb38 @year=1430, @month=1, @day=3>
|
|
51
|
+
|
|
50
52
|
# or you get today hijri date directly.
|
|
51
53
|
toady = Hijri::Date.today # => #<Hijri::Date:0x007f875e8d8410 @year=1436, @month=2, @day=16>
|
|
54
|
+
|
|
52
55
|
# and you can convert hijri date to greogian date.
|
|
53
56
|
hijri.to_greo # => #<Date: 2009-01-01 ((2454833j,0s,0n),+0s,2299161j)>
|
|
57
|
+
|
|
54
58
|
# and there is DateTime too
|
|
55
59
|
date_and_time = Hijri::DateTime.now # => #<Hijri::DateTime:0x007f875e8eac00 @year=1436, @month=2, @day=16, @hour=14, @minute=14, @second=39, @zone="+03:00">
|
|
56
60
|
```
|
|
@@ -62,8 +66,8 @@ date_and_time = Hijri::DateTime.now # => #<Hijri::DateTime:0x007f875e8eac00 @yea
|
|
|
62
66
|
- [x] Accept test error with one day range.
|
|
63
67
|
- [x] Add Hijri::DateTime.now to create Hijri::DateTime object.
|
|
64
68
|
- [x] Add Hijri::Date.today to create Hijri::Date object with today date.
|
|
69
|
+
- [x] Add Comparable for Hijri::Date.
|
|
65
70
|
- [ ] Implement strftime method.
|
|
66
|
-
- [ ] Add Comparable for Hijri::Date.
|
|
67
71
|
|
|
68
72
|
|
|
69
73
|
## Contributing
|
data/hijri.gemspec
CHANGED
|
@@ -10,7 +10,7 @@ Gem::Specification.new do |gem|
|
|
|
10
10
|
gem.license = "MIT"
|
|
11
11
|
gem.authors = ["Abdulaziz AlShetwi"]
|
|
12
12
|
gem.email = "ecleeld@gmail.com"
|
|
13
|
-
gem.homepage = "https://
|
|
13
|
+
gem.homepage = "https://github.com/ecleel/hijri"
|
|
14
14
|
|
|
15
15
|
gem.files = `git ls-files`.split($/)
|
|
16
16
|
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
data/lib/hijri/date.rb
CHANGED
|
@@ -1,10 +1,19 @@
|
|
|
1
1
|
module Hijri
|
|
2
2
|
class Date
|
|
3
3
|
|
|
4
|
+
include Comparable
|
|
5
|
+
|
|
4
6
|
attr_accessor :day, :month, :year
|
|
5
7
|
MONTHNAMES_EN = %w(Muharram Safar Rabia-Awwal Rabia-Thani Jumaada-Awal Jumaada-Thani Rajab Sha'ban Ramadan Shawwal Dhul-Qi'dah Dhul-Hijjah)
|
|
6
8
|
DAYNAMES = %w(as-Sabt al-Ahad al-Ithnayn ath-Thalaathaa al-Arba'aa' al-Khamis al-Jumu'ah)
|
|
7
9
|
|
|
10
|
+
class << self
|
|
11
|
+
def today
|
|
12
|
+
date = ::Date.today
|
|
13
|
+
date.to_hijri
|
|
14
|
+
end
|
|
15
|
+
end
|
|
16
|
+
|
|
8
17
|
def initialize(year=1, month=1, day=1)
|
|
9
18
|
@year, @month, @day = year, month, day
|
|
10
19
|
end
|
|
@@ -22,12 +31,24 @@ module Hijri
|
|
|
22
31
|
"#{@year}-#{sprintf('%02d', @month)}-#{sprintf('%02d', @day)}"
|
|
23
32
|
end
|
|
24
33
|
|
|
34
|
+
def <=>(date)
|
|
35
|
+
# Make sure the date is a Hijri::Date instance
|
|
36
|
+
date = date.to_hijri
|
|
37
|
+
if self.to_s == date.to_s
|
|
38
|
+
return 0
|
|
39
|
+
elsif @year > date.year || (@year == date.year && @month > date.month) || (@year == date.year && @month == date.month && @day > date.day)
|
|
40
|
+
return 1
|
|
41
|
+
else
|
|
42
|
+
return -1
|
|
43
|
+
end
|
|
44
|
+
end
|
|
45
|
+
|
|
25
46
|
def to_abs
|
|
26
47
|
month_days = 29 * (month - 1) # days on this year
|
|
27
48
|
nonleap_year_days = 354 * (year - 1)
|
|
28
49
|
leap_year_days = (3 + (11 * year)) / 30.0
|
|
29
50
|
this_year = (month / 2.0).to_i
|
|
30
|
-
|
|
51
|
+
|
|
31
52
|
return (day + month_days + this_year + nonleap_year_days + leap_year_days + Hijri::ISLAMIC_EPOCH).to_i
|
|
32
53
|
end
|
|
33
54
|
|
|
@@ -35,12 +56,10 @@ module Hijri
|
|
|
35
56
|
::Date.new *Converter.hijri_to_greo(self)
|
|
36
57
|
end
|
|
37
58
|
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
date.to_hijri
|
|
42
|
-
end
|
|
59
|
+
# Just to have a consistent Interface.
|
|
60
|
+
def to_hijri
|
|
61
|
+
self
|
|
43
62
|
end
|
|
44
63
|
|
|
45
64
|
end
|
|
46
|
-
end
|
|
65
|
+
end
|
|
@@ -112,22 +112,22 @@ class Date
|
|
|
112
112
|
class Bag # :nodoc:
|
|
113
113
|
|
|
114
114
|
def initialize
|
|
115
|
-
|
|
115
|
+
@elem = {}
|
|
116
116
|
end
|
|
117
117
|
|
|
118
118
|
def method_missing(t, *args, &block)
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
119
|
+
t = t.to_s
|
|
120
|
+
set = t.chomp!('=')
|
|
121
|
+
t = t.intern
|
|
122
|
+
if set
|
|
123
|
+
@elem[t] = args[0]
|
|
124
|
+
else
|
|
125
|
+
@elem[t]
|
|
126
|
+
end
|
|
127
127
|
end
|
|
128
128
|
|
|
129
129
|
def to_hash
|
|
130
|
-
|
|
130
|
+
@elem.reject{|k, v| /\A_/ =~ k.to_s || v.nil?}
|
|
131
131
|
end
|
|
132
132
|
|
|
133
133
|
end
|
data/lib/hijri/gregorian.rb
CHANGED
|
@@ -2,7 +2,7 @@ class Date
|
|
|
2
2
|
def to_hijri
|
|
3
3
|
Hijri::Date.new *Hijri::Converter.greo_to_hijri(self)
|
|
4
4
|
end
|
|
5
|
-
|
|
5
|
+
|
|
6
6
|
def last_day_of_gregorian_month(month)
|
|
7
7
|
# Compute the last date of the month for the Gregorian calendar.
|
|
8
8
|
if month == 2
|
|
@@ -10,7 +10,7 @@ class Date
|
|
|
10
10
|
end
|
|
11
11
|
return [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31][month - 1]
|
|
12
12
|
end
|
|
13
|
-
|
|
13
|
+
|
|
14
14
|
def to_abs
|
|
15
15
|
@d = self.day
|
|
16
16
|
@m = self.month - 1
|
|
@@ -25,10 +25,10 @@ class DateTime
|
|
|
25
25
|
def to_hijri
|
|
26
26
|
Hijri::DateTime.new *Hijri::Converter.greo_to_hijri(self)
|
|
27
27
|
end
|
|
28
|
-
|
|
28
|
+
|
|
29
29
|
if RUBY_VERSION < '1.8.8'
|
|
30
30
|
alias :minute :min
|
|
31
31
|
alias :second :sec
|
|
32
32
|
end
|
|
33
|
-
|
|
34
|
-
end
|
|
33
|
+
|
|
34
|
+
end
|
data/lib/hijri/version.rb
CHANGED
data/test/test_hijri.rb
CHANGED
|
@@ -53,5 +53,10 @@ class TestHijri < MiniTest::Unit::TestCase
|
|
|
53
53
|
assert_equal g_datetime.zone, exact_date.zone
|
|
54
54
|
end
|
|
55
55
|
|
|
56
|
-
|
|
56
|
+
def test_comparing_two_hijri_date
|
|
57
|
+
date1 = Hijri::Date.new 1435, 1, 1
|
|
58
|
+
date2 = Hijri::Date.new 1435, 1, 1
|
|
59
|
+
|
|
60
|
+
assert_equal date1, date2
|
|
61
|
+
end
|
|
57
62
|
end
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: hijri
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.2.
|
|
4
|
+
version: 0.2.5
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Abdulaziz AlShetwi
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2014-12-
|
|
11
|
+
date: 2014-12-11 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: bundler
|
|
@@ -68,17 +68,17 @@ files:
|
|
|
68
68
|
- README.md
|
|
69
69
|
- Rakefile
|
|
70
70
|
- hijri.gemspec
|
|
71
|
-
- lib/format.rb
|
|
72
71
|
- lib/hijri.rb
|
|
73
72
|
- lib/hijri/absolute.rb
|
|
74
73
|
- lib/hijri/converter.rb
|
|
75
74
|
- lib/hijri/date.rb
|
|
76
75
|
- lib/hijri/datetime.rb
|
|
76
|
+
- lib/hijri/format.rb
|
|
77
77
|
- lib/hijri/gregorian.rb
|
|
78
78
|
- lib/hijri/version.rb
|
|
79
79
|
- test/helper.rb
|
|
80
80
|
- test/test_hijri.rb
|
|
81
|
-
homepage: https://
|
|
81
|
+
homepage: https://github.com/ecleel/hijri
|
|
82
82
|
licenses:
|
|
83
83
|
- MIT
|
|
84
84
|
metadata: {}
|