parsi-date 0.3.1 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: a3d3208eb15dffe3337029d416689f316b35ada0
4
- data.tar.gz: 345fe584383351f93dedbe88dec53d69ab4da941
2
+ SHA256:
3
+ metadata.gz: e8e274346e199194141c9e715233cd1ce4fd88262abae4ddbcab5861c3a8f22f
4
+ data.tar.gz: 0dbcb0ae86ff18037e23f42c42eb059ae777e4e35360e685d1e4c1966b6d624f
5
5
  SHA512:
6
- metadata.gz: 6e30ea83c086ea01d854ce30dcb756007d298ebedf2531abbf05db90c1db55f0087ca28b59887483c5f7f64fe34307c7c54dfbc5b2e0d4f6018ff08284e98f17
7
- data.tar.gz: b5452ff1d01c2983317da602d660c1c435c4789aaf7e36e2c9c2c8ae0e865ae228d092b4ac595e8a403a394d34c5ff0c43819f2e7a56a275771dcceceb441e30
6
+ metadata.gz: 4bb7986d931227c9bb2630593c3ebbc9d2bb6305256bde113dd9db9e7dc6aaf93181070f1c92ca486bb665f88a5ba5ac81a77e9d4227bc538b794dbb9f9c451e
7
+ data.tar.gz: 439b3f899dff9c1507cd78dcef919fe75e2d087382bba7a6428778dc69572d1ed4f40e2e9ea69a83502ae72366f8aa39425662fe445196048d34b3742d828acb
@@ -0,0 +1,27 @@
1
+ name: Ruby
2
+
3
+ on:
4
+ push:
5
+ branches: [master]
6
+ pull_request:
7
+ branches: [master]
8
+
9
+ permissions:
10
+ contents: read
11
+
12
+ jobs:
13
+ test:
14
+ runs-on: ubuntu-latest
15
+ strategy:
16
+ matrix:
17
+ ruby-version: ["2.6", "2.7", "3.0", "3.1"]
18
+
19
+ steps:
20
+ - uses: actions/checkout@v3
21
+ - name: Set up Ruby
22
+ uses: ruby/setup-ruby@v1
23
+ with:
24
+ ruby-version: ${{ matrix.ruby-version }}
25
+ bundler-cache: true
26
+ - name: Run tests
27
+ run: bundle exec rspec spec
data/lib/parsi-date.rb CHANGED
@@ -141,11 +141,13 @@ module Parsi
141
141
  LD_EPOCH_IN_CJD = 2299160 # :nodoc:
142
142
  DAYS_IN_MONTH = [nil, 31, 31, 31, 31, 31, 31, 30, 30, 30, 30, 30, 29] # :nodoc:
143
143
 
144
+ LEAP_REMINDERS = [1, 5, 9, 13, 17, 22, 26, 30].freeze
145
+
144
146
  shared_methods = Module.new do
145
147
 
146
148
  # Returns true if the given year is a leap year of the calendar.
147
149
  def leap? year
148
- ((((((year - ((year > 0) ? 474 : 473)) % 2820) + 474) + 38) * 682) % 2816) < 682
150
+ LEAP_REMINDERS.include?(year - (year / 33).floor * 33)
149
151
  end
150
152
  alias_method :jalali_leap?, :leap?
151
153
 
@@ -189,7 +191,7 @@ module Parsi
189
191
  # Returns the corresponding Julian Day Number if they do, nil if they don't.
190
192
  # Invalid values cause an ArgumentError to be raised.
191
193
  def _valid_civil? year, month, day # :nodoc:
192
- return unless year.is_a?(Fixnum) && month.is_a?(Fixnum) && day.is_a?(Fixnum)
194
+ return unless year.is_a?(Integer) && month.is_a?(Integer) && day.is_a?(Integer)
193
195
  return civil_to_jd(year, 12, 30) if leap?(year) && month == 12 && day == 30
194
196
 
195
197
  if 1 <= month && month <= 12 && 1 <= day && day <= DAYS_IN_MONTH[month]
@@ -747,8 +749,9 @@ class Date
747
749
 
748
750
  # Returns a Parsi::Date object representing same date in Jalali calendar
749
751
  def to_parsi
750
- Parsi::Date.new! ajd, offset
752
+ Parsi::Date.new! ajd
751
753
  end
754
+
752
755
  alias :jalali :to_parsi
753
756
  alias :to_jalali :to_parsi
754
757
  alias :to_persian :to_parsi
data/lib/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  module Parsi
2
2
  class Date
3
- VERSION = "0.3.1"
3
+ VERSION = "0.4.0"
4
4
  end
5
5
  end
data/parsi-date.gemspec CHANGED
@@ -18,9 +18,9 @@ Gem::Specification.new do |s|
18
18
  s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
19
19
  s.require_paths = ['lib']
20
20
 
21
- s.add_development_dependency("bundler", "~> 1.4")
22
- s.add_development_dependency("rake", "~> 10.0")
23
- s.add_development_dependency("rspec", "~> 2.0")
24
- s.add_development_dependency("activerecord", "~> 4.2")
25
- s.add_development_dependency("sqlite3", "~> 1.3")
21
+ s.add_development_dependency("bundler", "~> 2.0")
22
+ s.add_development_dependency("rake", "~> 13.0")
23
+ s.add_development_dependency("rspec", "~> 3.0")
24
+ s.add_development_dependency("activerecord", "~> 6.0")
25
+ s.add_development_dependency("sqlite3", "~> 1.5")
26
26
  end
@@ -1,57 +1,57 @@
1
1
  describe "Parsi::Date#ajd" do
2
2
  it "determines the Astronomical Julian day" do
3
- Parsi::Date.civil(1391, 8, 6).ajd.should == Rational(4912455, 2)
3
+ expect Parsi::Date.civil(1391, 8, 6).ajd == Rational(4912455, 2)
4
4
  end
