Sha256: e9fe08d982ca9ee3c1f409790c92b5ea52dadcab0636b76b891c7ed8daac0fa6

Contents?: true

Size: 1.46 KB

Versions: 7

Compression:

Stored size: 1.46 KB

Contents

= Parsi Date

This is an implementation of {Solar Hijri Calendar}[http://en.wikipedia.org/wiki/Solar_Hijri_calendar]
(some times referred to as Jalali or Persian Calendar) which is Iran's official calendar.
Main aim of this gem is to create a Solar Hijri date library as close as possible to the built-in date library.
Conversion algorithm originally adopted from {here}[http://www.fourmilab.ch/documents/calendar/].

== Usage

You can use <tt>Parsi::Date<\tt> and <tt>Parsi::DateTime<\tt> objects as +Date+ and +DateTime+ objects
For example:

  a = Parsi::Date.today                     # => #<Parsi::Date: 1391-08-09 (4912461/2,0/1)>
  b = a >> 12                               # => #<Parsi::Date: 1392-08-09 (4913193/2,0/1)>
  a.upto(b).select{ |d| d.sunday? }.count   # => 52

  Parsi::Date.leap? 1391                    # => true

  c = Parsi::Date.parse "1391/10/12"        # => #<Parsi::Date: 1391-10-12 (4912587/2,0)>
  c.strftime "%A %d %B %Y"                  # => "سه‌شنبه 12 دی 1391"
  c.strftime "%^EA %d %^EB %Y"              # => "Seshambe 12 Day 1391"

For converting a +Date+ or +DateTime+ object just call +to_parsi+ (aliased to +jalali+ and +to_jalali+) on it.
To convert back use +to_gregorian+.

  d = Date.civil(2012, 10, 30).to_parsi     # => #<Parsi::Date: 1391-08-09 (4912461/2,0/1)>
  d.to_gregorian                            # => #<Date: 2012-10-30 ((2456231j,0s,0n),+0s,2299161j)>



Copyright (c) 2012 Hassan Zamani, released under the MIT license.

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
parsi-date-0.4.0 README.rdoc
parsi-date-0.3.1 README.rdoc
parsi-date-0.3.0 README.rdoc
parsi-date-0.2.6 README.rdoc
parsi-date-0.2.5 README.rdoc
parsi-date-0.2.4 README.rdoc
parsi-date-0.2.3 README.rdoc