hijri 0.2.5 → 0.4.0

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.
@@ -1,3 +1,3 @@
1
1
  module Hijri
2
- VERSION = "0.2.5"
2
+ VERSION = "0.4.0"
3
3
  end
@@ -16,7 +16,7 @@ rescue Bundler::BundlerError => e
16
16
  exit e.status_code
17
17
  end
18
18
 
19
- if RUBY_VERSION < '1.8.8'
19
+ if %w(1.8.7 2.2.0).include? RUBY_VERSION
20
20
  require 'minitest/autorun'
21
21
  end
22
22
 
@@ -9,7 +9,7 @@ class TestHijri < MiniTest::Unit::TestCase
9
9
  assert(!version.empty?, 'should have a VERSION constant')
10
10
  end
11
11
 
12
- def test_hijri_to_string
12
+ def test_hijri_date_to_string
13
13
  date = Hijri::Date.new 1433, 9, 18
14
14
  assert_equal "1433-09-18", date.to_s
15
15
  end
@@ -59,4 +59,82 @@ class TestHijri < MiniTest::Unit::TestCase
59
59
 
60
60
  assert_equal date1, date2
61
61
  end
62
+
63
+ def test_comparing_hijri_date_and_greogrian_date
64
+ date1 = Hijri::Date.new(1435, 1, 1)
65
+ date2 = Hijri::Date.new(1435, 1, 1).to_greo
66
+
67
+ assert_equal date1, date2
68
+ end
69
+
70
+ def test_comparing_two_hijri_datetime
71
+ date1 = Hijri::DateTime.new(1435, 1, 1, 1, 1, 1, 1)
72
+ date2 = Hijri::DateTime.new(1435, 1, 1, 1, 1, 1, 1)
73
+
74
+ assert_equal date1, date2
75
+ end
76
+
77
+ def test_hijri_datetime_to_string
78
+ datetime = Hijri::DateTime.new 1433, 9, 18, 1, 1, 1, '+03:00'
79
+ assert_equal "1433-09-18T01:01:01+03:00", datetime.to_s
80
+ end
81
+
82
+ def test_hijri_datetime_to_string_add_plus_for_zone_equal_0000
83
+ datetime = Hijri::DateTime.new 1433, 9, 18, 1, 1, 1, '00:00'
84
+ assert_equal "1433-09-18T01:01:01+00:00", datetime.to_s
85
+ end
86
+
87
+ def test_hijri_date_strftime_shows_hijri_month_names
88
+ date = Hijri::Date.new 1436, 2, 21
89
+ assert_equal "Safar", date.strftime("%B")
90
+ end
91
+
92
+ def test_hijri_date_strftime_with_no_input
93
+ date = Hijri::Date.new 1433, 9, 18
94
+ assert_equal "1433-09-18", date.strftime
95
+ end
96
+
97
+ def test_hijri_datetime_strftime_with_no_input
98
+ datetime = Hijri::DateTime.new 1433, 9, 18, 1, 1, 1, '+03:00'
99
+ #"1433-09-18T01:01:01+03:00"
100
+ assert_equal datetime.to_s, datetime.strftime
101
+ end
102
+
103
+ def test_hijri_full_arabic_month
104
+ date = Hijri::Date.new 1436, 3, 1
105
+ assert_equal "Rabia-Awwal", date.strftime('%B')
106
+ end
107
+
108
+ def test_hijri_short_arabic_month_name
109
+ date = Hijri::Date.new 1436, 3, 1
110
+ assert_equal "Rabia I", date.strftime('%b')
111
+ end
112
+
113
+ def test_hijri_full_arabic_day_name
114
+ (15..21).each do |day|
115
+ date = Hijri::Date.new 1436, 1, day
116
+ assert_equal Hijri::Date::DAYNAMES[(day-1)%7], date.strftime('%A')
117
+ end
118
+ end
119
+
120
+ def test_hijri_short_arabic_day_name
121
+ (1..7).each do |day|
122
+ date = Hijri::Date.new 1436, 3, day
123
+ assert_equal Hijri::Date::ABBR_DAYNAMES[(day+2)%7], date.strftime('%a')
124
+ end
125
+ end
126
+
127
+ def test_hijri_day_of_the_year
128
+ date = Hijri::Date.new 1436, 3, 20
129
+ assert_equal "079", date.strftime('%j')
130
+ end
131
+
132
+ def test_hijri_week_number_of_the_year
133
+ date = Hijri::Date.new 1436, 3, 20
134
+ assert_equal("11", date.strftime('%U'))
135
+ assert_equal("11", date.strftime('%W'))
136
+ end
137
+
138
+ # TODO add Hijri::Date.change and test it.
139
+
62
140
  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.5