5
5
  end
6
6
 
7
7
  describe "Parsi::Date#amjd" do
8
8
  it "determines the Astronomical Modified Julian day" do
9
- Parsi::Date.civil(1391, 8, 6).amjd.should == 56227
9
+ expect Parsi::Date.civil(1391, 8, 6).amjd == 56227
10
10
  end
11
11
  end
12
12
 
13
13
  describe "Parsi::Date#mjd" do
14
14
  it "determines the Modified Julian day" do
15
- Parsi::Date.civil(1391, 8, 6).mjd.should == 56227
15
+ expect Parsi::Date.civil(1391, 8, 6).mjd == 56227
16
16
  end
17
17
  end
18
18
 
19
19
  describe "Parsi::Date#ld" do
20
20
  it "determines the Modified Julian day" do
21
- Parsi::Date.civil(1391, 8, 6).ld.should == 157068
21
+ expect Parsi::Date.civil(1391, 8, 6).ld == 157068
22
22
  end
23
23
  end
24
24
 
25
25
  describe "Parsi::Date#year" do
26
26
  it "determines the year" do
27
- Parsi::Date.civil(1391, 8, 6).year.should == 1391
27
+ expect Parsi::Date.civil(1391, 8, 6).year == 1391
28
28
  end
29
29
  end
30
30
 
31
31
  describe "Parsi::Date#yday" do
32
32
  it "determines the year" do
33
- Parsi::Date.civil(1391, 1, 17).yday.should == 17
34
- Parsi::Date.civil(1391, 8, 6).yday.should == 222
33
+ expect Parsi::Date.civil(1391, 1, 17).yday == 17
34
+ expect Parsi::Date.civil(1391, 8, 6).yday == 222
35
35
  end
36
36
  end
37
37
 
38
38
  describe "Parsi::Date#mon" do
39
39
  it "determines the month" do
40
- Parsi::Date.civil(1391, 1, 17).mon.should == 1
41
- Parsi::Date.civil(1391, 8, 6).mon.should == 8
40
+ expect Parsi::Date.civil(1391, 1, 17).mon == 1
41
+ expect Parsi::Date.civil(1391, 8, 6).mon == 8
42
42
  end
43
43
  end
44
44
 
45
45
  describe "Parsi::Date#mday" do
46
46
  it "determines the day of the month" do
47
- Parsi::Date.civil(1391, 1, 17).mday.should == 17
48
- Parsi::Date.civil(1391, 10, 28).mday.should == 28
47
+ expect Parsi::Date.civil(1391, 1, 17).mday == 17
48
+ expect Parsi::Date.civil(1391, 10, 28).mday == 28
49
49
  end
50
50
  end
51
51
 
52
52
  describe "Parsi::Date#wday" do
53
53
  it "determines the week day" do
54
- Parsi::Date.civil(1391, 1, 17).wday.should == 4
55
- Parsi::Date.civil(1391, 8, 6).wday.should == 6
54
+ expect Parsi::Date.civil(1391, 1, 17).wday == 4
55
+ expect Parsi::Date.civil(1391, 8, 6).wday == 6
56
56
  end
57
57
  end
@@ -24,7 +24,7 @@ end
24
24
  describe "Record extended with Parsi::Date::Accessors" do
25
25
  it "has parsi postfixed accessor for giver attributes" do
26
26
  record = Record.new
27
- %i(created_at_parsi created_at_parsi= updated_at_parsi updated_at_parsi).each do |name|
27
+ [:created_at_parsi, :created_at_parsi=, :updated_at_parsi, :updated_at_parsi].each do |name|
28
28
  expect(record.respond_to?(name)).to be_truthy
29
29
  end
30
30
  end
@@ -55,7 +55,7 @@ describe "Record extended with Parsi::Date::Accessors" do
55
55
 
56
56
  it "raises error when string is not a date" do
57
57
  record = Record.new
58
- expect {record.created_at_parsi = "1393-13-11" }.to raise_error
58
+ expect {record.created_at_parsi = "1393-13-11" }.to raise_error(ArgumentError, 'invalid date')
59
59
  end
60
60
  end
61
61
  end
@@ -1,27 +1,25 @@
1
1
  describe "Parsi::Date#>>" do
2
2
  it "adds the number of months to a Parsi::Date" do
3
- d = Parsi::Date.civil(1391, 2, 27) >> 10
4
- d.should == Parsi::Date.civil(1391, 12, 27)
3
+ expect (Parsi::Date.civil(1391, 2, 27) >> 10) == Parsi::Date.civil(1391, 12, 27)
5
4
  end
6
5
 
7
6
  it "sets the day to the last day of a month if the day doesn't exist" do
8
- d = Parsi::Date.civil(1391, 6, 31) >> 1
9
- d.should == Parsi::Date.civil(1391, 7, 30)
7
+ expect (Parsi::Date.civil(1391, 6, 31) >> 1) == Parsi::Date.civil(1391, 7, 30)
10
8
  end
11
9
 
12
10
  it "raise a TypeError when passed a Symbol" do
13
- lambda { Parsi::Date.civil(1391, 2, 27) >> :hello }.should raise_error(TypeError)
11
+ expect { Parsi::Date.civil(1391, 2, 27) >> :hello }.to raise_error(TypeError)
14
12
  end
15
13
 
16
14
  it "raise a TypeError when passed a String" do
17
- lambda { Parsi::Date.civil(1391, 2, 27) >> "hello" }.should raise_error(TypeError)
15
+ expect { Parsi::Date.civil(1391, 2, 27) >> "hello" }.to raise_error(TypeError)
18
16
  end
19
17
 
20
18
  it "raise a TypeError when passed a Parsi::Date" do
