Code Monkey home page Code Monkey logo

parsi-date's Introduction

Parsi Date

This is an implementation of 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.

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 © 2012 Hassan Zamani, released under the MIT license.

parsi-date's People

Contributors

hzamani avatar martianboy avatar

Watchers

 avatar  avatar

Forkers

perryyo

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.