A Jalaali (Jalali, Persian, Khorshidi, Shamsi) calendar system implemention for Elixir
Switch branches/tags
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.


Elixir Jalaali calendar

Build Status Hex.pm GitHub license GitHub issues

Elixir implementation of jalaali.js which contains a Calendar implementation for jalaali and some functions for converting Jalaali and Gregorian calendar systems to each other.


You can install jalaali by Addding it to your list of dependencies in mix.exs:

def deps do
  [{:jalaali, "~> 0.2.1"}]

Usage (Elixir >= 1.5)

After installing jalaali package. you can create Dates/DateTimes in jalaali or convert Dates/DateTimes form other calendars back an forth.

This feature is intruduced in Elixir 1.5 so in any versions below 1.5 the Date and DateTime modules lack functions for converting calendars. However you can just copy those modules but its just better to migrate to 1.5 or above

How to use

  • Creating new Date
  Date.new(1396, 6, 30, Jalaali.Calendar)
  {:ok, %Date{calendar: Jalaali.Calendar, day: 30, month: 6, year: 1396}}
  • Converting a DateTime to Jalaali
  datetime_in_any_calendar = DateTime.utc_now(Calendar.ISO)
  {:ok, jalaali_datetime} = DateTime.convert(datetime_in_any_calendar, Jalaali.Calendar)
  • Converting a DateTime from Jalaali
  jalaali_datetime = DateTime.utc_now(Calendar.Jalaali)
  {:ok, iso_datetime} = DateTime.convert(jalaali_datetime, Calendar.ISO)
  • Converting a Date to Jalaali
  date_in_any_calendar = Date.new(2017, 1, 1, Calendar.ISO)
  {:ok, jalaali_date} = Date.convert(date_in_any_calendar, Jalaali.Calendar)
  • Converting a Date from Jalaali
  {:ok, jalaali_date} = Date.new(1396, 6, 30, Calendar.Jalaali)
  {:ok, iso_date} = Date.convert(jalaali_date, Calendar.ISO)

Thats super easy. :)

Usage (Elixir < 1.5) [Old bad way]

*IMPORTANT* Do not use these methods if you can migrate to Elixir 1.5 or above

After installing jalaali package. you can use it for:

  • Converting Gregorian dates to Jalaali:
  jal_date = Jalaali.to_jalaali(~D[2015-02-29])
  • Converting Jalaali dates to Gregorian:
  gre_date = Jalaali.to_gregorian(~D[1395-03-15])
  • Checking for Jalaali leap years:
  • Get a Jalaali month lenght
  Jalaali.jalaali_month_length(1395, 12)


This project is license under MIT.

For more information please check LICENSE