21
- lambda { Parsi::Date.civil(1391, 2, 27) >> Parsi::Date.new }.should raise_error(TypeError)
19
+ expect { Parsi::Date.civil(1391, 2, 27) >> Parsi::Date.new }.to raise_error(TypeError)
22
20
  end
23
21
 
24
22
  it "raise a TypeError when passed an Object" do
25
- lambda { Parsi::Date.civil(1391, 2, 27) >> Object.new }.should raise_error(TypeError)
23
+ expect { Parsi::Date.civil(1391, 2, 27) >> Object.new }.to raise_error(TypeError)
26
24
  end
27
25
  end
@@ -1,27 +1,25 @@
1
1
  describe "Parsi::Date#+" do
2
2
  it "adds the number of days to a Parsi::Date" do
3
- d = Parsi::Date.civil(1391, 2, 27) + 10
4
- d.should == Parsi::Date.civil(1391, 3, 6)
3
+ expect Parsi::Date.civil(1391, 2, 27) + 10 == Parsi::Date.civil(1391, 3, 6)
5
4
  end
6
5
 
7
6
  it "adds a negative number of days to a Parsi::Date" do
8
- d = Parsi::Date.civil(1391, 2, 27) + (-10)
9
- d.should == Parsi::Date.civil(1391, 2, 17)
7
+ expect Parsi::Date.civil(1391, 2, 27) + (-10) == Parsi::Date.civil(1391, 2, 17)
10
8
  end
11
9
 
12
10
  it "raises a TypeError when passed a Symbol" do
13
- lambda { Parsi::Date.civil(1391, 2, 27) + :hello }.should raise_error(TypeError)
11
+ expect { Parsi::Date.civil(1391, 2, 27) + :hello }.to raise_error(TypeError)
14
12
  end
15
13
 
16
14
  it "raises a TypeError when passed a String" do
17
- lambda { Parsi::Date.civil(1391, 2, 27) + "hello" }.should raise_error(TypeError)
15
+ expect { Parsi::Date.civil(1391, 2, 27) + "hello" }.to raise_error(TypeError)
18
16
  end
19
17
 
20
18
  it "raises a TypeError when passed a Parsi::Date" do
21
- lambda { Parsi::Date.civil(1391, 2, 27) + Parsi::Date.new }.should raise_error(TypeError)
19
+ expect { Parsi::Date.civil(1391, 2, 27) + Parsi::Date.new }.to raise_error(TypeError)
22
20
  end
23
21
 
24
22
  it "raises a TypeError when passed an Object" do
25
- lambda { Parsi::Date.civil(1391, 2, 27) + Object.new }.should raise_error(TypeError)
23
+ expect { Parsi::Date.civil(1391, 2, 27) + Object.new }.to raise_error(TypeError)
26
24
  end
27
25
  end
@@ -2,29 +2,29 @@ require 'date'
2
2
 
3
3
  describe "Parsi::Date#<=>" do
4
4
  it "returns 0 when two dates are equal" do
5
- (Parsi::Date.civil(1391, 4, 6) <=> Parsi::Date.civil(1391, 4, 6)).should == 0
6
- (Parsi::Date.civil(1391, 4, 6) <=> Date.civil(2012, 6, 26)).should == 0
5
+ expect (Parsi::Date.civil(1391, 4, 6) <=> Parsi::Date.civil(1391, 4, 6)) == 0
6
+ expect (Parsi::Date.civil(1391, 4, 6) <=> Date.civil(2012, 6, 26)) == 0
7
7
  end
8
8
 
9
9
  it "returns -1 when self is less than another date" do
10
- (Parsi::Date.civil(1391, 4, 5) <=> Parsi::Date.civil(1391, 4, 6)).should == -1
11
- (Parsi::Date.civil(1391, 4, 5) <=> Date.civil(2012, 6, 26)).should == -1
10
+ expect (Parsi::Date.civil(1391, 4, 5) <=> Parsi::Date.civil(1391, 4, 6)) == -1
11
+ expect (Parsi::Date.civil(1391, 4, 5) <=> Date.civil(2012, 6, 26)) == -1
12
12
  end
13
13
 
14
14
  it "returns 1 when self is greater than another date" do
15
- (Parsi::Date.civil(1392, 4, 7) <=> Parsi::Date.civil(1391, 4, 6)).should == 1
16
- (Parsi::Date.civil(1391, 4, 7) <=> Date.civil(2012, 6, 26)).should == 1
15
+ expect (Parsi::Date.civil(1392, 4, 7) <=> Parsi::Date.civil(1391, 4, 6)) == 1
16
+ expect (Parsi::Date.civil(1391, 4, 7) <=> Date.civil(2012, 6, 26)) == 1
17
17
  end
18
18
 
19
19
  it "returns 0 when self is equal to a Numeric" do
20
- (Parsi::Date.civil(1391, 4, 6) <=> Rational(4912209,2)).should == 0
20
+ expect (Parsi::Date.civil(1391, 4, 6) <=> Rational(4912209,2)) == 0
21
21
  end
22
22
 
23
23
  it "returns -1 when self is less than a Numeric" do
24
- (Parsi::Date.civil(1391, 4, 6) <=> Rational(4912210,2)).should == -1
24
+ expect (Parsi::Date.civil(1391, 4, 6) <=> Rational(4912210,2)) == -1
25
25
  end
26
26
 
27
27
  it "returns 1 when self is greater than a Numeric" do
28
- (Parsi::Date.civil(1391, 4, 6) <=> Rational(4912208,2)).should == 1
28
+ expect (Parsi::Date.civil(1391, 4, 6) <=> Rational(4912208,2)) == 1
29
29
  end
30
30
  end
@@ -1,41 +1,41 @@
1
1
  # encoding: utf-8
2
2
  describe "Date constants" do
