parsi-date 0.3.1 → 0.5.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.github/workflows/ruby.yml +26 -0
- data/README.md +94 -0
- data/lib/parsi-date.rb +38 -31
- data/lib/version.rb +1 -1
- data/parsi-date.gemspec +6 -5
- data/spec/parsi-date/accessor_spec.rb +23 -14
- data/spec/parsi-date/accessors_helper_spec.rb +3 -2
- data/spec/parsi-date/add_month_spec.rb +8 -8
- data/spec/parsi-date/add_spec.rb +8 -8
- data/spec/parsi-date/comp_spec.rb +9 -9
- data/spec/parsi-date/constants_spec.rb +16 -12
- data/spec/parsi-date/construction_spec.rb +14 -13
- data/spec/parsi-date/conversion_spec.rb +20 -9
- data/spec/parsi-date/leap_spec.rb +8 -6
- data/spec/parsi-date/step_spec.rb +14 -14
- data/spec/parsi-date/strftime_spec.rb +60 -60
- data/spec/parsi-date/week_methods_spec.rb +8 -8
- data/spec/spec_helper.rb +0 -1
- metadata +32 -21
- data/.travis.yml +0 -6
- data/README.rdoc +0 -31
- data/TODO +0 -13
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 3ba469a494b1e1aae0d7c2c7f588da147cc467248ddbe734f435e3fab64d4171
|
4
|
+
data.tar.gz: 56e054bb3539f9e52ceb0ed6f766d9b058ee2a0457b61ba78593e5ce12232193
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2584be47bf36f9946259cf0e8d8954c4ab9132ae05986509f70655fc57900f9e5bbb43eefc0186a93992a0a1990c9fb99b8f06639558f78f3e88c9ed1330bbc9
|
7
|
+
data.tar.gz: dc6fc42431960c45147036b6dc86ae3097ac9dbfb27e5d96be312d5048c71f3d6b3ebd26c41501d1f028bb56075b853e2646adb638338716fc3f9aa35aabc6bf
|
@@ -0,0 +1,26 @@
|
|
1
|
+
name: Ruby
|
2
|
+
|
3
|
+
on: [push, pull_request]
|
4
|
+
|
5
|
+
permissions:
|
6
|
+
contents: read
|
7
|
+
|
8
|
+
jobs:
|
9
|
+
test:
|
10
|
+
runs-on: ubuntu-latest
|
11
|
+
strategy:
|
12
|
+
matrix:
|
13
|
+
ruby-version:
|
14
|
+
- '3.1'
|
15
|
+
- '3.2'
|
16
|
+
- '3.3'
|
17
|
+
|
18
|
+
steps:
|
19
|
+
- uses: actions/checkout@v4
|
20
|
+
- name: Set up Ruby
|
21
|
+
uses: ruby/setup-ruby@v1
|
22
|
+
with:
|
23
|
+
ruby-version: ${{ matrix.ruby-version }}
|
24
|
+
bundler-cache: true
|
25
|
+
- name: Run tests
|
26
|
+
run: bundle exec rspec spec
|
data/README.md
ADDED
@@ -0,0 +1,94 @@
|
|
1
|
+
# Parsi Date
|
2
|
+
|
3
|
+
The Parsi Date library is an implementation of the [Solar Hijri Calendar](http://en.wikipedia.org/wiki/Solar_Hijri_calendar), also known as the Jalali or Persian Calendar, which is the official calendar of Iran. This library aims to create a Solar Hijri date library that closely resembles Ruby's built-in date library, providing a seamless experience for users who need to work with the Solar Hijri dates. The conversion algorithm used in this library is inspired by FarsiWeb.
|
4
|
+
|
5
|
+
## Features
|
6
|
+
|
7
|
+
- **Parsi::Date** and **Parsi::DateTime**: These objects can be used just like Ruby's `Date` and `DateTime` objects.
|
8
|
+
- **Date Conversion:** Easily convert between Gregorian and Solar Hijri dates.
|
9
|
+
- **Leap Year Calculation:** Determine if a given Solar Hijri year is a leap year.
|
10
|
+
- **Date Parsing and Formatting:** Parse Solar Hijri date strings and format dates in various styles.
|
11
|
+
|
12
|
+
## Usage
|
13
|
+
|
14
|
+
### Basic Operations
|
15
|
+
|
16
|
+
You can use `Parsi::Date` and `Parsi::DateTime` objects in the same way you use `Date` and `DateTime` objects in Ruby. Here are some examples:
|
17
|
+
|
18
|
+
```ruby
|
19
|
+
# Get today's Solar Hijri date
|
20
|
+
a = Parsi::Date.today
|
21
|
+
# => #<Parsi::Date: 1391-08-09 (4912461/2,0/1)>
|
22
|
+
|
23
|
+
# Add 12 months to it
|
24
|
+
b = a >> 12
|
25
|
+
# => #<Parsi::Date: 1392-08-09 (4913193/2,0/1)>
|
26
|
+
|
27
|
+
# Count the number of Sundays between two dates
|
28
|
+
a.upto(b).select{ |d| d.sunday? }.count
|
29
|
+
# => 52
|
30
|
+
|
31
|
+
# Check if a given year is a leap year
|
32
|
+
Parsi::Date.leap?(1391)
|
33
|
+
# => true
|
34
|
+
```
|
35
|
+
|
36
|
+
### Parsing and Formatting Dates
|
37
|
+
|
38
|
+
You can parse Solar Hijri date strings and format them in various styles:
|
39
|
+
|
40
|
+
```ruby
|
41
|
+
# Parse a Solar Hijri date string
|
42
|
+
c = Parsi::Date.parse("1391/10/12")
|
43
|
+
# => #<Parsi::Date: 1391-10-12 (4912587/2,0)>
|
44
|
+
|
45
|
+
# Format the date in Persian
|
46
|
+
c.strftime("%A %d %B %Y")
|
47
|
+
# => "سهشنبه 12 دی 1391"
|
48
|
+
|
49
|
+
# Format the date in English
|
50
|
+
c.strftime("%^EA %d %^EB %Y")
|
51
|
+
# => "Seshambe 12 Day 1391"
|
52
|
+
```
|
53
|
+
|
54
|
+
### Converting Between Calendars
|
55
|
+
|
56
|
+
You can easily convert between Gregorian and Solar Hijri dates:
|
57
|
+
|
58
|
+
```ruby
|
59
|
+
# Convert a Gregorian date to Solar Hijri
|
60
|
+
d = Date.civil(2012, 10, 30).to_parsi
|
61
|
+
# => #<Parsi::Date: 1391-08-09 (4912461/2,0/1)>
|
62
|
+
|
63
|
+
# Convert a Solar Hijri date back to Gregorian
|
64
|
+
d.to_gregorian
|
65
|
+
# => #<Date: 2012-10-30 ((2456231j,0s,0n),+0s,2299161j)>
|
66
|
+
```
|
67
|
+
|
68
|
+
## Installation
|
69
|
+
|
70
|
+
Add this line to your application's Gemfile:
|
71
|
+
|
72
|
+
```ruby
|
73
|
+
gem 'parsi-date'
|
74
|
+
```
|
75
|
+
|
76
|
+
And then execute:
|
77
|
+
|
78
|
+
```sh
|
79
|
+
bundle install
|
80
|
+
```
|
81
|
+
|
82
|
+
Or install it yourself as:
|
83
|
+
|
84
|
+
```sh
|
85
|
+
gem install parsi-date
|
86
|
+
```
|
87
|
+
|
88
|
+
## License
|
89
|
+
|
90
|
+
The Parsi Date library is open-source software licensed under the MIT license.
|
91
|
+
|
92
|
+
## Contributing
|
93
|
+
|
94
|
+
If you would like to contribute to the development of the Parsi Date library, please feel free to fork the repository and submit pull requests. Contributions, bug reports, and feature requests are welcome and appreciated.
|
data/lib/parsi-date.rb
CHANGED
@@ -135,61 +135,68 @@ module Parsi
|
|
135
135
|
JALALI_EPOCH_IN_AJD = Rational(3896641, 2) # :nodoc:
|
136
136
|
MJD_EPOCH_IN_AJD = Rational(4800001, 2) # 1858-11-17 # :nodoc:
|
137
137
|
UNIX_EPOCH_IN_AJD = Rational(4881175, 2) # 1970-01-01 # :nodoc:
|
138
|
-
JALALI_EPOCH_IN_CJD =
|
138
|
+
JALALI_EPOCH_IN_CJD = 1948320 # :nodoc:
|
139
139
|
MJD_EPOCH_IN_CJD = 2400001 # :nodoc:
|
140
140
|
UNIX_EPOCH_IN_CJD = 2440588 # :nodoc:
|
141
141
|
LD_EPOCH_IN_CJD = 2299160 # :nodoc:
|
142
|
-
DAYS_IN_MONTH = [
|
142
|
+
DAYS_IN_MONTH = [0, 31, 31, 31, 31, 31, 31, 30, 30, 30, 30, 30, 29] # :nodoc:
|
143
|
+
|
144
|
+
LEAP_REMINDERS = [1, 5, 9, 13, 17, 22, 26, 30].freeze
|
143
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
|
-
(
|
150
|
+
LEAP_REMINDERS.include?(year - (year / 33).floor * 33)
|
149
151
|
end
|
150
152
|
alias_method :jalali_leap?, :leap?
|
151
153
|
|
152
154
|
private
|
153
155
|
|
154
|
-
DAYS_TO_FIRST_OF_MONTH = [nil, 0, 31, 62, 93, 124, 155, 186, 216, 246, 276, 306, 336] # :nodoc:
|
155
|
-
|
156
156
|
# Convert a Civil Date to a Julian Day Number and returns the corresponding Julian Day Number.
|
157
|
-
def civil_to_jd
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
157
|
+
def civil_to_jd(year, month, day) # :nodoc:
|
158
|
+
year -= 1
|
159
|
+
month -= 1
|
160
|
+
day -= 1
|
161
|
+
|
162
|
+
jd = 365*year + (year/33)*8 + (year%33+3)/4;
|
163
|
+
while month > 0
|
164
|
+
jd += DAYS_IN_MONTH[month]
|
165
|
+
month -= 1
|
166
|
+
end
|
167
|
+
|
168
|
+
jd + day + JALALI_EPOCH_IN_CJD
|
166
169
|
end
|
167
170
|
|
168
171
|
# Convert a Julian Day Number to a Civil Date. +jday+ is the Julian Day Number.
|
169
172
|
#
|
170
173
|
# Returns the corresponding [year, month, day_of_month] as a three-element array.
|
171
|
-
def jd_to_civil
|
172
|
-
|
173
|
-
cycle, cyear = depoch.divmod 1029983
|
174
|
+
def jd_to_civil jd
|
175
|
+
jd -= JALALI_EPOCH_IN_CJD
|
174
176
|
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
177
|
+
n, jd = jd.divmod 12053
|
178
|
+
m, jd = jd.divmod 1461
|
179
|
+
year = 33*n + 4*m + 1
|
180
|
+
|
181
|
+
if jd >= 366
|
182
|
+
n, jd = (jd - 1).divmod 365
|
183
|
+
year += n
|
184
|
+
end
|
185
|
+
|
186
|
+
month = 1
|
187
|
+
while month < 12 && jd >= DAYS_IN_MONTH[month]
|
188
|
+
jd -= DAYS_IN_MONTH[month]
|
189
|
+
month += 1
|
180
190
|
end
|
181
|
-
|
182
|
-
|
183
|
-
month = ((yday <= 186) ? yday / 31.0 : (yday - 6) / 30.0).ceil
|
184
|
-
day = (jday - first_day_of_month(year, month) + 1)
|
185
|
-
[year, month, day]
|
191
|
+
|
192
|
+
[year, month, jd + 1]
|
186
193
|
end
|
187
194
|
|
188
195
|
# Do +year+, +month+, and day-of-month +day+ make a valid Civil Date?
|
189
196
|
# Returns the corresponding Julian Day Number if they do, nil if they don't.
|
190
197
|
# Invalid values cause an ArgumentError to be raised.
|
191
198
|
def _valid_civil? year, month, day # :nodoc:
|
192
|
-
return unless year.is_a?(
|
199
|
+
return unless year.is_a?(Integer) && month.is_a?(Integer) && day.is_a?(Integer)
|
193
200
|
return civil_to_jd(year, 12, 30) if leap?(year) && month == 12 && day == 30
|
194
201
|
|
195
202
|
if 1 <= month && month <= 12 && 1 <= day && day <= DAYS_IN_MONTH[month]
|
@@ -330,7 +337,6 @@ module Parsi
|
|
330
337
|
# Parsi::Date.jd # => #<Parsi::Date: -5335-09-01>
|
331
338
|
#
|
332
339
|
def jd jday=0
|
333
|
-
jd = _valid_jd? jday
|
334
340
|
new! jd_to_ajd(jday, 0, 0), 0
|
335
341
|
end
|
336
342
|
|
@@ -731,7 +737,7 @@ module Parsi
|
|
731
737
|
def marshal_dump() [@ajd, @offset] end
|
732
738
|
|
733
739
|
# Load from Marshal format.
|
734
|
-
def marshal_load(a) @ajd, @
|
740
|
+
def marshal_load(a) @ajd, @offset, = a end
|
735
741
|
end
|
736
742
|
end
|
737
743
|
|
@@ -747,8 +753,9 @@ class Date
|
|
747
753
|
|
748
754
|
# Returns a Parsi::Date object representing same date in Jalali calendar
|
749
755
|
def to_parsi
|
750
|
-
Parsi::Date.new! ajd
|
756
|
+
Parsi::Date.new! ajd
|
751
757
|
end
|
758
|
+
|
752
759
|
alias :jalali :to_parsi
|
753
760
|
alias :to_jalali :to_parsi
|
754
761
|
alias :to_persian :to_parsi
|
data/lib/version.rb
CHANGED
data/parsi-date.gemspec
CHANGED
@@ -18,9 +18,10 @@ 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", "~>
|
22
|
-
s.add_development_dependency("
|
23
|
-
s.add_development_dependency("
|
24
|
-
s.add_development_dependency("
|
25
|
-
s.add_development_dependency("
|
21
|
+
s.add_development_dependency("bundler", "~> 2.0")
|
22
|
+
s.add_development_dependency("json", "~> 2.0")
|
23
|
+
s.add_development_dependency("rake", "~> 13.0")
|
24
|
+
s.add_development_dependency("rspec", "~> 3.0")
|
25
|
+
s.add_development_dependency("activerecord", "~> 6.0")
|
26
|
+
s.add_development_dependency("sqlite3", "~> 1.5")
|
26
27
|
end
|
@@ -1,57 +1,66 @@
|
|
1
1
|
describe "Parsi::Date#ajd" do
|
2
2
|
it "determines the Astronomical Julian day" do
|
3
|
-
Parsi::Date.civil(1391, 8, 6).ajd.
|
3
|
+
expect(Parsi::Date.civil(1391, 8, 6).ajd).to be == Rational(4912455, 2)
|
4
|
+
expect(Parsi::Date.civil(1403, 12, 30).ajd).to be == Rational(4921509, 2)
|
4
5
|
end
|
5
6
|
end
|
6
7
|
|
7
8
|
describe "Parsi::Date#amjd" do
|
8
9
|
it "determines the Astronomical Modified Julian day" do
|
9
|
-
Parsi::Date.civil(1391, 8, 6).amjd.
|
10
|
+
expect(Parsi::Date.civil(1391, 8, 6).amjd).to be == 56227
|
11
|
+
expect(Parsi::Date.civil(1403, 12, 30).amjd).to be == 60754
|
10
12
|
end
|
11
13
|
end
|
12
14
|
|
13
15
|
describe "Parsi::Date#mjd" do
|
14
16
|
it "determines the Modified Julian day" do
|
15
|
-
Parsi::Date.civil(1391, 8, 6).mjd.
|
17
|
+
expect(Parsi::Date.civil(1391, 8, 6).mjd).to be == 56227
|
18
|
+
expect(Parsi::Date.civil(1403, 12, 30).mjd).to be == 60754
|
16
19
|
end
|
17
20
|
end
|
18
21
|
|
19
22
|
describe "Parsi::Date#ld" do
|
20
|
-
it "determines the
|
21
|
-
Parsi::Date.civil(1391, 8, 6).ld.
|
23
|
+
it "determines the number of days since the Day of Calendar Reform" do
|
24
|
+
expect(Parsi::Date.civil(1391, 8, 6).ld).to be == 157068
|
25
|
+
expect(Parsi::Date.civil(1403, 12, 30).ld).to be == 161595
|
22
26
|
end
|
23
27
|
end
|
24
28
|
|
25
29
|
describe "Parsi::Date#year" do
|
26
30
|
it "determines the year" do
|
27
|
-
Parsi::Date.civil(1391, 8, 6).year.
|
31
|
+
expect(Parsi::Date.civil(1391, 8, 6).year).to be == 1391
|
32
|
+
expect(Parsi::Date.civil(1403, 12, 30).year).to be == 1403
|
28
33
|
end
|
29
34
|
end
|
30
35
|
|
31
36
|
describe "Parsi::Date#yday" do
|
32
37
|
it "determines the year" do
|
33
|
-
Parsi::Date.civil(1391, 1, 17).yday.
|
34
|
-
Parsi::Date.civil(1391, 8, 6).yday.
|
38
|
+
expect(Parsi::Date.civil(1391, 1, 17).yday).to be == 17
|
39
|
+
expect(Parsi::Date.civil(1391, 8, 6).yday).to be == 222
|
40
|
+
expect(Parsi::Date.civil(1403, 12, 30).yday).to be == 366
|
35
41
|
end
|
36
42
|
end
|
37
43
|
|
38
44
|
describe "Parsi::Date#mon" do
|
39
45
|
it "determines the month" do
|
40
|
-
Parsi::Date.civil(1391, 1, 17).mon.
|
41
|
-
Parsi::Date.civil(1391, 8, 6).mon.
|
46
|
+
expect(Parsi::Date.civil(1391, 1, 17).mon).to be == 1
|
47
|
+
expect(Parsi::Date.civil(1391, 8, 6).mon).to be == 8
|
48
|
+
expect(Parsi::Date.civil(1403, 12, 30).mon).to be == 12
|
42
49
|
end
|
43
50
|
end
|
44
51
|
|
45
52
|
describe "Parsi::Date#mday" do
|
46
53
|
it "determines the day of the month" do
|
47
|
-
Parsi::Date.civil(1391, 1, 17).mday.
|
48
|
-
Parsi::Date.civil(1391, 10, 28).mday.
|
54
|
+
expect(Parsi::Date.civil(1391, 1, 17).mday).to be == 17
|
55
|
+
expect(Parsi::Date.civil(1391, 10, 28).mday).to be == 28
|
56
|
+
expect(Parsi::Date.civil(1403, 12, 30).mday).to be == 30
|
49
57
|
end
|
50
58
|
end
|
51
59
|
|
52
60
|
describe "Parsi::Date#wday" do
|
53
61
|
it "determines the week day" do
|
54
|
-
Parsi::Date.civil(1391, 1, 17).wday.
|
55
|
-
Parsi::Date.civil(1391, 8, 6).wday.
|
62
|
+
expect(Parsi::Date.civil(1391, 1, 17).wday).to be == 4
|
63
|
+
expect(Parsi::Date.civil(1391, 8, 6).wday).to be == 6
|
64
|
+
expect(Parsi::Date.civil(1403, 12, 30).wday).to be == 4
|
56
65
|
end
|
57
66
|
end
|
@@ -1,5 +1,6 @@
|
|
1
1
|
require 'active_record'
|
2
2
|
require 'sqlite3'
|
3
|
+
require 'json'
|
3
4
|
|
4
5
|
ActiveRecord::Base.establish_connection(adapter: "sqlite3", database: ":memory:")
|
5
6
|
|
@@ -24,7 +25,7 @@ end
|
|
24
25
|
describe "Record extended with Parsi::Date::Accessors" do
|
25
26
|
it "has parsi postfixed accessor for giver attributes" do
|
26
27
|
record = Record.new
|
27
|
-
|
28
|
+
[:created_at_parsi, :created_at_parsi=, :updated_at_parsi, :updated_at_parsi].each do |name|
|
28
29
|
expect(record.respond_to?(name)).to be_truthy
|
29
30
|
end
|
30
31
|
end
|
@@ -55,7 +56,7 @@ describe "Record extended with Parsi::Date::Accessors" do
|
|
55
56
|
|
56
57
|
it "raises error when string is not a date" do
|
57
58
|
record = Record.new
|
58
|
-
expect {record.created_at_parsi = "1393-13-11" }.to raise_error
|
59
|
+
expect {record.created_at_parsi = "1393-13-11" }.to raise_error(ArgumentError, 'invalid date')
|
59
60
|
end
|
60
61
|
end
|
61
62
|
end
|
@@ -1,27 +1,27 @@
|
|
1
1
|
describe "Parsi::Date#>>" do
|
2
2
|
it "adds the number of months to a Parsi::Date" do
|
3
|
-
|
4
|
-
|
3
|
+
expect(Parsi::Date.civil(1391, 2, 27) >> 10).to be == Parsi::Date.civil(1391, 12, 27)
|
4
|
+
expect(Parsi::Date.civil(1403, 11, 30) >> 1).to be == Parsi::Date.civil(1403, 12, 30)
|
5
5
|
end
|
6
6
|
|
7
7
|
it "sets the day to the last day of a month if the day doesn't exist" do
|
8
|
-
|
9
|
-
|
8
|
+
expect(Parsi::Date.civil(1391, 6, 31) >> 1).to be == Parsi::Date.civil(1391, 7, 30)
|
9
|
+
expect(Parsi::Date.civil(1402, 11, 30) >> 1).to be == Parsi::Date.civil(1402, 12, 29)
|
10
10
|
end
|
11
11
|
|
12
12
|
it "raise a TypeError when passed a Symbol" do
|
13
|
-
|
13
|
+
expect { Parsi::Date.civil(1391, 2, 27) >> :hello }.to raise_error(TypeError)
|
14
14
|
end
|
15
15
|
|
16
16
|
it "raise a TypeError when passed a String" do
|
17
|
-
|
17
|
+
expect { Parsi::Date.civil(1391, 2, 27) >> "hello" }.to raise_error(TypeError)
|
18
18
|
end
|
19
19
|
|
20
20
|
it "raise a TypeError when passed a Parsi::Date" do
|
21
|
-
|
21
|
+
expect { Parsi::Date.civil(1391, 2, 27) >> Parsi::Date.new }.to raise_error(TypeError)
|
22
22
|
end
|
23
23
|
|
24
24
|
it "raise a TypeError when passed an Object" do
|
25
|
-
|
25
|
+
expect { Parsi::Date.civil(1391, 2, 27) >> Object.new }.to raise_error(TypeError)
|
26
26
|
end
|
27
27
|
end
|
data/spec/parsi-date/add_spec.rb
CHANGED
@@ -1,27 +1,27 @@
|
|
1
1
|
describe "Parsi::Date#+" do
|
2
2
|
it "adds the number of days to a Parsi::Date" do
|
3
|
-
|
4
|
-
|
3
|
+
expect(Parsi::Date.civil(1391, 2, 27) + 10).to be == Parsi::Date.civil(1391, 3, 6)
|
4
|
+
expect(Parsi::Date.civil(1403, 12, 29) + 1).to be == Parsi::Date.civil(1403, 12, 30)
|
5
|
+
expect(Parsi::Date.civil(1403, 12, 30) + 1).to be == Parsi::Date.civil(1404, 1, 1)
|
5
6
|
end
|
6
7
|
|
7
8
|
it "adds a negative number of days to a Parsi::Date" do
|
8
|
-
|
9
|
-
d.should == Parsi::Date.civil(1391, 2, 17)
|
9
|
+
expect(Parsi::Date.civil(1391, 2, 27) + (-10)).to be == Parsi::Date.civil(1391, 2, 17)
|
10
10
|
end
|
11
11
|
|
12
12
|
it "raises a TypeError when passed a Symbol" do
|
13
|
-
|
13
|
+
expect { Parsi::Date.civil(1391, 2, 27) + :hello }.to raise_error(TypeError)
|
14
14
|
end
|
15
15
|
|
16
16
|
it "raises a TypeError when passed a String" do
|
17
|
-
|
17
|
+
expect { Parsi::Date.civil(1391, 2, 27) + "hello" }.to raise_error(TypeError)
|
18
18
|
end
|
19
19
|
|
20
20
|
it "raises a TypeError when passed a Parsi::Date" do
|
21
|
-
|
21
|
+
expect { Parsi::Date.civil(1391, 2, 27) + Parsi::Date.new }.to raise_error(TypeError)
|
22
22
|
end
|
23
23
|
|
24
24
|
it "raises a TypeError when passed an Object" do
|
25
|
-
|
25
|
+
expect { Parsi::Date.civil(1391, 2, 27) + Object.new }.to raise_error(TypeError)
|
26
26
|
end
|
27
27
|
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)).
|
6
|
-
(Parsi::Date.civil(1391, 4, 6) <=> Date.civil(2012, 6, 26)).
|
5
|
+
expect(Parsi::Date.civil(1391, 4, 6) <=> Parsi::Date.civil(1391, 4, 6)).to be == 0
|
6
|
+
expect(Parsi::Date.civil(1391, 4, 6) <=> Date.civil(2012, 6, 26)).to be == 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)).
|
11
|
-
(Parsi::Date.civil(1391, 4, 5) <=> Date.civil(2012, 6, 26)).
|
10
|
+
expect(Parsi::Date.civil(1391, 4, 5) <=> Parsi::Date.civil(1391, 4, 6)).to be == -1
|
11
|
+
expect(Parsi::Date.civil(1391, 4, 5) <=> Date.civil(2012, 6, 26)).to be == -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)).
|
16
|
-
(Parsi::Date.civil(1391, 4, 7) <=> Date.civil(2012, 6, 26)).
|
15
|
+
expect(Parsi::Date.civil(1392, 4, 7) <=> Parsi::Date.civil(1391, 4, 6)).to be == 1
|
16
|
+
expect(Parsi::Date.civil(1391, 4, 7) <=> Date.civil(2012, 6, 26)).to be == 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)).
|
20
|
+
expect(Parsi::Date.civil(1391, 4, 6) <=> Rational(4912209,2)).to be == 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)).
|
24
|
+
expect(Parsi::Date.civil(1391, 4, 6) <=> Rational(4912210,2)).to be == -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)).
|
28
|
+
expect(Parsi::Date.civil(1391, 4, 6) <=> Rational(4912208,2)).to be == 1
|
29
29
|
end
|
30
30
|
end
|
@@ -1,41 +1,45 @@
|
|
1
1
|
# encoding: utf-8
|
2
2
|
describe "Date constants" do
|
3
3
|
it "defines MONTHNAMES" do
|
4
|
-
Parsi::Date::MONTHNAMES.
|
5
|
-
%w(فروردین اردیبهشت خرداد تیر مرداد شهریور مهر آبان آذر دی بهمن اسفند)
|
4
|
+
expect(Parsi::Date::MONTHNAMES).to be ==
|
5
|
+
[nil] + %w(فروردین اردیبهشت خرداد تیر مرداد شهریور مهر آبان آذر دی بهمن اسفند)
|
6
6
|
end
|
7
7
|
|
8
8
|
it "defines EN_MONTHNAMES" do
|
9
|
-
Parsi::Date::EN_MONTHNAMES.
|
10
|
-
%w(farvardin ordibehesht khordad tir mordad shahrivar mehr aban azar day bahman esfand)
|
9
|
+
expect(Parsi::Date::EN_MONTHNAMES).to be ==
|
10
|
+
[nil] + %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.
|
15
|
-
%w(far ord kho tir mor sha meh abn azr day bah esf)
|
14
|
+
expect(Parsi::Date::ABBR_MONTHNAMES).to be ==
|
15
|
+
[nil] + %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.
|
19
|
+
expect(Parsi::Date::DAYNAMES).to be ==
|
20
|
+
%w(یکشنبه دوشنبه سهشنبه چهارشنبه پنجشنبه جمعه شنبه)
|
20
21
|
end
|
21
22
|
|
22
23
|
it "defines EN_DAYNAMES" do
|
23
|
-
Parsi::Date::EN_DAYNAMES.
|
24
|
+
expect(Parsi::Date::EN_DAYNAMES).to be ==
|
25
|
+
%w(yekshanbe doshanbe seshanbe chaharshanbe panjshanbe jomee shanbe)
|
24
26
|
end
|
25
27
|
|
26
28
|
it "defines ABBR_DAYNAMES" do
|
27
|
-
Parsi::Date::ABBR_DAYNAMES.
|
29
|
+
expect(Parsi::Date::ABBR_DAYNAMES).to be ==
|
30
|
+
%w(۱ش ۲ش ۳ش ۴ش ۵ش ج ش)
|
28
31
|
end
|
29
32
|
|
30
33
|
it "defines ABBR_EN_DAYNAMES" do
|
31
|
-
Parsi::Date::ABBR_EN_DAYNAMES.
|
34
|
+
expect(Parsi::Date::ABBR_EN_DAYNAMES).to be ==
|
35
|
+
%w(ye do se ch pj jo sh)
|
32
36
|
end
|
33
37
|
|
34
38
|
it "freezes MONTHNAMES, DAYNAMES, EN_DAYNAMES, ABBR_MONTHNAMES, ABBR_DAYSNAMES" do
|
35
39
|
[Parsi::Date::MONTHNAMES, Parsi::Date::EN_MONTHNAMES, Parsi::Date::ABBR_MONTHNAMES,
|
36
40
|
Parsi::Date::DAYNAMES, Parsi::Date::EN_DAYNAMES,
|
37
|
-
Parsi::Date::ABBR_DAYNAMES, Parsi::Date::ABBR_EN_DAYNAMES].each do |
|
38
|
-
|
41
|
+
Parsi::Date::ABBR_DAYNAMES, Parsi::Date::ABBR_EN_DAYNAMES].each do |array|
|
42
|
+
expect(array).to be_frozen
|
39
43
|
end
|
40
44
|
end
|
41
45
|
end
|
@@ -21,38 +21,39 @@ 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.
|
25
|
-
date.month.
|
26
|
-
date.day.
|
24
|
+
expect(date.year ).to be == 1
|
25
|
+
expect(date.month).to be == 1
|
26
|
+
expect(date.day ).to be == 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).
|
33
|
-
Parsi::Date.ordinal(1390,7).
|
34
|
-
Parsi::Date.ordinal(1390,100).
|
32
|
+
expect(Parsi::Date.ordinal(1390) ).to be == Parsi::Date.civil(1390, 1, 1)
|
33
|
+
expect(Parsi::Date.ordinal(1390, 7) ).to be == Parsi::Date.civil(1390, 1, 7)
|
34
|
+
expect(Parsi::Date.ordinal(1390, 100)).to be == Parsi::Date.civil(1390, 4, 7)
|
35
|
+
expect(Parsi::Date.ordinal(1403, 366)).to be == Parsi::Date.civil(1403, 12, 30)
|
35
36
|
end
|
36
37
|
end
|
37
38
|
|
38
39
|
context "parse" do
|
39
|
-
it "
|
40
|
+
it "parses date from strings" do
|
40
41
|
['1391/8/6', '1391-8-6', '1391 8 6', '1391 8 6', '13910806'].each do |date_string|
|
41
42
|
date = Parsi::Date.parse date_string
|
42
|
-
[date.year, date.month, date.day].
|
43
|
+
expect([date.year, date.month, date.day]).to be == [1391, 8, 6]
|
43
44
|
end
|
44
45
|
end
|
45
46
|
|
46
47
|
it "completes century when second arg is true" do
|
47
|
-
Date.
|
48
|
+
allow(Date).to receive(:today) { Date.new 2012, 10, 26 }
|
48
49
|
date = Parsi::Date.parse '91/8/5', true
|
49
|
-
[date.year, date.month, date.day].
|
50
|
+
expect([date.year, date.month, date.day]).to be == [1391, 8, 5]
|
50
51
|
end
|
51
52
|
|
52
|
-
it "
|
53
|
-
expect { date = Parsi::Date.parse '1390/12/30'
|
53
|
+
it "raises ArgumentError on invalid date string" do
|
54
|
+
expect { date = Parsi::Date.parse '1390/12/30' }.to raise_error(ArgumentError)
|
54
55
|
expect { date = Parsi::Date.parse 'bad date string' }.to raise_error(ArgumentError)
|
55
|
-
expect { date = Parsi::Date.parse '12-30-1390'
|
56
|
+
expect { date = Parsi::Date.parse '12-30-1390' }.to raise_error(ArgumentError)
|
56
57
|
end
|
57
58
|
end
|
58
59
|
end
|
@@ -1,36 +1,47 @@
|
|
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).
|
4
|
-
Parsi::Date.jd(2456229).
|
3
|
+
expect(Parsi::Date.jd(2456228)).to be == Parsi::Date.civil(1391, 8, 6)
|
4
|
+
expect(Parsi::Date.jd(2456229)).to be == Parsi::Date.civil(1391, 8, 7)
|
5
|
+
expect(Parsi::Date.jd(2456229)).to be == Parsi::Date.civil(1391, 8, 7)
|
6
|
+
expect(Parsi::Date.jd(2460755)).to be == Parsi::Date.civil(1403, 12, 30)
|
7
|
+
expect(Parsi::Date.jd(2460756)).to be == Parsi::Date.civil(1404, 1, 1)
|
5
8
|
end
|
6
9
|
|
7
10
|
it "returns a Date object representing Julian day 0 if no arguments passed"do
|
8
|
-
Parsi::Date.jd.
|
11
|
+
expect(Parsi::Date.jd).to be == Parsi::Date.civil(-5334, 9, 3)
|
9
12
|
end
|
10
13
|
|
11
14
|
it "constructs a Date object if passed a negative number" do
|
12
|
-
Parsi::Date.jd(-1).
|
15
|
+
expect(Parsi::Date.jd(-1)).to be == Parsi::Date.civil(-5334, 9, 2)
|
13
16
|
end
|
14
17
|
end
|
15
18
|
|
16
19
|
describe "Parsi::Date#jd" do
|
17
20
|
it "determines the Julian day for a Date object" do
|
18
|
-
Parsi::Date.civil(1391, 8, 7).jd.
|
21
|
+
expect(Parsi::Date.civil(1391, 8, 7).jd ).to be == 2456229
|
22
|
+
expect(Parsi::Date.civil(1403, 12, 30).jd).to be == 2460755
|
23
|
+
expect(Parsi::Date.civil(1404, 1, 1).jd ).to be == 2460756
|
19
24
|
end
|
20
25
|
end
|
21
26
|
|
22
27
|
describe "Parsi::Date#to_gregorian" do
|
23
28
|
it "converts date to Gregorian date" do
|
24
29
|
date = Parsi::Date.civil(1391, 8, 7).to_gregorian
|
25
|
-
date.
|
26
|
-
date.
|
30
|
+
expect(date).to be_a(Date)
|
31
|
+
expect(date).to be == Date.civil(2012, 10, 28)
|
32
|
+
|
33
|
+
expect(Parsi::Date.civil(1366, 11, 14).to_gregorian).to be == Date.civil(1988, 2, 3)
|
34
|
+
expect(Parsi::Date.civil(1403, 12, 30).to_gregorian).to be == Date.civil(2025, 3, 20)
|
27
35
|
end
|
28
36
|
end
|
29
37
|
|
30
38
|
describe "Date#to_parsi" do
|
31
39
|
it "converts date to Parsi date" do
|
32
40
|
date = Date.civil(2012, 10, 28).to_parsi
|
33
|
-
date.
|
34
|
-
date.
|
41
|
+
expect(date).to be_a(Parsi::Date)
|
42
|
+
expect(date).to be == Parsi::Date.civil(1391, 8, 7)
|
43
|
+
|
44
|
+
expect(Date.civil(1988, 2, 3).to_parsi ).to be == Parsi::Date.civil(1366, 11, 14)
|
45
|
+
expect(Date.civil(2025, 3, 20).to_parsi).to be == Parsi::Date.civil(1403, 12, 30)
|
35
46
|
end
|
36
47
|
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).
|
4
|
-
Parsi::Date.leap?(1391).
|
5
|
-
Parsi::Date.leap?(1395).
|
3
|
+
expect(Parsi::Date.leap?(1387)).to be true
|
4
|
+
expect(Parsi::Date.leap?(1391)).to be true
|
5
|
+
expect(Parsi::Date.leap?(1395)).to be true
|
6
|
+
expect(Parsi::Date.leap?(1403)).to be 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).
|
10
|
-
Parsi::Date.leap?(1392).
|
11
|
-
Parsi::Date.leap?(1400).
|
10
|
+
expect(Parsi::Date.leap?(1390)).to be false
|
11
|
+
expect(Parsi::Date.leap?(1392)).to be false
|
12
|
+
expect(Parsi::Date.leap?(1400)).to be false
|
13
|
+
expect(Parsi::Date.leap?(1404)).to be 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.
|
9
|
-
d.
|
8
|
+
expect(d).to be <= ds
|
9
|
+
expect(d).to be >= de
|
10
10
|
count += 1
|
11
11
|
end
|
12
|
-
count.
|
12
|
+
expect(count).to be == 13
|
13
13
|
|
14
14
|
count = 0
|
15
15
|
de.step(ds, 5) do |d|
|
16
|
-
d.
|
17
|
-
d.
|
16
|
+
expect(d).to be <= ds
|
17
|
+
expect(d).to be >= de
|
18
18
|
count += 1
|
19
19
|
end
|
20
|
-
count.
|
20
|
+
expect(count).to be == 3
|
21
21
|
|
22
22
|
count = 0
|
23
23
|
ds.step(de) do |d|; count += 1; end
|
24
|
-
count.
|
24
|
+
expect(count).to be == 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.
|
33
|
-
d.
|
32
|
+
expect(d).to be <= ds
|
33
|
+
expect(d).to be >= de
|
34
34
|
count += 1
|
35
35
|
end
|
36
|
-
count.
|
36
|
+
expect(count).to be == 17
|
37
37
|
|
38
38
|
count = 0
|
39
39
|
ds.step(de, -5) do |d|
|
40
|
-
d.
|
41
|
-
d.
|
40
|
+
expect(d).to be <= ds
|
41
|
+
expect(d).to be >= de
|
42
42
|
count += 1
|
43
43
|
end
|
44
|
-
count.
|
44
|
+
expect(count).to be == 4
|
45
45
|
|
46
46
|
count = 0
|
47
47
|
de.step(ds, -1) do |d|; count += 1; end
|
48
|
-
count.
|
48
|
+
expect(count).to be == 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 "
|
5
|
-
Parsi::Date.civil(1390, 4, 6).strftime.
|
4
|
+
it "is able to print the date" do
|
5
|
+
expect(Parsi::Date.civil(1390, 4, 6).strftime).to be == "1390/04/06"
|
6
6
|
end
|
7
7
|
|
8
|
-
it "
|
9
|
-
Parsi::Date.civil(1390, 4, 6).strftime("%A").
|
8
|
+
it "is able to print the full day name" do
|
9
|
+
expect(Parsi::Date.civil(1390, 4, 6).strftime("%A")).to be == "دوشنبه"
|
10
10
|
end
|
11
11
|
|
12
|
-
it "
|
13
|
-
Parsi::Date.civil(1390, 4, 6).strftime("%a").
|
12
|
+
it "is able to print the short day name" do
|
13
|
+
expect(Parsi::Date.civil(1390, 4, 6).strftime("%a")).to be == "۲ش"
|
14
14
|
end
|
15
15
|
|
16
|
-
it "
|
17
|
-
Parsi::Date.civil(1390, 4, 6).strftime("%B").
|
18
|
-
Parsi::Date.civil(1390, 4, 6).strftime("%EB").
|
19
|
-
Parsi::Date.civil(1390, 4, 6).strftime("%^EB").
|
16
|
+
it "is able to print the full month name" do
|
17
|
+
expect(Parsi::Date.civil(1390, 4, 6).strftime("%B") ).to be == "تیر"
|
18
|
+
expect(Parsi::Date.civil(1390, 4, 6).strftime("%EB") ).to be == "tir"
|
19
|
+
expect(Parsi::Date.civil(1390, 4, 6).strftime("%^EB")).to be == "Tir"
|
20
20
|
end
|
21
21
|
|
22
|
-
it "
|
23
|
-
Parsi::Date.civil(1390, 4, 6).strftime("%b").
|
24
|
-
Parsi::Date.civil(1390, 4, 6).strftime("%h").
|
25
|
-
Parsi::Date.civil(1390, 4, 6).strftime("%^b").
|
26
|
-
Parsi::Date.civil(1390, 4, 6).strftime("%^h").
|
27
|
-
Parsi::Date.civil(1390, 4, 6).strftime("%b").
|
22
|
+
it "is able to print the short month name" do
|
23
|
+
expect(Parsi::Date.civil(1390, 4, 6).strftime("%b") ).to be == "tir"
|
24
|
+
expect(Parsi::Date.civil(1390, 4, 6).strftime("%h") ).to be == "tir"
|
25
|
+
expect(Parsi::Date.civil(1390, 4, 6).strftime("%^b")).to be == "Tir"
|
26
|
+
expect(Parsi::Date.civil(1390, 4, 6).strftime("%^h")).to be == "Tir"
|
27
|
+
expect(Parsi::Date.civil(1390, 4, 6).strftime("%b") ).to be == Parsi::Date.civil(1390, 4, 6).strftime("%h")
|
28
28
|
end
|
29
29
|
|
30
|
-
it "
|
31
|
-
Parsi::Date.civil(1390, 4, 6).strftime("%C").
|
30
|
+
it "is able to print the century" do
|
31
|
+
expect(Parsi::Date.civil(1390, 4, 6).strftime("%C")).to be == "13"
|
32
32
|
end
|
33
33
|
|
34
|
-
it "
|
35
|
-
Parsi::Date.civil(1390, 4, 6).strftime("%d").
|
36
|
-
Parsi::Date.civil(1390, 4, 16).strftime("%d").
|
34
|
+
it "is able to print the month day with leading zeroes" do
|
35
|
+
expect(Parsi::Date.civil(1390, 4, 6).strftime("%d")).to be == "06"
|
36
|
+
expect(Parsi::Date.civil(1390, 4, 16).strftime("%d")).to be == "16"
|
37
37
|
end
|
38
38
|
|
39
|
-
it "
|
40
|
-
Parsi::Date.civil(1390, 4, 6).strftime("%-d").
|
41
|
-
Parsi::Date.civil(1390, 4, 6).strftime("%e").
|
42
|
-
Parsi::Date.civil(1390, 4, 16).strftime("%e").
|
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")).to be == "6"
|
41
|
+
expect(Parsi::Date.civil(1390, 4, 6).strftime("%e") ).to be == " 6"
|
42
|
+
expect(Parsi::Date.civil(1390, 4, 16).strftime("%e") ).to be == "16"
|
43
43
|
end
|
44
44
|
|
45
|
-
it "
|
46
|
-
Parsi::Date.civil(1390, 4, 6).strftime("%m").
|
47
|
-
Parsi::Date.civil(1390, 11, 6).strftime("%m").
|
48
|
-
Parsi::Date.civil(1390, 4, 6).strftime("%_m").
|
49
|
-
Parsi::Date.civil(1390, 11, 6).strftime("%_m").
|
50
|
-
Parsi::Date.civil(1390, 4, 6).strftime("%-m").
|
51
|
-
Parsi::Date.civil(1390, 11, 6).strftime("%-m").
|
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") ).to be == "04"
|
47
|
+
expect(Parsi::Date.civil(1390, 11, 6).strftime("%m") ).to be == "11"
|
48
|
+
expect(Parsi::Date.civil(1390, 4, 6).strftime("%_m")).to be == " 4"
|
49
|
+
expect(Parsi::Date.civil(1390, 11, 6).strftime("%_m")).to be == "11"
|
50
|
+
expect(Parsi::Date.civil(1390, 4, 6).strftime("%-m")).to be == "4"
|
51
|
+
expect(Parsi::Date.civil(1390, 11, 6).strftime("%-m")).to be == "11"
|
52
52
|
end
|
53
53
|
|
54
|
-
it "
|
55
|
-
Parsi::Date.civil(1390, 4, 6).strftime("%n").
|
54
|
+
it "is able to add a newline" do
|
55
|
+
expect(Parsi::Date.civil(1390, 4, 6).strftime("%n")).to be == "\n"
|
56
56
|
end
|
57
57
|
|
58
|
-
it "
|
59
|
-
Parsi::Date.civil(1390, 4, 6).strftime("%t").
|
58
|
+
it "is able to add a tab" do
|
59
|
+
expect(Parsi::Date.civil(1390, 4, 6).strftime("%t")).to be == "\t"
|
60
60
|
end
|
61
61
|
|
62
|
-
it "
|
63
|
-
Parsi::Date.civil(1390, 4, 11).strftime("%w").
|
64
|
-
Parsi::Date.civil(1390, 4, 12).strftime("%w").
|
62
|
+
it "is able to show the week day" do
|
63
|
+
expect(Parsi::Date.civil(1390, 4, 11).strftime("%w")).to be == "6"
|
64
|
+
expect(Parsi::Date.civil(1390, 4, 12).strftime("%w")).to be == "0"
|
65
65
|
end
|
66
66
|
|
67
|
-
it "
|
68
|
-
Parsi::Date.civil(1390, 4, 9).strftime("%Y").
|
67
|
+
it "is able to show the year in YYYY format" do
|
68
|
+
expect(Parsi::Date.civil(1390, 4, 9).strftime("%Y")).to be == "1390"
|
69
69
|
end
|
70
70
|
|
71
|
-
it "
|
72
|
-
Parsi::Date.civil(1390, 4, 9).strftime("%y").
|
71
|
+
it "is able to show the year in YY format" do
|
72
|
+
expect(Parsi::Date.civil(1390, 4, 9).strftime("%y")).to be == "90"
|
73
73
|
end
|
74
74
|
|
75
|
-
it "
|
76
|
-
Parsi::Date.civil(1390, 4, 9).strftime("%%").
|
75
|
+
it "is able to escape the % character" do
|
76
|
+
expect(Parsi::Date.civil(1390, 4, 9).strftime("%%")).to be == "%"
|
77
77
|
end
|
78
78
|
|
79
79
|
############################
|
80
80
|
# Specs that combine stuff #
|
81
81
|
############################
|
82
82
|
|
83
|
-
it "
|
84
|
-
Parsi::Date.civil(1390, 4, 6).strftime("%c").
|
85
|
-
Parsi::Date.civil(1390, 4, 6).strftime("%c").
|
83
|
+
it "is able to print the date in full" do
|
84
|
+
expect(Parsi::Date.civil(1390, 4, 6).strftime("%c")).to be == "۲ش 6 تیر 1390"
|
85
|
+
expect(Parsi::Date.civil(1390, 4, 6).strftime("%c")).to be == Parsi::Date.civil(1390, 4, 6).strftime('%a %-d %B %Y')
|
86
86
|
end
|
87
87
|
|
88
|
-
it "
|
89
|
-
Parsi::Date.civil(1390, 4, 6).strftime("%D").
|
90
|
-
Parsi::Date.civil(1390, 4, 6).strftime("%D").
|
88
|
+
it "is able to print the date with slashes" do
|
89
|
+
expect(Parsi::Date.civil(1390, 4, 6).strftime("%D")).to be == "90/04/06"
|
90
|
+
expect(Parsi::Date.civil(1390, 4, 6).strftime("%D")).to be == Parsi::Date.civil(1390, 4, 6).strftime('%y/%m/%d')
|
91
91
|
end
|
92
92
|
|
93
|
-
it "
|
94
|
-
Parsi::Date.civil(1390, 4, 6).strftime("%F").
|
95
|
-
Parsi::Date.civil(1390, 4, 6).strftime("%F").
|
93
|
+
it "is able to print the date as YYYY-MM-DD" do
|
94
|
+
expect(Parsi::Date.civil(1390, 4, 6).strftime("%F")).to be == "1390-04-06"
|
95
|
+
expect(Parsi::Date.civil(1390, 4, 6).strftime("%F")).to be == Parsi::Date.civil(1390, 4, 6).strftime('%Y-%m-%d')
|
96
96
|
end
|
97
97
|
|
98
|
-
it "
|
99
|
-
Parsi::Date.civil(1390, 4, 9).strftime("%v").
|
100
|
-
Parsi::Date.civil(1390, 4, 9).strftime("%v").
|
98
|
+
it "is able to show the commercial week" do
|
99
|
+
expect(Parsi::Date.civil(1390, 4, 9).strftime("%v")).to be == " 9-تیر-1390"
|
100
|
+
expect(Parsi::Date.civil(1390, 4, 9).strftime("%v")).to be == Parsi::Date.civil(1390, 4, 9).strftime('%e-%B-%Y')
|
101
101
|
end
|
102
102
|
|
103
|
-
it "
|
104
|
-
Parsi::Date.civil(1390, 4, 6).strftime("%x").
|
105
|
-
Parsi::Date.civil(1390, 4, 6).strftime("%x").
|
103
|
+
it "is able to show YY/MM/DD" do
|
104
|
+
expect(Parsi::Date.civil(1390, 4, 6).strftime("%x")).to be == "90/04/06"
|
105
|
+
expect(Parsi::Date.civil(1390, 4, 6).strftime("%x")).to be == 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.
|
4
|
-
Parsi::Date.civil(1394, 1, 3).cwday.
|
3
|
+
expect(Parsi::Date.civil(1393, 12, 3).cwday).to be == 7
|
4
|
+
expect(Parsi::Date.civil(1394, 1, 3).cwday).to be == 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.
|
11
|
-
Parsi::Date.civil(1393, 12, 1).cweek.
|
12
|
-
Parsi::Date.civil(1393, 12, 29).cweek.
|
13
|
-
Parsi::Date.civil(1394, 1, 1).cweek.
|
14
|
-
Parsi::Date.civil(1394, 1, 7).cweek.
|
15
|
-
Parsi::Date.civil(1394, 1, 8).cweek.
|
10
|
+
expect(Parsi::Date.civil(1393, 11, 30).cweek).to be == 48
|
11
|
+
expect(Parsi::Date.civil(1393, 12, 1).cweek ).to be == 48
|
12
|
+
expect(Parsi::Date.civil(1393, 12, 29).cweek).to be == 52
|
13
|
+
expect(Parsi::Date.civil(1394, 1, 1).cweek ).to be == 1
|
14
|
+
expect(Parsi::Date.civil(1394, 1, 7).cweek ).to be == 1
|
15
|
+
expect(Parsi::Date.civil(1394, 1, 8).cweek ).to be == 2
|
16
16
|
end
|
17
17
|
end
|
data/spec/spec_helper.rb
CHANGED
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.
|
4
|
+
version: 0.5.1
|
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:
|
11
|
+
date: 2024-06-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -16,70 +16,84 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '
|
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: '
|
26
|
+
version: '2.0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: json
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '2.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '2.0'
|
27
41
|
- !ruby/object:Gem::Dependency
|
28
42
|
name: rake
|
29
43
|
requirement: !ruby/object:Gem::Requirement
|
30
44
|
requirements:
|
31
45
|
- - "~>"
|
32
46
|
- !ruby/object:Gem::Version
|
33
|
-
version: '
|
47
|
+
version: '13.0'
|
34
48
|
type: :development
|
35
49
|
prerelease: false
|
36
50
|
version_requirements: !ruby/object:Gem::Requirement
|
37
51
|
requirements:
|
38
52
|
- - "~>"
|
39
53
|
- !ruby/object:Gem::Version
|
40
|
-
version: '
|
54
|
+
version: '13.0'
|
41
55
|
- !ruby/object:Gem::Dependency
|
42
56
|
name: rspec
|
43
57
|
requirement: !ruby/object:Gem::Requirement
|
44
58
|
requirements:
|
45
59
|
- - "~>"
|
46
60
|
- !ruby/object:Gem::Version
|
47
|
-
version: '
|
61
|
+
version: '3.0'
|
48
62
|
type: :development
|
49
63
|
prerelease: false
|
50
64
|
version_requirements: !ruby/object:Gem::Requirement
|
51
65
|
requirements:
|
52
66
|
- - "~>"
|
53
67
|
- !ruby/object:Gem::Version
|
54
|
-
version: '
|
68
|
+
version: '3.0'
|
55
69
|
- !ruby/object:Gem::Dependency
|
56
70
|
name: activerecord
|
57
71
|
requirement: !ruby/object:Gem::Requirement
|
58
72
|
requirements:
|
59
73
|
- - "~>"
|
60
74
|
- !ruby/object:Gem::Version
|
61
|
-
version: '
|
75
|
+
version: '6.0'
|
62
76
|
type: :development
|
63
77
|
prerelease: false
|
64
78
|
version_requirements: !ruby/object:Gem::Requirement
|
65
79
|
requirements:
|
66
80
|
- - "~>"
|
67
81
|
- !ruby/object:Gem::Version
|
68
|
-
version: '
|
82
|
+
version: '6.0'
|
69
83
|
- !ruby/object:Gem::Dependency
|
70
84
|
name: sqlite3
|
71
85
|
requirement: !ruby/object:Gem::Requirement
|
72
86
|
requirements:
|
73
87
|
- - "~>"
|
74
88
|
- !ruby/object:Gem::Version
|
75
|
-
version: '1.
|
89
|
+
version: '1.5'
|
76
90
|
type: :development
|
77
91
|
prerelease: false
|
78
92
|
version_requirements: !ruby/object:Gem::Requirement
|
79
93
|
requirements:
|
80
94
|
- - "~>"
|
81
95
|
- !ruby/object:Gem::Version
|
82
|
-
version: '1.
|
96
|
+
version: '1.5'
|
83
97
|
description: A Solar Hijri (Jalali) date library for Ruby, whitch provides much of
|
84
98
|
Ruby's built-in date class
|
85
99
|
email: hsn.zamani@gmail.com
|
@@ -87,13 +101,12 @@ executables: []
|
|
87
101
|
extensions: []
|
88
102
|
extra_rdoc_files: []
|
89
103
|
files:
|
104
|
+
- ".github/workflows/ruby.yml"
|
90
105
|
- ".gitignore"
|
91
106
|
- ".rspec"
|
92
|
-
- ".travis.yml"
|
93
107
|
- Gemfile
|
94
108
|
- MIT-LICENSE
|
95
|
-
- README.
|
96
|
-
- TODO
|
109
|
+
- README.md
|
97
110
|
- lib/parsi-date-accessors.rb
|
98
111
|
- lib/parsi-date.rb
|
99
112
|
- lib/parsi-datetime.rb
|
@@ -116,7 +129,7 @@ homepage: http://github.com/hzamani/parsi-date
|
|
116
129
|
licenses:
|
117
130
|
- MIT
|
118
131
|
metadata: {}
|
119
|
-
post_install_message:
|
132
|
+
post_install_message:
|
120
133
|
rdoc_options: []
|
121
134
|
require_paths:
|
122
135
|
- lib
|
@@ -131,9 +144,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
131
144
|
- !ruby/object:Gem::Version
|
132
145
|
version: '0'
|
133
146
|
requirements: []
|
134
|
-
|
135
|
-
|
136
|
-
signing_key:
|
147
|
+
rubygems_version: 3.3.25
|
148
|
+
signing_key:
|
137
149
|
specification_version: 4
|
138
150
|
summary: Solar Hijri (Jalali, Persian, Parsi) date library for Ruby
|
139
151
|
test_files:
|
@@ -150,4 +162,3 @@ test_files:
|
|
150
162
|
- spec/parsi-date/strftime_spec.rb
|
151
163
|
- spec/parsi-date/week_methods_spec.rb
|
152
164
|
- spec/spec_helper.rb
|
153
|
-
has_rdoc:
|
data/.travis.yml
DELETED
data/README.rdoc
DELETED
@@ -1,31 +0,0 @@
|
|
1
|
-
= Parsi Date
|
2
|
-
|
3
|
-
This is an implementation of {Solar Hijri Calendar}[http://en.wikipedia.org/wiki/Solar_Hijri_calendar]
|
4
|
-
(some times referred to as Jalali or Persian Calendar) which is Iran's official calendar.
|
5
|
-
Main aim of this gem is to create a Solar Hijri date library as close as possible to the built-in date library.
|
6
|
-
Conversion algorithm originally adopted from {here}[http://www.fourmilab.ch/documents/calendar/].
|
7
|
-
|
8
|
-
== Usage
|
9
|
-
|
10
|
-
You can use <tt>Parsi::Date<\tt> and <tt>Parsi::DateTime<\tt> objects as +Date+ and +DateTime+ objects
|
11
|
-
For example:
|
12
|
-
|
13
|
-
a = Parsi::Date.today # => #<Parsi::Date: 1391-08-09 (4912461/2,0/1)>
|
14
|
-
b = a >> 12 # => #<Parsi::Date: 1392-08-09 (4913193/2,0/1)>
|
15
|
-
a.upto(b).select{ |d| d.sunday? }.count # => 52
|
16
|
-
|
17
|
-
Parsi::Date.leap? 1391 # => true
|
18
|
-
|
19
|
-
c = Parsi::Date.parse "1391/10/12" # => #<Parsi::Date: 1391-10-12 (4912587/2,0)>
|
20
|
-
c.strftime "%A %d %B %Y" # => "سهشنبه 12 دی 1391"
|
21
|
-
c.strftime "%^EA %d %^EB %Y" # => "Seshambe 12 Day 1391"
|
22
|
-
|
23
|
-
For converting a +Date+ or +DateTime+ object just call +to_parsi+ (aliased to +jalali+ and +to_jalali+) on it.
|
24
|
-
To convert back use +to_gregorian+.
|
25
|
-
|
26
|
-
d = Date.civil(2012, 10, 30).to_parsi # => #<Parsi::Date: 1391-08-09 (4912461/2,0/1)>
|
27
|
-
d.to_gregorian # => #<Date: 2012-10-30 ((2456231j,0s,0n),+0s,2299161j)>
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
Copyright (c) 2012 Hassan Zamani, released under the MIT license.
|
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'
|