-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
17 changed files
with
287 additions
and
190 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
# Parsi Date | ||
|
||
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 adopted from [FarsiWeb](http://www.farsiweb.info/jalali/jalali.c). | ||
|
||
## Features | ||
|
||
- **Parsi::Date** and **Parsi::DateTime**: These objects can be used just like Ruby's `Date` and `DateTime` objects. | ||
- **Date Conversion:** Easily convert between Gregorian and Solar Hijri dates. | ||
- **Leap Year Calculation:** Determine if a given Solar Hijri year is a leap year. | ||
- **Date Parsing and Formatting:** Parse Solar Hijri date strings and format dates in various styles. | ||
|
||
## Usage | ||
|
||
### Basic Operations | ||
|
||
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: | ||
|
||
```ruby | ||
# Get today's Solar Hijri date | ||
a = Parsi::Date.today | ||
# => #<Parsi::Date: 1391-08-09 (4912461/2,0/1)> | ||
|
||
# Add 12 months to it | ||
b = a >> 12 | ||
# => #<Parsi::Date: 1392-08-09 (4913193/2,0/1)> | ||
|
||
# Count the number of Sundays between two dates | ||
a.upto(b).select{ |d| d.sunday? }.count | ||
# => 52 | ||
|
||
# Check if a given year is a leap year | ||
Parsi::Date.leap?(1391) | ||
# => true | ||
``` | ||
|
||
### Parsing and Formatting Dates | ||
|
||
You can parse Solar Hijri date strings and format them in various styles: | ||
|
||
```ruby | ||
# Parse a Solar Hijri date string | ||
c = Parsi::Date.parse("1391/10/12") | ||
# => #<Parsi::Date: 1391-10-12 (4912587/2,0)> | ||
|
||
# Format the date in Persian | ||
c.strftime("%A %d %B %Y") | ||
# => "سهشنبه 12 دی 1391" | ||
|
||
# Format the date in English | ||
c.strftime("%^EA %d %^EB %Y") | ||
# => "Seshambe 12 Day 1391" | ||
``` | ||
|
||
### Converting Between Calendars | ||
|
||
You can easily convert between Gregorian and Solar Hijri dates: | ||
|
||
```ruby | ||
# Convert a Gregorian date to Solar Hijri | ||
d = Date.civil(2012, 10, 30).to_parsi | ||
# => #<Parsi::Date: 1391-08-09 (4912461/2,0/1)> | ||
|
||
# Convert a Solar Hijri date back to Gregorian | ||
d.to_gregorian | ||
# => #<Date: 2012-10-30 ((2456231j,0s,0n),+0s,2299161j)> | ||
``` | ||
|
||
## Installation | ||
|
||
Add this line to your application's Gemfile: | ||
|
||
```ruby | ||
gem 'parsi_date' | ||
``` | ||
|
||
And then execute: | ||
|
||
```sh | ||
bundle install | ||
``` | ||
|
||
Or install it yourself as: | ||
|
||
```sh | ||
gem install parsi_date | ||
``` | ||
|
||
## License | ||
|
||
The Parsi Date library is open-source software licensed under the MIT license. | ||
|
||
## Contributing | ||
|
||
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. |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,57 +1,66 @@ | ||
describe "Parsi::Date#ajd" do | ||
it "determines the Astronomical Julian day" do | ||
expect Parsi::Date.civil(1391, 8, 6).ajd == Rational(4912455, 2) | ||
expect(Parsi::Date.civil(1391, 8, 6).ajd).to be == Rational(4912455, 2) | ||
expect(Parsi::Date.civil(1403, 12, 30).ajd).to be == Rational(4921509, 2) | ||
end | ||
end | ||
|
||
describe "Parsi::Date#amjd" do | ||
it "determines the Astronomical Modified Julian day" do | ||
expect Parsi::Date.civil(1391, 8, 6).amjd == 56227 | ||
expect(Parsi::Date.civil(1391, 8, 6).amjd).to be == 56227 | ||
expect(Parsi::Date.civil(1403, 12, 30).amjd).to be == 60754 | ||
end | ||
end | ||
|
||
describe "Parsi::Date#mjd" do | ||
it "determines the Modified Julian day" do | ||
expect Parsi::Date.civil(1391, 8, 6).mjd == 56227 | ||
expect(Parsi::Date.civil(1391, 8, 6).mjd).to be == 56227 | ||
expect(Parsi::Date.civil(1403, 12, 30).mjd).to be == 60754 | ||
end | ||
end | ||
|
||
describe "Parsi::Date#ld" do | ||
it "determines the Modified Julian day" do | ||
expect Parsi::Date.civil(1391, 8, 6).ld == 157068 | ||
it "determines the number of days since the Day of Calendar Reform" do | ||
expect(Parsi::Date.civil(1391, 8, 6).ld).to be == 157068 | ||
expect(Parsi::Date.civil(1403, 12, 30).ld).to be == 161595 | ||
end | ||
end | ||
|
||
describe "Parsi::Date#year" do | ||
it "determines the year" do | ||
expect Parsi::Date.civil(1391, 8, 6).year == 1391 | ||
expect(Parsi::Date.civil(1391, 8, 6).year).to be == 1391 | ||
expect(Parsi::Date.civil(1403, 12, 30).year).to be == 1403 | ||
end | ||
end | ||
|
||
describe "Parsi::Date#yday" do | ||
it "determines the year" do | ||
expect Parsi::Date.civil(1391, 1, 17).yday == 17 | ||
expect Parsi::Date.civil(1391, 8, 6).yday == 222 | ||
expect(Parsi::Date.civil(1391, 1, 17).yday).to be == 17 | ||
expect(Parsi::Date.civil(1391, 8, 6).yday).to be == 222 | ||
expect(Parsi::Date.civil(1403, 12, 30).yday).to be == 366 | ||
end | ||
end | ||
|
||
describe "Parsi::Date#mon" do | ||
it "determines the month" do | ||
expect Parsi::Date.civil(1391, 1, 17).mon == 1 | ||
expect Parsi::Date.civil(1391, 8, 6).mon == 8 | ||
expect(Parsi::Date.civil(1391, 1, 17).mon).to be == 1 | ||
expect(Parsi::Date.civil(1391, 8, 6).mon).to be == 8 | ||
expect(Parsi::Date.civil(1403, 12, 30).mon).to be == 12 | ||
end | ||
end | ||
|
||
describe "Parsi::Date#mday" do | ||
it "determines the day of the month" do | ||
expect Parsi::Date.civil(1391, 1, 17).mday == 17 | ||
expect Parsi::Date.civil(1391, 10, 28).mday == 28 | ||
expect(Parsi::Date.civil(1391, 1, 17).mday).to be == 17 | ||
expect(Parsi::Date.civil(1391, 10, 28).mday).to be == 28 | ||
expect(Parsi::Date.civil(1403, 12, 30).mday).to be == 30 | ||
end | ||
end | ||
|
||
describe "Parsi::Date#wday" do | ||
it "determines the week day" do | ||
expect Parsi::Date.civil(1391, 1, 17).wday == 4 | ||
expect Parsi::Date.civil(1391, 8, 6).wday == 6 | ||
expect(Parsi::Date.civil(1391, 1, 17).wday).to be == 4 | ||
expect(Parsi::Date.civil(1391, 8, 6).wday).to be == 6 | ||
expect(Parsi::Date.civil(1403, 12, 30).wday).to be == 4 | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.