3
3
  it "defines MONTHNAMES" do
4
- Parsi::Date::MONTHNAMES.should == [nil] +
4
+ expect Parsi::Date::MONTHNAMES == [nil] +
5
5
  %w(فروردین اردیبهشت خرداد تیر مرداد شهریور مهر آبان آذر دی بهمن اسفند)
6
6
  end
7
7
 
8
8
  it "defines EN_MONTHNAMES" do
9
- Parsi::Date::EN_MONTHNAMES.should == [nil] +
9
+ expect Parsi::Date::EN_MONTHNAMES == [nil] +
10
10
  %w(farvardin ordibehesht khordad tir mordad shahrivar mehr aban azar day bahman esfand)
11
11
  end
12
12
 
13
13
  it "defines ABBR_MONTHNAMES" do
14
- Parsi::Date::ABBR_MONTHNAMES.should == [nil] +
14
+ expect Parsi::Date::ABBR_MONTHNAMES == [nil] +
15
15
  %w(far ord kho tir mor sha meh abn azr day bah esf)
16
16
  end
17
17
 
18
18
  it "defines DAYNAMES" do
19
- Parsi::Date::DAYNAMES.should == %w(یک‌شنبه دوشنبه سه‌شنبه چهارشنبه پنج‌شنبه جمعه شنبه)
19
+ expect Parsi::Date::DAYNAMES == %w(یک‌شنبه دوشنبه سه‌شنبه چهارشنبه پنج‌شنبه جمعه شنبه)
20
20
  end
21
21
 
22
22
  it "defines EN_DAYNAMES" do
23
- Parsi::Date::EN_DAYNAMES.should == %w(yekshanbe doshanbe seshanbe chaharshanbe panjshanbe jomee shanbe)
23
+ expect Parsi::Date::EN_DAYNAMES == %w(yekshanbe doshanbe seshanbe chaharshanbe panjshanbe jomee shanbe)
24
24
  end
25
25
 
26
26
  it "defines ABBR_DAYNAMES" do
27
- Parsi::Date::ABBR_DAYNAMES.should == %w(۱ش ۲ش ۳ش ۴ش ۵ش ج ش)
27
+ expect Parsi::Date::ABBR_DAYNAMES == %w(۱ش ۲ش ۳ش ۴ش ۵ش ج ش)
28
28
  end
29
29
 
30
30
  it "defines ABBR_EN_DAYNAMES" do
31
- Parsi::Date::ABBR_EN_DAYNAMES.should == %w(ye do se ch pj jo sh)
31
+ expect Parsi::Date::ABBR_EN_DAYNAMES == %w(ye do se ch pj jo sh)
32
32
  end
33
33
 
34
34
  it "freezes MONTHNAMES, DAYNAMES, EN_DAYNAMES, ABBR_MONTHNAMES, ABBR_DAYSNAMES" do
35
35
  [Parsi::Date::MONTHNAMES, Parsi::Date::EN_MONTHNAMES, Parsi::Date::ABBR_MONTHNAMES,
36
36
  Parsi::Date::DAYNAMES, Parsi::Date::EN_DAYNAMES,
37
- Parsi::Date::ABBR_DAYNAMES, Parsi::Date::ABBR_EN_DAYNAMES].each do |ary|
38
- ary.should be_frozen
37
+ Parsi::Date::ABBR_DAYNAMES, Parsi::Date::ABBR_EN_DAYNAMES].each do |array|
38
+ expect(array).to be_frozen
39
39
  end
40
40
  end
41
41
  end
@@ -21,35 +21,35 @@ describe Parsi::Date do
21
21
 
22
22
  it "constructs a Date for 1/1/1 by default" do
23
23
  date = Parsi::Date.civil
24
- date.year.should == 1
25
- date.month.should == 1
26
- date.day.should == 1
24
+ expect date.year == 1
25
+ expect date.month == 1
26
+ expect date.day == 1
27
27
  end
28
28
  end
29
29
 
30
30
  context "ordinal" do
31
31
  it "constructs a Date object from an ordinal date" do
32
- Parsi::Date.ordinal(1390).should == Parsi::Date.civil(1390, 1, 1)
33
- Parsi::Date.ordinal(1390,7).should == Parsi::Date.civil(1390, 1, 7)
34
- Parsi::Date.ordinal(1390,100).should == Parsi::Date.civil(1390, 4, 7)
32
+ expect Parsi::Date.ordinal(1390) == Parsi::Date.civil(1390, 1, 1)
33
+ expect Parsi::Date.ordinal(1390,7) == Parsi::Date.civil(1390, 1, 7)
34
+ expect Parsi::Date.ordinal(1390,100) == Parsi::Date.civil(1390, 4, 7)
35
35
  end
36
36
  end
37
37
 
38
38
  context "parse" do
39
- it "should parse date from strings" do
39
+ it "parses date from strings" do
40
40
  ['1391/8/6', '1391-8-6', '1391 8 6', '1391 8 6', '13910806'].each do |date_string|
41
41
  date = Parsi::Date.parse date_string
42
- [date.year, date.month, date.day].should == [1391, 8, 6]
42
+ expect [date.year, date.month, date.day] == [1391, 8, 6]
43
43
  end
44
44
  end
45
45
 
46
46
  it "completes century when second arg is true" do
47
- Date.stub(:today) { Date.new 2012, 10, 26 }
47
+ allow(Date).to receive(:today) { Date.new 2012, 10, 26 }
48
48
  date = Parsi::Date.parse '91/8/5', true
49
- [date.year, date.month, date.day].should == [1391, 8, 5]
49
+ expect [date.year, date.month, date.day] == [1391, 8, 5]
50
50
  end
51
51
 