4
+ version: 0.4.0
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 00:00:00.000000000 Z
11
+ date: 2015-01-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -69,7 +69,6 @@ files:
69
69
  - Rakefile
70
70
  - hijri.gemspec
71
71
  - lib/hijri.rb
72
- - lib/hijri/absolute.rb
73
72
  - lib/hijri/converter.rb
74
73
  - lib/hijri/date.rb
75
74
  - lib/hijri/datetime.rb
@@ -98,7 +97,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
98
97
  version: '0'
99
98
  requirements: []
100
99
  rubyforge_project:
101
- rubygems_version: 2.2.2
100
+ rubygems_version: 2.4.5
102
101
  signing_key:
103
102
  specification_version: 4
104
103
  summary: Hijri Date Library for Ruby
@@ -1,72 +0,0 @@
1
- module Hijri
2
- class Absolute
3
- attr_accessor :absolute
4
-
5
- def initialize abs
6
- self.absolute = abs
7
- end
8
-
9
- # def greo_to_hijri(date)
10
- # hijri = absolute2islamic(gregorian2absolute(date.day, date.month, date.year))
11
- # Hijri.new hijri[0], hijri[1], hijri[2]
12
- # end
13
- #
14
- # def hijri_to_greo(date)
15
- # greo = absolute2gregorian(islamic2absolute(date.day,date.month,date.year))
16
- # Date.new greo[0], greo[1], greo[2]
17
- # end
18
-
19
- def gregorian2absolute(day, month, year)
20
- # # Computes the absolute date from the Gregorian date.
21
- @d = day
22
- @m = month - 1
23
- @m.downto(1) do |m|
24
- @d += last_day_of_gregorian_month(@m, year)
25
- end
26
- return (@d + 365 * (year - 1) + (year -1) / 4.0 - (year - 1) / 100.0 + (year - 1) / 400.0).to_i
27
- end
28
-
29
- def to_greo
30
- # Computes the Gregorian date from the absolute date.
31
- # Search forward year by year from approximate year
32
- puts self.absolute
33
- year = (self.absolute / 366.0 + 0.5).to_i
34
- while (self.absolute >= gregorian2absolute(1, 1, year + 1))
35
- year += 1
36
- end
37
- # Search forward month by month from January
38
- month = 1
39
- while (self.absolute > gregorian2absolute(last_day_of_gregorian_month(month, year), month, year))
40
- month += 1
41
- end
42
- day = self.absolute - gregorian2absolute(1, month, year) + 1
43
- return [year, month, day]
44
- end
45
-
46
- # TODO
47
- def to_hijri
48
- # Computes the Islamic date from the absolute date.
49
- # puts "abs #{abs} and islamicEpoch #{IslamicEpoch}"
50
- if (absolute <= Hijri::ISLAMIC_EPOCH)
51
- # Date is pre-Islamic
52
- month = 0
53
- day = 0
54
- year = 0
55
- elsif
56
- # Search forward year by year from approximate year
57
- year = ((absolute - Hijri::ISLAMIC_EPOCH) / 355.0).to_i
58
- while (absolute >= islamic2absolute(1,1,year+1))
59
- year += 1
60
- end
61
- # Search forward month by month from Muharram
62
- month = 1
63
- while (absolute > islamic2absolute(last_day_of_islamic_month(month,year), month, year))
64
- month += 1
65
- end
66
- day = absolute - islamic2absolute(1, month, year) + 1
67
- end
68
- return [year, month, day]
69
- end
70
-
71
- end
72
- end