jalalidate 0.3.1 → 0.3.2
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.
- data/Gemfile.lock +12 -12
- data/README.md +5 -2
- data/bin/jcal +0 -0
- data/jalalidate.gemspec +2 -2
- data/lib/jalalidate.rb +8 -6
- data/lib/jalalidate/version.rb +1 -1
- data/spec/jalalidate_spec.rb +29 -29
- data/spec/spec_helper.rb +0 -2
- metadata +47 -62
data/Gemfile.lock
CHANGED
@@ -1,25 +1,25 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
jalalidate (0.2
|
4
|
+
jalalidate (0.3.2)
|
5
5
|
|
6
6
|
GEM
|
7
7
|
remote: http://rubygems.org/
|
8
8
|
specs:
|
9
|
-
diff-lcs (1.
|
10
|
-
rspec (2.
|
11
|
-
rspec-core (~> 2.
|
12
|
-
rspec-expectations (~> 2.
|
13
|
-
rspec-mocks (~> 2.
|
14
|
-
rspec-core (2.1
|
15
|
-
rspec-expectations (2.
|
16
|
-
diff-lcs (
|
17
|
-
rspec-mocks (2.1
|
9
|
+
diff-lcs (1.2.2)
|
10
|
+
rspec (2.13.0)
|
11
|
+
rspec-core (~> 2.13.0)
|
12
|
+
rspec-expectations (~> 2.13.0)
|
13
|
+
rspec-mocks (~> 2.13.0)
|
14
|
+
rspec-core (2.13.1)
|
15
|
+
rspec-expectations (2.13.0)
|
16
|
+
diff-lcs (>= 1.1.3, < 2.0)
|
17
|
+
rspec-mocks (2.13.1)
|
18
18
|
|
19
19
|
PLATFORMS
|
20
20
|
ruby
|
21
21
|
|
22
22
|
DEPENDENCIES
|
23
|
-
bundler (~> 1.
|
23
|
+
bundler (~> 1.3.0)
|
24
24
|
jalalidate!
|
25
|
-
rspec (~> 2.
|
25
|
+
rspec (~> 2.13.0)
|
data/README.md
CHANGED
@@ -5,6 +5,9 @@
|
|
5
5
|
|
6
6
|
## History
|
7
7
|
|
8
|
+
#### 0.3.2 - 8.APR.2013
|
9
|
+
* Making JalaliDate class thread safe, courtesy of [Jahangir Zinedine](https://github.com/jzinedine)
|
10
|
+
|
8
11
|
#### 0.3.1 - 26.APR.2011
|
9
12
|
* Added ruby 1.9 compatibility, courtesy of [Reza](https://github.com/ryco)
|
10
13
|
|
@@ -21,11 +24,11 @@
|
|
21
24
|
* Updated gemspec file for rubygems.org
|
22
25
|
* Updated some documentations
|
23
26
|
|
24
|
-
#### 0.02 -
|
27
|
+
#### 0.02 - 8.AUG.2008
|
25
28
|
* Added jalali to geregorian date convertor.
|
26
29
|
* Added JalaliDate class and ported Date class method to JalaliDate
|
27
30
|
|
28
|
-
#### 0.01 -
|
31
|
+
#### 0.01 - 7.AUG.2008
|
29
32
|
* Planning the project
|
30
33
|
|
31
34
|
|
data/bin/jcal
CHANGED
File without changes
|
data/jalalidate.gemspec
CHANGED
@@ -19,6 +19,6 @@ Gem::Specification.new do |s|
|
|
19
19
|
s.require_paths = ["lib"]
|
20
20
|
s.extra_rdoc_files = [ "LICENSE", "README.md"]
|
21
21
|
s.rdoc_options = ["--charset=UTF-8"]
|
22
|
-
s.add_development_dependency(%q<rspec>, ["~> 2.
|
23
|
-
s.add_development_dependency(%q<bundler>, ["~> 1.
|
22
|
+
s.add_development_dependency(%q<rspec>, ["~> 2.13.0"])
|
23
|
+
s.add_development_dependency(%q<bundler>, ["~> 1.3.0"])
|
24
24
|
end
|
data/lib/jalalidate.rb
CHANGED
@@ -276,6 +276,7 @@ class JalaliDate
|
|
276
276
|
private #-------------------------------------------------------------------------
|
277
277
|
|
278
278
|
def gregorian_to_jalali(year, month, day) # :nodoc:
|
279
|
+
jj=0
|
279
280
|
gy = year - 1600
|
280
281
|
gm = month - 1
|
281
282
|
gd = day - 1
|
@@ -298,19 +299,20 @@ class JalaliDate
|
|
298
299
|
11.times do |i|
|
299
300
|
if j_day_no >= JDaysInMonth[i]
|
300
301
|
j_day_no -= JDaysInMonth[i]
|
301
|
-
|
302
|
+
jj = i + 1
|
302
303
|
else
|
303
|
-
|
304
|
+
jj = i
|
304
305
|
break
|
305
306
|
end
|
306
307
|
end
|
307
|
-
jm =
|
308
|
+
jm = jj + 1
|
308
309
|
jd = j_day_no + 1
|
309
310
|
|
310
311
|
[jy, jm, jd]
|
311
312
|
end
|
312
313
|
|
313
314
|
def jalali_to_gregorian(year,month,day) # :nodoc:
|
315
|
+
gg=0
|
314
316
|
jy = year - 979
|
315
317
|
jm = month - 1
|
316
318
|
jd = day - 1
|
@@ -344,13 +346,13 @@ class JalaliDate
|
|
344
346
|
leap_day = (i==1 && leap) ? 1 : 0
|
345
347
|
if g_day_no >= (GDaysInMonth[i] + leap_day )
|
346
348
|
g_day_no -= (GDaysInMonth[i] + leap_day )
|
347
|
-
|
349
|
+
gg = i + 1
|
348
350
|
else
|
349
|
-
|
351
|
+
gg = i
|
350
352
|
break
|
351
353
|
end
|
352
354
|
end
|
353
|
-
gm =
|
355
|
+
gm = gg + 1
|
354
356
|
gd = g_day_no + 1
|
355
357
|
|
356
358
|
[gy,gm,gd]
|
data/lib/jalalidate/version.rb
CHANGED
data/spec/jalalidate_spec.rb
CHANGED
@@ -32,9 +32,9 @@ describe JalaliDate do
|
|
32
32
|
|
33
33
|
it "should return today, yesterday, and tomorrow date according to jalali calendar" do
|
34
34
|
Date.stub!(:today).and_return(Date.new(2010,1,1))
|
35
|
-
JalaliDate.today.should
|
36
|
-
JalaliDate.yesterday.should
|
37
|
-
JalaliDate.tomorrow.should
|
35
|
+
JalaliDate.today.should === JalaliDate.new(1388,10,11)
|
36
|
+
JalaliDate.yesterday.should === JalaliDate.new(1388,10,10)
|
37
|
+
JalaliDate.tomorrow.should === JalaliDate.new(1388,10,12)
|
38
38
|
end
|
39
39
|
|
40
40
|
it "should distinguish invalid jalali dates" do
|
@@ -57,39 +57,39 @@ describe JalaliDate do
|
|
57
57
|
|
58
58
|
it "should convert to string, array and hash correctly" do
|
59
59
|
jdate = JalaliDate.new(1388,10,11)
|
60
|
-
jdate.to_s.should
|
61
|
-
jdate.to_a.should
|
62
|
-
jdate.to_hash.should
|
60
|
+
jdate.to_s.should === "1388/10/11"
|
61
|
+
jdate.to_a.should === [1388,10,11]
|
62
|
+
jdate.to_hash.should === {:year => 1388, :month => 10, :day => 11}
|
63
63
|
end
|
64
64
|
|
65
65
|
it "should be able to add and substract days from the currect jalai date object" do
|
66
66
|
jdate = JalaliDate.new(1388,10,11)
|
67
67
|
five_days_later = jdate + 5
|
68
68
|
twenty_days_ago = jdate - 20
|
69
|
-
five_days_later.should
|
70
|
-
twenty_days_ago.should
|
69
|
+
five_days_later.should === JalaliDate.new(1388,10,16)
|
70
|
+
twenty_days_ago.should === JalaliDate.new(1388,9,21)
|
71
71
|
end
|
72
72
|
|
73
73
|
it "should be able to compare two jalali dates" do
|
74
74
|
jdate = JalaliDate.new(1388,10,11)
|
75
75
|
next_month_jdate = JalaliDate.new(1388,11,11)
|
76
|
-
next_month_jdate.<=>(jdate).should
|
77
|
-
jdate.<=>(next_month_jdate).should
|
76
|
+
next_month_jdate.<=>(jdate).should === 1
|
77
|
+
jdate.<=>(next_month_jdate).should === -1
|
78
78
|
jdate.<=>(jdate).should == 0
|
79
79
|
end
|
80
80
|
|
81
81
|
it "should now its next and previous dates" do
|
82
82
|
jdate = JalaliDate.new(1388,10,11)
|
83
|
-
jdate.next.should
|
84
|
-
jdate.previous.should
|
83
|
+
jdate.next.should === JalaliDate.new(1388,10,12)
|
84
|
+
jdate.previous.should === JalaliDate.new(1388,10,10)
|
85
85
|
end
|
86
86
|
|
87
87
|
it "should be able to move the month forward and backward" do
|
88
88
|
jdate = JalaliDate.new(1388,10,11)
|
89
89
|
five_month_later = jdate >> 5
|
90
90
|
five_month_ago = jdate << 5
|
91
|
-
five_month_later.should
|
92
|
-
five_month_ago.should
|
91
|
+
five_month_later.should === JalaliDate.new(1389,3,11)
|
92
|
+
five_month_ago.should === JalaliDate.new(1388,5,11)
|
93
93
|
end
|
94
94
|
|
95
95
|
it "should be able to cycle through dates in different ways, namely, step, upto and downto" do
|
@@ -99,13 +99,13 @@ describe JalaliDate do
|
|
99
99
|
jdate.step( jdate + 10 , 2) do |jd|
|
100
100
|
days_string += jd.day.to_s
|
101
101
|
end
|
102
|
-
days_string.should
|
102
|
+
days_string.should === "101214161820"
|
103
103
|
|
104
104
|
days_string = ""
|
105
105
|
jdate.upto(jdate+5) do |jd|
|
106
106
|
days_string += jd.day.to_s
|
107
107
|
end
|
108
|
-
days_string.should
|
108
|
+
days_string.should === "101112131415"
|
109
109
|
|
110
110
|
days_string = ""
|
111
111
|
jdate.downto(jdate-5) do |jd|
|
@@ -115,10 +115,10 @@ describe JalaliDate do
|
|
115
115
|
end
|
116
116
|
|
117
117
|
it "should return a correct year day based on Jalali Calendar" do
|
118
|
-
JalaliDate.new(1388,1,1).yday.should
|
119
|
-
JalaliDate.new(1388,12,29).yday.should
|
120
|
-
JalaliDate.new(1387,12,30).yday.should
|
121
|
-
JalaliDate.new(1388,9,17).yday.should
|
118
|
+
JalaliDate.new(1388,1,1).yday.should === 1
|
119
|
+
JalaliDate.new(1388,12,29).yday.should === 365
|
120
|
+
JalaliDate.new(1387,12,30).yday.should === 366
|
121
|
+
JalaliDate.new(1388,9,17).yday.should === 263
|
122
122
|
end
|
123
123
|
|
124
124
|
it "should be able to print jalali date in different formats" do
|
@@ -131,15 +131,15 @@ describe JalaliDate do
|
|
131
131
|
end
|
132
132
|
|
133
133
|
it "should be able for format %H %I %M %p %S %X %Z correctly if initiallized with time" do
|
134
|
-
JalaliDate.new(1388,2,15,5,50,10).strftime("%H").should
|
135
|
-
JalaliDate.new(1388,2,15,18,50,10).strftime("%H %I").should
|
136
|
-
JalaliDate.new(1388,2,15,12,50,10).strftime("%H %I").should
|
137
|
-
JalaliDate.new(1388,2,15,12,50,10).strftime("%H %I %M %S").should
|
138
|
-
JalaliDate.new(1388,2,15,5,50,10).strftime("%p").should
|
139
|
-
JalaliDate.new(1388,2,15,15,50,10).strftime("%p").should
|
140
|
-
JalaliDate.new(1388,2,15,15,50,10).strftime("%X").should
|
141
|
-
JalaliDate.new(1388,2,15,15,50,10).strftime("%X").should
|
142
|
-
JalaliDate.new(1388,2,15,15,50,10,"CET",3600).strftime("%Z").should
|
134
|
+
JalaliDate.new(1388,2,15,5,50,10).strftime("%H").should === "05"
|
135
|
+
JalaliDate.new(1388,2,15,18,50,10).strftime("%H %I").should === "18 06"
|
136
|
+
JalaliDate.new(1388,2,15,12,50,10).strftime("%H %I").should === "12 00"
|
137
|
+
JalaliDate.new(1388,2,15,12,50,10).strftime("%H %I %M %S").should === "12 00 50 10"
|
138
|
+
JalaliDate.new(1388,2,15,5,50,10).strftime("%p").should === "قبل از ظهر"
|
139
|
+
JalaliDate.new(1388,2,15,15,50,10).strftime("%p").should === "بعد از ظهر"
|
140
|
+
JalaliDate.new(1388,2,15,15,50,10).strftime("%X").should === "15:50:10"
|
141
|
+
JalaliDate.new(1388,2,15,15,50,10).strftime("%X").should === "15:50:10"
|
142
|
+
JalaliDate.new(1388,2,15,15,50,10,"CET",3600).strftime("%Z").should === "CET"
|
143
143
|
time = Time.now
|
144
144
|
JalaliDate.new(time).strftime("%Z").should == time.zone
|
145
145
|
end
|
data/spec/spec_helper.rb
CHANGED
metadata
CHANGED
@@ -1,65 +1,58 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: jalalidate
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.3.2
|
5
5
|
prerelease:
|
6
|
-
segments:
|
7
|
-
- 0
|
8
|
-
- 3
|
9
|
-
- 1
|
10
|
-
version: 0.3.1
|
11
6
|
platform: ruby
|
12
|
-
authors:
|
7
|
+
authors:
|
13
8
|
- Allen A. Bargi
|
14
9
|
autorequire:
|
15
10
|
bindir: bin
|
16
11
|
cert_chain: []
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
- !ruby/object:Gem::Dependency
|
12
|
+
date: 2013-04-08 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
21
15
|
name: rspec
|
22
|
-
|
23
|
-
requirement: &id001 !ruby/object:Gem::Requirement
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
24
17
|
none: false
|
25
|
-
requirements:
|
18
|
+
requirements:
|
26
19
|
- - ~>
|
27
|
-
- !ruby/object:Gem::Version
|
28
|
-
|
29
|
-
segments:
|
30
|
-
- 2
|
31
|
-
- 1
|
32
|
-
- 0
|
33
|
-
version: 2.1.0
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: 2.13.0
|
34
22
|
type: :development
|
35
|
-
version_requirements: *id001
|
36
|
-
- !ruby/object:Gem::Dependency
|
37
|
-
name: bundler
|
38
23
|
prerelease: false
|
39
|
-
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ~>
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: 2.13.0
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: bundler
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
40
33
|
none: false
|
41
|
-
requirements:
|
34
|
+
requirements:
|
42
35
|
- - ~>
|
43
|
-
- !ruby/object:Gem::Version
|
44
|
-
|
45
|
-
segments:
|
46
|
-
- 1
|
47
|
-
- 0
|
48
|
-
- 0
|
49
|
-
version: 1.0.0
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: 1.3.0
|
50
38
|
type: :development
|
51
|
-
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ~>
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: 1.3.0
|
52
46
|
description: A library for working with Jalali Calendar (a.k.a Persian Calendar)
|
53
47
|
email: allen.bargi@gmail.com
|
54
|
-
executables:
|
48
|
+
executables:
|
55
49
|
- jcal
|
56
50
|
- jdate
|
57
51
|
extensions: []
|
58
|
-
|
59
|
-
extra_rdoc_files:
|
52
|
+
extra_rdoc_files:
|
60
53
|
- LICENSE
|
61
54
|
- README.md
|
62
|
-
files:
|
55
|
+
files:
|
63
56
|
- .gitignore
|
64
57
|
- Gemfile
|
65
58
|
- Gemfile.lock
|
@@ -77,37 +70,29 @@ files:
|
|
77
70
|
- spec/spec_helper.rb
|
78
71
|
homepage: http://github.com/aziz/jalalidate
|
79
72
|
licenses: []
|
80
|
-
|
81
73
|
post_install_message:
|
82
|
-
rdoc_options:
|
74
|
+
rdoc_options:
|
83
75
|
- --charset=UTF-8
|
84
|
-
require_paths:
|
76
|
+
require_paths:
|
85
77
|
- lib
|
86
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
78
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
87
79
|
none: false
|
88
|
-
requirements:
|
89
|
-
- -
|
90
|
-
- !ruby/object:Gem::Version
|
91
|
-
|
92
|
-
|
93
|
-
- 0
|
94
|
-
version: "0"
|
95
|
-
required_rubygems_version: !ruby/object:Gem::Requirement
|
80
|
+
requirements:
|
81
|
+
- - ! '>='
|
82
|
+
- !ruby/object:Gem::Version
|
83
|
+
version: '0'
|
84
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
96
85
|
none: false
|
97
|
-
requirements:
|
98
|
-
- -
|
99
|
-
- !ruby/object:Gem::Version
|
100
|
-
|
101
|
-
segments:
|
102
|
-
- 0
|
103
|
-
version: "0"
|
86
|
+
requirements:
|
87
|
+
- - ! '>='
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
104
90
|
requirements: []
|
105
|
-
|
106
91
|
rubyforge_project: jalalidate
|
107
|
-
rubygems_version: 1.
|
92
|
+
rubygems_version: 1.8.25
|
108
93
|
signing_key:
|
109
94
|
specification_version: 3
|
110
95
|
summary: A library for working with Jalali Calendar (a.k.a Persian Calendar)
|
111
|
-
test_files:
|
96
|
+
test_files:
|
112
97
|
- spec/jalalidate_spec.rb
|
113
98
|
- spec/spec_helper.rb
|