52
- it "should raise ArgumentError on invalid date string" do
52
+ it "raises ArgumentError on invalid date string" do
53
53
  expect { date = Parsi::Date.parse '1390/12/30' }.to raise_error(ArgumentError)
54
54
  expect { date = Parsi::Date.parse 'bad date string' }.to raise_error(ArgumentError)
55
55
  expect { date = Parsi::Date.parse '12-30-1390' }.to raise_error(ArgumentError)
@@ -1,36 +1,36 @@
1
1
  describe "Parsi::Date.jd" do
2
2
  it "constructs a date form given Chronological Julian day number" do
3
- Parsi::Date.jd(2456228).should == Parsi::Date.civil(1391, 8, 6)
4
- Parsi::Date.jd(2456229).should == Parsi::Date.civil(1391, 8, 7)
3
+ expect Parsi::Date.jd(2456228) == Parsi::Date.civil(1391, 8, 6)
4
+ expect Parsi::Date.jd(2456229) == Parsi::Date.civil(1391, 8, 7)
5
5
  end
6
6
 
7
7
  it "returns a Date object representing Julian day 0 if no arguments passed"do
8
- Parsi::Date.jd.should == Parsi::Date.civil(-5334, 9, 1)
8
+ expect Parsi::Date.jd == Parsi::Date.civil(-5334, 9, 1)
9
9
  end
10
10
 
11
11
  it "constructs a Date object if passed a negative number" do
12
- Parsi::Date.jd(-1).should == Parsi::Date.civil(-5334, 8, 30)
12
+ expect Parsi::Date.jd(-1) == Parsi::Date.civil(-5334, 8, 30)
13
13
  end
14
14
  end
15
15
 
16
16
  describe "Parsi::Date#jd" do
17
17
  it "determines the Julian day for a Date object" do
18
- Parsi::Date.civil(1391, 8, 7).jd.should == 2456229
18
+ expect Parsi::Date.civil(1391, 8, 7).jd == 2456229
19
19
  end
20
20
  end
21
21
 
22
22
  describe "Parsi::Date#to_gregorian" do
23
23
  it "converts date to Gregorian date" do
24
24
  date = Parsi::Date.civil(1391, 8, 7).to_gregorian
25
- date.should be_a(Date)
26
- date.should == Date.civil(2012, 10, 28)
25
+ expect(date).to be_a(Date)
26
+ expect date == Date.civil(2012, 10, 28)
27
27
  end
28
28
  end
29
29
 
30
30
  describe "Date#to_parsi" do
31
31
  it "converts date to Parsi date" do
32
32
  date = Date.civil(2012, 10, 28).to_parsi
33
- date.should be_a(Parsi::Date)
34
- date.should == Parsi::Date.civil(1391, 8, 7)
33
+ expect(date).to be_a(Parsi::Date)
34
+ expect date == Parsi::Date.civil(1391, 8, 7)
35
35
  end
36
36
  end
@@ -1,13 +1,15 @@
1
1
  describe "Parsi::Date#leap?" do
2
2
  it "returns true if a year is a leap year in the Parsi (Jalali) calendar" do
3
- Parsi::Date.leap?(1387).should be_truthy
4
- Parsi::Date.leap?(1391).should be_truthy
5
- Parsi::Date.leap?(1395).should be_truthy
3
+ expect Parsi::Date.leap?(1387) == true
4
+ expect Parsi::Date.leap?(1391) == true
5
+ expect Parsi::Date.leap?(1395) == true
6
+ expect Parsi::Date.leap?(1403) == true
6
7
  end
7
8
 
8
9
  it "returns false if a year is not a leap year in the Parsi (Jalali) calendar" do
9
- Parsi::Date.leap?(1390).should be_falsey
10
- Parsi::Date.leap?(1392).should be_falsey
11
- Parsi::Date.leap?(1400).should be_falsey
10
+ expect Parsi::Date.leap?(1390) == false
11
+ expect Parsi::Date.leap?(1392) == false
12
+ expect Parsi::Date.leap?(1400) == false
13
+ expect Parsi::Date.leap?(1404) == false
12
14
  end
13
15
  end
@@ -5,23 +5,23 @@ describe "Parsi::Date#step" do
5
5
  de = Parsi::Date.civil(1391, 9, 29)
6
6
  count = 0
7
7
  de.step(ds) do |d|
8
- d.should <= ds
9
- d.should >= de
8
+ expect d <= ds
9
+ expect d >= de
10
10
  count += 1
11
11
  end
12
- count.should == 13
12
+ expect count == 13
13
13
 
14
14
  count = 0
15
15
  de.step(ds, 5) do |d|
16
- d.should <= ds
17
- d.should >= de
16
+ expect d <= ds
17
+ expect d >= de
18
18
  count += 1
19
19
  end
20
- count.should == 3
20
+ expect count == 3
21
21
 
22
22
  count = 0
23
23
  ds.step(de) do |d|; count += 1; end
24
- count.should == 0
24
+ expect count == 0
25
25
  end
26
26
 
27
27
  it "steps backward in time" do
@@ -29,22 +29,22 @@ describe "Parsi::Date#step" do
29
29
  de = Parsi::Date.civil(1390, 3, 29)
30
30
  count = 0
31
31
  ds.step(de, -1) do |d|
32
- d.should <= ds
33
- d.should >= de
32
+ expect d <= ds
33
+ expect d >= de
34
34
  count += 1
35
35
  end
36
- count.should == 17
36
+ expect count == 17
37
37
 
38
38
  count = 0
39
39
  ds.step(de, -5) do |d|
40
- d.should <= ds
41
- d.should >= de
40
+ expect d <= ds
41
+ expect d >= de
42
42
  count += 1
43
43
  end
44
- count.should == 4
44
+ expect count == 4
45
45
 
46
46
  count = 0
47
47
  de.step(ds, -1) do |d|; count += 1; end
48
- count.should == 0
48
+ expect count == 0
49
49
  end
50
50
  end
@@ -1,108 +1,108 @@
1
1
  # encoding: utf-8
2
2
  describe "Parsi::Date#strftime" do
3
3
 
4
- it "should be able to print the date" do
5
- Parsi::Date.civil(1390, 4, 6).strftime.should == "1390/04/06"
4
+ it "is able to print the date" do
5
+ expect Parsi::Date.civil(1390, 4, 6).strftime == "1390/04/06"
6
6
  end
7
7
 
8
- it "should be able to print the full day name" do
9
- Parsi::Date.civil(1390, 4, 6).strftime("%A").should == "دوشنبه"
8
+ it "is able to print the full day name" do
9
+ expect Parsi::Date.civil(1390, 4, 6).strftime("%A") == "دوشنبه"
10
10
  end
11
11
 
12
- it "should be able to print the short day name" do
13
- Parsi::Date.civil(1390, 4, 6).strftime("%a").should == "۲ش"
12
+ it "is able to print the short day name" do
13
+ expect Parsi::Date.civil(1390, 4, 6).strftime("%a") == "۲ش"
14
14
  end
15
15
 
16
- it "should be able to print the full month name" do
17
- Parsi::Date.civil(1390, 4, 6).strftime("%B").should == "تیر"
18
- Parsi::Date.civil(1390, 4, 6).strftime("%EB").should == "tir"
19
- Parsi::Date.civil(1390, 4, 6).strftime("%^EB").should == "Tir"
16
+ it "is able to print the full month name" do
17
+ expect Parsi::Date.civil(1390, 4, 6).strftime("%B") == "تیر"
18
+ expect Parsi::Date.civil(1390, 4, 6).strftime("%EB") == "tir"
19
+ expect Parsi::Date.civil(1390, 4, 6).strftime("%^EB") == "Tir"
20
20
  end
21
21
 
22
- it "should be able to print the short month name" do
23
- Parsi::Date.civil(1390, 4, 6).strftime("%b").should == "tir"
24
- Parsi::Date.civil(1390, 4, 6).strftime("%h").should == "tir"
25
- Parsi::Date.civil(1390, 4, 6).strftime("%^b").should == "Tir"
26
- Parsi::Date.civil(1390, 4, 6).strftime("%^h").should == "Tir"
27
- Parsi::Date.civil(1390, 4, 6).strftime("%b").should == Parsi::Date.civil(1390, 4, 6).strftime("%h")
22
+ it "is able to print the short month name" do
23
+ expect Parsi::Date.civil(1390, 4, 6).strftime("%b") == "tir"
24
+ expect Parsi::Date.civil(1390, 4, 6).strftime("%h") == "tir"
25
+ expect Parsi::Date.civil(1390, 4, 6).strftime("%^b") == "Tir"
26
+ expect Parsi::Date.civil(1390, 4, 6).strftime("%^h") == "Tir"
27
+ expect Parsi::Date.civil(1390, 4, 6).strftime("%b") == Parsi::Date.civil(1390, 4, 6).strftime("%h")
28
28
  end
29
29
 
30
- it "should be able to print the century" do
31
- Parsi::Date.civil(1390, 4, 6).strftime("%C").should == "13"
30
+ it "is able to print the century" do
31
+ expect Parsi::Date.civil(1390, 4, 6).strftime("%C") == "13"
32
32
  end
33
33
 
34
- it "should be able to print the month day with leading zeroes" do
35
- Parsi::Date.civil(1390, 4, 6).strftime("%d").should == "06"
36
- Parsi::Date.civil(1390, 4, 16).strftime("%d").should == "16"
34
+ it "is able to print the month day with leading zeroes" do
35
+ expect Parsi::Date.civil(1390, 4, 6).strftime("%d") == "06"
36
+ expect Parsi::Date.civil(1390, 4, 16).strftime("%d") == "16"
37
37
  end
38
38
 
39
- it "should be able to print the month day with leading spaces and without em" do
40
- Parsi::Date.civil(1390, 4, 6).strftime("%-d").should == "6"
41
- Parsi::Date.civil(1390, 4, 6).strftime("%e").should == " 6"
42
- Parsi::Date.civil(1390, 4, 16).strftime("%e").should == "16"
39
+ it "is able to print the month day with leading spaces and without em" do
40
+ expect Parsi::Date.civil(1390, 4, 6).strftime("%-d") == "6"
41
+ expect Parsi::Date.civil(1390, 4, 6).strftime("%e") == " 6"
42
+ expect Parsi::Date.civil(1390, 4, 16).strftime("%e") == "16"
43
43
  end
44
44
 
45
- it "should be able to print the month with leading zeroes, spaces and none" do
46
- Parsi::Date.civil(1390, 4, 6).strftime("%m").should == "04"
47
- Parsi::Date.civil(1390, 11, 6).strftime("%m").should == "11"
48
- Parsi::Date.civil(1390, 4, 6).strftime("%_m").should == " 4"
49
- Parsi::Date.civil(1390, 11, 6).strftime("%_m").should == "11"
50
- Parsi::Date.civil(1390, 4, 6).strftime("%-m").should == "4"
51
- Parsi::Date.civil(1390, 11, 6).strftime("%-m").should == "11"
45
+ it "is able to print the month with leading zeroes, spaces and none" do
46
+ expect Parsi::Date.civil(1390, 4, 6).strftime("%m") == "04"
47
+ expect Parsi::Date.civil(1390, 11, 6).strftime("%m") == "11"
48
+ expect Parsi::Date.civil(1390, 4, 6).strftime("%_m") == " 4"
49
+ expect Parsi::Date.civil(1390, 11, 6).strftime("%_m") == "11"
50
+ expect Parsi::Date.civil(1390, 4, 6).strftime("%-m") == "4"
51
+ expect Parsi::Date.civil(1390, 11, 6).strftime("%-m") == "11"
52
52
  end
53
53
 
54
- it "should be able to add a newline" do
55
- Parsi::Date.civil(1390, 4, 6).strftime("%n").should == "\n"
54
+ it "is able to add a newline" do
55
+ expect Parsi::Date.civil(1390, 4, 6).strftime("%n") == "\n"
56
56
  end
57
57
 
58
- it "should be able to add a tab" do
59
- Parsi::Date.civil(1390, 4, 6).strftime("%t").should == "\t"
58
+ it "is able to add a tab" do
59
+ expect Parsi::Date.civil(1390, 4, 6).strftime("%t") == "\t"
60
60
  end
61
61
 
62
- it "should be able to show the week day" do
63
- Parsi::Date.civil(1390, 4, 11).strftime("%w").should == "6"
64
- Parsi::Date.civil(1390, 4, 12).strftime("%w").should == "0"
62
+ it "is able to show the week day" do
63
+ expect Parsi::Date.civil(1390, 4, 11).strftime("%w") == "6"
64
+ expect Parsi::Date.civil(1390, 4, 12).strftime("%w") == "0"
65
65
  end
66
66
 
67
- it "should be able to show the year in YYYY format" do
68
- Parsi::Date.civil(1390, 4, 9).strftime("%Y").should == "1390"
67
+ it "is able to show the year in YYYY format" do
68
+ expect Parsi::Date.civil(1390, 4, 9).strftime("%Y") == "1390"
69
69
  end
70
70
 
71
- it "should be able to show the year in YY format" do
72
- Parsi::Date.civil(1390, 4, 9).strftime("%y").should == "90"
71
+ it "is able to show the year in YY format" do
72
+ expect Parsi::Date.civil(1390, 4, 9).strftime("%y") == "90"
73
73
  end
74
74
 
75
- it "should be able to escape the % character" do
76
- Parsi::Date.civil(1390, 4, 9).strftime("%%").should == "%"
75
+ it "is able to escape the % character" do
76
+ expect Parsi::Date.civil(1390, 4, 9).strftime("%%") == "%"
77
77
  end
78
78
 
79
79
  ############################
80
80
  # Specs that combine stuff #
81
81
  ############################
82
82
 
83
- it "should be able to print the date in full" do
84
- Parsi::Date.civil(1390, 4, 6).strftime("%c").should == "۲ش 6 تیر 1390"
85
- Parsi::Date.civil(1390, 4, 6).strftime("%c").should == Parsi::Date.civil(1390, 4, 6).strftime('%a %-d %B %Y')
83
+ it "is able to print the date in full" do
84
+ expect Parsi::Date.civil(1390, 4, 6).strftime("%c") == "۲ش 6 تیر 1390"
85
+ expect Parsi::Date.civil(1390, 4, 6).strftime("%c") == Parsi::Date.civil(1390, 4, 6).strftime('%a %-d %B %Y')
86
86
  end
87
87
 
88
- it "should be able to print the date with slashes" do
89
- Parsi::Date.civil(1390, 4, 6).strftime("%D").should == "90/04/06"
90
- Parsi::Date.civil(1390, 4, 6).strftime("%D").should == Parsi::Date.civil(1390, 4, 6).strftime('%y/%m/%d')
88
+ it "is able to print the date with slashes" do
89
+ expect Parsi::Date.civil(1390, 4, 6).strftime("%D") == "90/04/06"
90
+ expect Parsi::Date.civil(1390, 4, 6).strftime("%D") == Parsi::Date.civil(1390, 4, 6).strftime('%y/%m/%d')
91
91
  end
92
92
 
93
- it "should be able to print the date as YYYY-MM-DD" do
94
- Parsi::Date.civil(1390, 4, 6).strftime("%F").should == "1390-04-06"
95
- Parsi::Date.civil(1390, 4, 6).strftime("%F").should == Parsi::Date.civil(1390, 4, 6).strftime('%Y-%m-%d')
93
+ it "is able to print the date as YYYY-MM-DD" do
94
+ expect Parsi::Date.civil(1390, 4, 6).strftime("%F") == "1390-04-06"
95
+ expect Parsi::Date.civil(1390, 4, 6).strftime("%F") == Parsi::Date.civil(1390, 4, 6).strftime('%Y-%m-%d')
96
96
  end
97
97
 
98
- it "should be able to show the commercial week" do
99
- Parsi::Date.civil(1390, 4, 9).strftime("%v").should == " 9-تیر-1390"
100
- Parsi::Date.civil(1390, 4, 9).strftime("%v").should == Parsi::Date.civil(1390, 4, 9).strftime('%e-%B-%Y')
98
+ it "is able to show the commercial week" do
99
+ expect Parsi::Date.civil(1390, 4, 9).strftime("%v") == " 9-تیر-1390"
100
+ expect Parsi::Date.civil(1390, 4, 9).strftime("%v") == Parsi::Date.civil(1390, 4, 9).strftime('%e-%B-%Y')
101
101
  end
102
102
 
103
- it "should be able to show YY/MM/DD" do
104
- Parsi::Date.civil(1390, 4, 6).strftime("%x").should == "90/04/06"
105
- Parsi::Date.civil(1390, 4, 6).strftime("%x").should == Parsi::Date.civil(1390, 4, 6).strftime('%y/%m/%d')
103
+ it "is able to show YY/MM/DD" do
104
+ expect Parsi::Date.civil(1390, 4, 6).strftime("%x") == "90/04/06"
105
+ expect Parsi::Date.civil(1390, 4, 6).strftime("%x") == Parsi::Date.civil(1390, 4, 6).strftime('%y/%m/%d')
106
106
  end
107
107
 
108
108
  end
@@ -1,17 +1,17 @@
1
1
  describe "Parsi::Date#cwday?" do
2
2
  it "returns the day of calendar week (1-7, Monday is 1)" do
3
- Parsi::Date.civil(1393, 12, 3).cwday.should == 7
4
- Parsi::Date.civil(1394, 1, 3).cwday.should == 1
3
+ expect Parsi::Date.civil(1393, 12, 3).cwday == 7
4
+ expect Parsi::Date.civil(1394, 1, 3).cwday == 1
5
5
  end
6
6
  end
7
7
 
8
8
  describe "Parsi::Date#cweek?" do
9
9
  it "returns the calendar week number (1-53)" do
10
- Parsi::Date.civil(1393, 11, 30).cweek.should == 48
11
- Parsi::Date.civil(1393, 12, 1).cweek.should == 48
12
- Parsi::Date.civil(1393, 12, 29).cweek.should == 52
13
- Parsi::Date.civil(1394, 1, 1).cweek.should == 1
14
- Parsi::Date.civil(1394, 1, 7).cweek.should == 1
15
- Parsi::Date.civil(1394, 1, 8).cweek.should == 2
10
+ expect Parsi::Date.civil(1393, 11, 30).cweek == 48
11
+ expect Parsi::Date.civil(1393, 12, 1).cweek == 48
12
+ expect Parsi::Date.civil(1393, 12, 29).cweek == 52
13
+ expect Parsi::Date.civil(1394, 1, 1).cweek == 1
14
+ expect Parsi::Date.civil(1394, 1, 7).cweek == 1
15
+ expect Parsi::Date.civil(1394, 1, 8).cweek == 2
16
16
  end
17
17
  end
data/spec/spec_helper.rb CHANGED
@@ -1,6 +1,5 @@
1
1
  require 'parsi-date'
2
2
 
3
3
  RSpec.configure do |config|
4
- config.treat_symbols_as_metadata_keys_with_true_values = true
5
4
  config.run_all_when_everything_filtered = true
6
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: parsi-date
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.1
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Hassan Zamani
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-03-05 00:00:00.000000000 Z
11
+ date: 2022-11-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -16,70 +16,70 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '1.4'
19
+ version: '2.0'
20
20
  type: :development
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: '1.4'
26
+ version: '2.0'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rake
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: '10.0'
33
+ version: '13.0'
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: '10.0'
40
+ version: '13.0'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: rspec
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
45
  - - "~>"
46
46
  - !ruby/object:Gem::Version
47
- version: '2.0'
47
+ version: '3.0'
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
- version: '2.0'
54
+ version: '3.0'
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: activerecord
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
59
  - - "~>"
60
60
  - !ruby/object:Gem::Version
61
- version: '4.2'
61
+ version: '6.0'
62
62
  type: :development
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
66
  - - "~>"
67
67
  - !ruby/object:Gem::Version
68
- version: '4.2'
68
+ version: '6.0'
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: sqlite3
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
73
  - - "~>"
74
74
  - !ruby/object:Gem::Version
75
- version: '1.3'
75
+ version: '1.5'
76
76
  type: :development
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
80
  - - "~>"
81
81
  - !ruby/object:Gem::Version
82
- version: '1.3'
82
+ version: '1.5'
83
83
  description: A Solar Hijri (Jalali) date library for Ruby, whitch provides much of
84
84
  Ruby's built-in date class
85
85
  email: hsn.zamani@gmail.com
@@ -87,13 +87,12 @@ executables: []
87
87
  extensions: []
88
88
  extra_rdoc_files: []
89
89
  files:
90
+ - ".github/workflows/ruby.yml"
90
91
  - ".gitignore"
91
92
  - ".rspec"
92
- - ".travis.yml"
93
93
  - Gemfile
94
94
  - MIT-LICENSE
95
95
  - README.rdoc
96
- - TODO
97
96
  - lib/parsi-date-accessors.rb
98
97
  - lib/parsi-date.rb
99
98
  - lib/parsi-datetime.rb
@@ -116,7 +115,7 @@ homepage: http://github.com/hzamani/parsi-date
116
115
  licenses:
117
116
  - MIT
118
117
  metadata: {}
119
- post_install_message:
118
+ post_install_message:
120
119
  rdoc_options: []
121
120
  require_paths:
122
121
  - lib
@@ -131,9 +130,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
131
130
  - !ruby/object:Gem::Version
132
131
  version: '0'
133
132
  requirements: []
134
- rubyforge_project:
135
- rubygems_version: 2.4.5
136
- signing_key:
133
+ rubygems_version: 3.3.11
134
+ signing_key:
137
135
  specification_version: 4
138
136
  summary: Solar Hijri (Jalali, Persian, Parsi) date library for Ruby
139
137
  test_files:
@@ -150,4 +148,3 @@ test_files:
150
148
  - spec/parsi-date/strftime_spec.rb
151
149
  - spec/parsi-date/week_methods_spec.rb
152
150
  - spec/spec_helper.rb
153
- has_rdoc:
data/.travis.yml DELETED
@@ -1,6 +0,0 @@
1
- language: ruby
2
- rvm:
3
- - 2.0.0
4
- - 1.9.3
5
- script:
6
- - bundle exec rspec spec/
data/TODO DELETED
@@ -1,13 +0,0 @@
1
- (A) Write rdocs
2
- (A) Fulfill specs
3
-
4
- Add change log
5
-
6
- Add activerecord helper: (maybe it's better to add somewhere else parsi-localize for example)
7
-
8
- class Product < ActiveRecord::Base
9
- # this must add :parsi_released_at accessors and sync with original attribute
10
- has_parsi_date_for :released_at
11
-
12
- # can have an optional name
13
- has_parsi_date_for :lifecycel_ended_at, as: 'end_of_life'